diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2011-08-06T13·02+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2011-08-06T13·02+0000 |
commit | 54945a2950174ded83d58336061b4a9990cdbbfd (patch) | |
tree | 8789c505f73551e9a40d745cbb2858ddc683cd9c /src/libexpr/parser.y | |
parent | c8606664abe952f74985503c831d31ae7a7369bc (diff) |
* Refactoring: move parseExprFromFile() and parseExprFromString() into
the EvalState class.
Diffstat (limited to 'src/libexpr/parser.y')
-rw-r--r-- | src/libexpr/parser.y | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index e5c586266f78..a64d327b454b 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -450,11 +450,11 @@ formal namespace nix { -static Expr * parse(EvalState & state, const char * text, +Expr * EvalState::parse(const char * text, const Path & path, const Path & basePath) { yyscan_t scanner; - ParseData data(state.symbols); + ParseData data(symbols); data.basePath = basePath; data.path = path; @@ -466,7 +466,7 @@ static Expr * parse(EvalState & state, const char * text, if (res) throw ParseError(data.error); try { - data.result->bindVars(state.staticBaseEnv); + data.result->bindVars(staticBaseEnv); } catch (Error & e) { throw ParseError(format("%1%, in `%2%'") % e.msg() % path); } @@ -475,7 +475,7 @@ static Expr * parse(EvalState & state, const char * text, } -Expr * parseExprFromFile(EvalState & state, Path path) +Expr * EvalState::parseExprFromFile(Path path) { assert(path[0] == '/'); @@ -493,15 +493,21 @@ Expr * parseExprFromFile(EvalState & state, Path path) if (S_ISDIR(st.st_mode)) path = canonPath(path + "/default.nix"); - /* Read and parse the input file. */ - return parse(state, readFile(path).c_str(), path, dirOf(path)); + /* Read and parse the input file, unless it's already in the parse + tree cache. */ + Expr * e = parseTrees[path]; + if (!e) { + e = parse(readFile(path).c_str(), path, dirOf(path)); + parseTrees[path] = e; + } + + return e; } -Expr * parseExprFromString(EvalState & state, - const string & s, const Path & basePath) +Expr * EvalState::parseExprFromString(const string & s, const Path & basePath) { - return parse(state, s.c_str(), "(string)", basePath); + return parse(s.c_str(), "(string)", basePath); } |