about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--third_party/nix/src/libexpr/lexer.l73
-rw-r--r--third_party/nix/src/libexpr/parser.hh32
2 files changed, 53 insertions, 52 deletions
diff --git a/third_party/nix/src/libexpr/lexer.l b/third_party/nix/src/libexpr/lexer.l
index be5fe4a78f7d..d5b8a459363a 100644
--- a/third_party/nix/src/libexpr/lexer.l
+++ b/third_party/nix/src/libexpr/lexer.l
@@ -14,68 +14,39 @@
 %{
 #include <boost/lexical_cast.hpp>
 
-#include "libexpr/nixexpr.hh"
 #include "generated/parser-tab.hh"
+#include "libexpr/nixexpr.hh"
+#include "libexpr/parser.hh"
 
 using namespace nix;
 
 namespace nix {
 
-
-static void initLoc(YYLTYPE * loc)
-{
-    loc->first_line = loc->last_line = 1;
-    loc->first_column = loc->last_column = 1;
+static void initLoc(YYLTYPE* loc) {
+  loc->first_line = loc->last_line = 1;
+  loc->first_column = loc->last_column = 1;
 }
 
-
-static void adjustLoc(YYLTYPE * loc, const char * s, size_t len)
-{
-    loc->first_line = loc->last_line;
-    loc->first_column = loc->last_column;
-
-    while (len--) {
-       switch (*s++) {
-       case '\r':
-           if (*s == '\n') /* cr/lf */
-               s++;
-           /* fall through */
-       case '\n':
-           ++loc->last_line;
-           loc->last_column = 1;
-           break;
-       default:
-           ++loc->last_column;
-       }
+static void adjustLoc(YYLTYPE* loc, const char* s, size_t len) {
+  loc->first_line = loc->last_line;
+  loc->first_column = loc->last_column;
+
+  while (len--) {
+    switch (*s++) {
+      case '\r':
+        if (*s == '\n') /* cr/lf */
+          s++;
+        /* fall through */
+      case '\n':
+        ++loc->last_line;
+        loc->last_column = 1;
+        break;
+      default:
+        ++loc->last_column;
     }
+  }
 }
 
-
-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));
-}
-
-
 }
 
 #define YY_USER_INIT initLoc(yylloc)
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