2004-01-30 15:21:42 +00:00
|
|
|
%option reentrant bison-bridge bison-locations
|
|
|
|
%option noyywrap
|
|
|
|
%option never-interactive
|
|
|
|
|
|
|
|
|
2006-05-01 14:01:47 +00:00
|
|
|
%x STRING
|
2007-11-30 16:48:45 +00:00
|
|
|
%x IND_STRING
|
2006-05-01 14:01:47 +00:00
|
|
|
|
|
|
|
|
2004-01-30 15:21:42 +00:00
|
|
|
%{
|
2006-09-04 21:36:15 +00:00
|
|
|
#include "aterm.hh"
|
|
|
|
#include "nixexpr.hh"
|
|
|
|
#include "nixexpr-ast.hh"
|
2006-10-02 14:43:15 +00:00
|
|
|
#define BISON_HEADER_HACK
|
2006-09-04 21:06:23 +00:00
|
|
|
#include "parser-tab.hh"
|
2004-01-30 15:21:42 +00:00
|
|
|
|
2006-09-04 21:36:15 +00:00
|
|
|
using namespace nix;
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
2004-01-30 15:21:42 +00:00
|
|
|
static void initLoc(YYLTYPE * loc)
|
|
|
|
{
|
|
|
|
loc->first_line = 1;
|
|
|
|
loc->first_column = 1;
|
|
|
|
}
|
|
|
|
|
2006-09-04 21:36:15 +00:00
|
|
|
|
2004-01-30 15:21:42 +00:00
|
|
|
static void adjustLoc(YYLTYPE * loc, const char * s, size_t len)
|
|
|
|
{
|
|
|
|
while (len--) {
|
|
|
|
switch (*s++) {
|
2006-08-16 10:28:44 +00:00
|
|
|
case '\r':
|
|
|
|
if (*s == '\n') /* cr/lf */
|
|
|
|
s++;
|
|
|
|
/* fall through */
|
2004-01-30 15:21:42 +00:00
|
|
|
case '\n':
|
|
|
|
++loc->first_line;
|
|
|
|
loc->first_column = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
++loc->first_column;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-04 21:36:15 +00:00
|
|
|
|
|
|
|
static Expr unescapeStr(const char * s)
|
2006-09-04 21:06:23 +00:00
|
|
|
{
|
2006-09-04 21:36:15 +00:00
|
|
|
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;
|
|
|
|
}
|
2006-10-16 15:55:34 +00:00
|
|
|
return makeStr(toATerm(t), ATempty);
|
2006-09-04 21:06:23 +00:00
|
|
|
}
|
|
|
|
|
2006-09-04 21:36:15 +00:00
|
|
|
|
|
|
|
}
|
2006-05-01 14:01:47 +00:00
|
|
|
|
2004-01-30 15:21:42 +00:00
|
|
|
#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]+
|
|
|
|
PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+
|
2004-03-28 20:34:22 +00:00
|
|
|
URI [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']+
|
2004-01-30 15:21:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
|
|
if { return IF; }
|
|
|
|
then { return THEN; }
|
|
|
|
else { return ELSE; }
|
|
|
|
assert { return ASSERT; }
|
2004-10-25 16:54:56 +00:00
|
|
|
with { return WITH; }
|
2004-01-30 15:21:42 +00:00
|
|
|
let { return LET; }
|
2006-10-02 15:52:44 +00:00
|
|
|
in { return IN; }
|
2004-01-30 15:21:42 +00:00
|
|
|
rec { return REC; }
|
2004-02-02 21:39:33 +00:00
|
|
|
inherit { return INHERIT; }
|
2004-01-30 15:21:42 +00:00
|
|
|
|
|
|
|
\=\= { return EQ; }
|
|
|
|
\!\= { return NEQ; }
|
|
|
|
\&\& { return AND; }
|
|
|
|
\|\| { return OR; }
|
|
|
|
\-\> { return IMPL; }
|
2004-02-04 16:49:51 +00:00
|
|
|
\/\/ { return UPDATE; }
|
2005-07-25 15:05:34 +00:00
|
|
|
\+\+ { return CONCAT; }
|
2004-01-30 15:21:42 +00:00
|
|
|
|
2006-05-01 14:01:47 +00:00
|
|
|
{ID} { yylval->t = toATerm(yytext); return ID; /* !!! alloc */ }
|
2004-01-30 17:06:03 +00:00
|
|
|
{INT} { int n = atoi(yytext); /* !!! overflow */
|
|
|
|
yylval->t = ATmake("<int>", n);
|
|
|
|
return INT;
|
|
|
|
}
|
2006-05-01 14:01:47 +00:00
|
|
|
|
|
|
|
\" { BEGIN(STRING); return '"'; }
|
2006-09-01 12:04:06 +00:00
|
|
|
<STRING>([^\$\"\\]|\$[^\{\"]|\\.)+ {
|
|
|
|
/* !!! Not quite right: we want a follow restriction on "$", it
|
|
|
|
shouldn't be followed by a "{". Right now "$\"" will be consumed
|
|
|
|
as part of a string, rather than a "$" followed by the string
|
|
|
|
terminator. Disallow "$\"" for now. */
|
2006-05-01 14:01:47 +00:00
|
|
|
yylval->t = unescapeStr(yytext); /* !!! alloc */
|
|
|
|
return STR;
|
2004-01-30 15:21:42 +00:00
|
|
|
}
|
2006-05-01 14:01:47 +00:00
|
|
|
<STRING>\$\{ { BEGIN(INITIAL); return DOLLAR_CURLY; }
|
|
|
|
<STRING>\" { BEGIN(INITIAL); return '"'; }
|
|
|
|
<STRING>. return yytext[0]; /* just in case: shouldn't be reached */
|
|
|
|
|
2007-11-30 16:48:45 +00:00
|
|
|
\'\'(\ *\n)? { BEGIN(IND_STRING); return IND_STRING_OPEN; }
|
2008-02-05 13:38:07 +00:00
|
|
|
<IND_STRING>([^\$\']|\$[^\{\']|\'[^\'\$])+ {
|
2007-11-30 16:48:45 +00:00
|
|
|
yylval->t = makeIndStr(toATerm(yytext));
|
|
|
|
return IND_STR;
|
2007-12-06 10:20:58 +00:00
|
|
|
}
|
|
|
|
<IND_STRING>\'\'\$ {
|
|
|
|
yylval->t = makeIndStr(toATerm("$"));
|
|
|
|
return IND_STR;
|
|
|
|
}
|
|
|
|
<IND_STRING>\'\'\' {
|
|
|
|
yylval->t = makeIndStr(toATerm("''"));
|
|
|
|
return IND_STR;
|
|
|
|
}
|
|
|
|
<IND_STRING>\'\'\\. {
|
|
|
|
yylval->t = unescapeStr(yytext + 2);
|
|
|
|
return IND_STR;
|
2007-11-30 16:48:45 +00:00
|
|
|
}
|
|
|
|
<IND_STRING>\$\{ { BEGIN(INITIAL); return DOLLAR_CURLY; }
|
|
|
|
<IND_STRING>\'\' { BEGIN(INITIAL); return IND_STRING_CLOSE; }
|
2008-02-05 13:38:07 +00:00
|
|
|
<IND_STRING>\' {
|
|
|
|
yylval->t = makeIndStr(toATerm("'"));
|
|
|
|
return IND_STR;
|
|
|
|
}
|
2007-11-30 16:48:45 +00:00
|
|
|
<IND_STRING>. return yytext[0]; /* just in case: shouldn't be reached */
|
2006-05-01 14:01:47 +00:00
|
|
|
|
|
|
|
{PATH} { yylval->t = toATerm(yytext); return PATH; /* !!! alloc */ }
|
|
|
|
{URI} { yylval->t = toATerm(yytext); return URI; /* !!! alloc */ }
|
2004-01-30 15:21:42 +00:00
|
|
|
|
2006-08-16 10:28:44 +00:00
|
|
|
[ \t\r\n]+ /* eat up whitespace */
|
|
|
|
\#[^\r\n]* /* single-line comments */
|
2004-10-27 13:00:31 +00:00
|
|
|
\/\*([^*]|\*[^\/])*\*\/ /* long comments */
|
2004-01-30 15:21:42 +00:00
|
|
|
|
|
|
|
. return yytext[0];
|
|
|
|
|
|
|
|
|
|
|
|
%%
|
2006-05-01 14:01:47 +00:00
|
|
|
|
2006-09-04 21:36:15 +00:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2006-05-01 14:01:47 +00:00
|
|
|
/* 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)
|
|
|
|
{
|
2006-09-04 21:36:15 +00:00
|
|
|
struct yyguts_t * yyg = (struct yyguts_t *) scanner;
|
2006-05-01 14:01:47 +00:00
|
|
|
BEGIN(STRING);
|
|
|
|
}
|
2006-09-04 21:36:15 +00:00
|
|
|
|
2007-11-30 16:48:45 +00:00
|
|
|
void backToIndString(yyscan_t scanner)
|
|
|
|
{
|
|
|
|
struct yyguts_t * yyg = (struct yyguts_t *) scanner;
|
|
|
|
BEGIN(IND_STRING);
|
|
|
|
}
|
|
|
|
|
2006-09-04 21:36:15 +00:00
|
|
|
}
|