diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-09-04T21·36+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-09-04T21·36+0000 |
commit | e3ce954582f56b9d853ea379c783cf6cd5571c83 (patch) | |
tree | b4882e00f5ecccbabcfb5c4f37427d01149b585f /src/libexpr/lexer.l | |
parent | 75068e7d753cf6cbe45a4bf294000dca9bd41d8b (diff) |
* Compile the lexer as C++ code. Remove all the redundant C/C++
marshalling code.
Diffstat (limited to 'src/libexpr/lexer.l')
-rw-r--r-- | src/libexpr/lexer.l | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l index bbf872ff6ec8..625e044b682f 100644 --- a/src/libexpr/lexer.l +++ b/src/libexpr/lexer.l @@ -7,16 +7,23 @@ %{ -#include <string.h> -#include <aterm2.h> +#include "aterm.hh" +#include "nixexpr.hh" +#include "nixexpr-ast.hh" #include "parser-tab.hh" +using namespace nix; + +namespace nix { + + static void initLoc(YYLTYPE * loc) { loc->first_line = 1; loc->first_column = 1; } + static void adjustLoc(YYLTYPE * loc, const char * s, size_t len) { while (len--) { @@ -35,12 +42,32 @@ static void adjustLoc(YYLTYPE * loc, const char * s, size_t len) } } -ATerm toATerm(const char * s) + +static Expr unescapeStr(const char * s) { - return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue)); + string t; + 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 makeStr(toATerm(t)); } -ATerm unescapeStr(const char * s); + +} #define YY_USER_INIT initLoc(yylloc) #define YY_USER_ACTION adjustLoc(yylloc, yytext, yyleng); @@ -106,12 +133,17 @@ inherit { return INHERIT; } %% + +namespace nix { + /* Horrible, disgusting hack: allow the parser to set the scanner start condition back to STRING. Necessary in interpolations like "foo${expr}bar"; after the close brace we have to go back to the STRING state. */ void backToString(yyscan_t scanner) { - struct yyguts_t * yyg = (struct yyguts_t*) scanner; + struct yyguts_t * yyg = (struct yyguts_t *) scanner; BEGIN(STRING); } + +} |