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