diff options
Diffstat (limited to 'third_party/nix/src/libexpr/parser.hh')
-rw-r--r-- | third_party/nix/src/libexpr/parser.hh | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/third_party/nix/src/libexpr/parser.hh b/third_party/nix/src/libexpr/parser.hh index 7f4c360b1bfd..7592e3f82ce6 100644 --- a/third_party/nix/src/libexpr/parser.hh +++ b/third_party/nix/src/libexpr/parser.hh @@ -19,7 +19,7 @@ namespace nix { -struct ParseData { +struct ParseData : public gc { EvalState& state; SymbolTable& symbols; Expr* result; @@ -55,4 +55,34 @@ Expr* stripIndentation(const Pos& pos, SymbolTable& symbols, Path resolveExprPath(Path path); +// implementations originally from lexer.l + +static Expr* unescapeStr(SymbolTable& symbols, const char* s, size_t length) { + std::string t; + t.reserve(length); + char c; + while ((c = *s++)) { + if (c == '\\') { + assert(*s); + c = *s++; + if (c == 'n') { + t += '\n'; + } else if (c == 'r') { + t += '\r'; + } else if (c == 't') { + t += '\t'; + } else + t += c; + } else if (c == '\r') { + /* Normalise CR and CR/LF into LF. */ + t += '\n'; + if (*s == '\n') { + s++; + } /* cr/lf */ + } else + t += c; + } + return new ExprString(symbols.Create(t)); +} + } // namespace nix |