diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-01-30 15:21:42 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-01-30 15:21:42 +0000 |
commit | c5baaafae69394082817ede9e6eb3910c4601a72 (patch) | |
tree | bfc2599717c4274e16ba02959617254873c0c007 /src/libexpr/lexer.l | |
parent | abd1878b26200ba3fa75592637aa87e04f52100d (diff) | |
download | guix-c5baaafae69394082817ede9e6eb3910c4601a72.tar.gz |
* Replaced the SDF parser by a substantially faster Bison/Flex
parser (roughly 80x faster). The absolutely latest version of Bison (1.875c) is required for reentrant GLR support, as well as a recent version of Flex (say, 2.5.31). Note that most Unix distributions ship with the prehistoric Flex 2.5.4, which doesn't support reentrancy.
Diffstat (limited to 'src/libexpr/lexer.l')
-rw-r--r-- | src/libexpr/lexer.l | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l new file mode 100644 index 0000000000..705b31b41a --- /dev/null +++ b/src/libexpr/lexer.l @@ -0,0 +1,78 @@ +%option reentrant bison-bridge bison-locations +%option noyywrap +%option never-interactive + + +%{ +#include <string.h> +#include <aterm2.h> +#include "parser-tab.h" + +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--) { + switch (*s++) { + case '\n': + ++loc->first_line; + loc->first_column = 1; + break; + default: + ++loc->first_column; + } + } +} + +#define YY_USER_INIT initLoc(yylloc) +#define YY_USER_ACTION adjustLoc(yylloc, yytext, yyleng); + +%} + + +ID [a-zA-Z\_][a-zA-Z0-9\_\']* +INT [0-9]+ +STR \"[^\n\"]*\" +PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+ +URI [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']* + + +%% + + +if { return IF; } +then { return THEN; } +else { return ELSE; } +assert { return ASSERT; } +let { return LET; } +rec { return REC; } + +\=\= { return EQ; } +\!\= { return NEQ; } +\&\& { return AND; } +\|\| { return OR; } +\-\> { return IMPL; } + +{ID} { yylval->t = ATmake("<str>", yytext); return ID; /* !!! alloc */ } +{INT} { return INT; } +{STR} { int len = strlen(yytext); + yytext[len - 1] = 0; + yylval->t = ATmake("<str>", yytext + 1); + yytext[len - 1] = '\"'; + return STR; /* !!! alloc */ + } +{PATH} { yylval->t = ATmake("<str>", yytext); return PATH; /* !!! alloc */ } +{URI} { yylval->t = ATmake("<str>", yytext); return URI; /* !!! alloc */ } + +[ \t\n]+ /* eat up whitespace */ +\#[^\n]* /* single-line comments */ +\/\*(.|\n)*\*\/ /* long comments */ + +. return yytext[0]; + + +%% |