about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr/parser.hh
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-07-19T01·26+0100
committertazjin <mail@tazj.in>2020-07-19T02·59+0000
commit105ad71015465104db98a7e6077a4cc48bd8e5f0 (patch)
tree233435e7f3cd760f9b70a7aa770b9b16ea1f1298 /third_party/nix/src/libexpr/parser.hh
parent9f5f71616affc7c3c588bfb97d578bfc61839b37 (diff)
refactor(3p/nix/libexpr): Move some code out of lexer.l r/1392
Moves a function that is not dependent on the generated code over to
parser.hh. This function also looks like it could be improved, but
that is left as an exercise for the reader.

Code that remains in lexer.l has been reformatted, while we're here.

Change-Id: I9c26bb4eed0772a720d0715029e8bc10ab16ac38
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1279
Tested-by: BuildkiteCI
Reviewed-by: Kane York <rikingcoding@gmail.com>
Diffstat (limited to '')
-rw-r--r--third_party/nix/src/libexpr/parser.hh32
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 7f4c360b1b..7592e3f82c 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