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 "nixexpr.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)
|
|
|
|
{
|
2010-05-06 16:46:48 +00:00
|
|
|
loc->first_line = loc->last_line = 1;
|
|
|
|
loc->first_column = loc->last_column = 1;
|
2004-01-30 15:21:42 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2010-05-06 16:46:48 +00:00
|
|
|
loc->first_line = loc->last_line;
|
|
|
|
loc->first_column = loc->last_column;
|
|
|
|
|
2004-01-30 15:21:42 +00:00
|
|
|
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':
|
2010-05-06 16:46:48 +00:00
|
|
|
++loc->last_line;
|
|
|
|
loc->last_column = 1;
|
2004-01-30 15:21:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-05-06 16:46:48 +00:00
|
|
|
++loc->last_column;
|
2004-01-30 15:21:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-04 21:36:15 +00:00
|
|
|
|
2010-10-23 21:11:59 +00:00
|
|
|
static Expr * unescapeStr(SymbolTable & symbols, 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;
|
|
|
|
}
|
2010-10-23 21:11:59 +00:00
|
|
|
return new ExprString(symbols.create(t));
|
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);
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
|
2012-09-27 19:43:08 +00:00
|
|
|
ID [a-zA-Z\_][a-zA-Z0-9\_\'\-]*
|
2004-01-30 15:21:42 +00:00
|
|
|
INT [0-9]+
|
|
|
|
PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+
|
2011-08-06 16:05:24 +00:00
|
|
|
SPATH \<[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; }
|
2011-07-13 12:19:57 +00:00
|
|
|
or { return OR_KW; }
|
2008-08-14 14:00:44 +00:00
|
|
|
\.\.\. { return ELLIPSIS; }
|
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
|
|
|
|
2010-04-12 18:30:11 +00:00
|
|
|
{ID} { yylval->id = strdup(yytext); return ID; }
|
2004-01-30 17:06:03 +00:00
|
|
|
{INT} { int n = atoi(yytext); /* !!! overflow */
|
2010-04-12 10:38:18 +00:00
|
|
|
yylval->n = n;
|
2004-01-30 17:06:03 +00:00
|
|
|
return INT;
|
|
|
|
}
|
2006-05-01 14:01:47 +00:00
|
|
|
|
|
|
|
\" { BEGIN(STRING); return '"'; }
|
2006-09-01 12:04:06 +00:00
|
|
|
<STRING>([^\$\"\\]|\$[^\{\"]|\\.)+ {
|
2010-04-12 22:03:27 +00:00
|
|
|
/* !!! 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. */
|
2010-10-23 21:11:59 +00:00
|
|
|
yylval->e = unescapeStr(data->symbols, yytext);
|
2006-05-01 14:01:47 +00:00
|
|
|
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>([^\$\']|\$[^\{\']|\'[^\'\$])+ {
|
2010-04-12 22:03:27 +00:00
|
|
|
yylval->e = new ExprIndStr(yytext);
|
2007-11-30 16:48:45 +00:00
|
|
|
return IND_STR;
|
2007-12-06 10:20:58 +00:00
|
|
|
}
|
|
|
|
<IND_STRING>\'\'\$ {
|
2010-04-12 22:03:27 +00:00
|
|
|
yylval->e = new ExprIndStr("$");
|
2007-12-06 10:20:58 +00:00
|
|
|
return IND_STR;
|
|
|
|
}
|
|
|
|
<IND_STRING>\'\'\' {
|
2010-04-12 22:03:27 +00:00
|
|
|
yylval->e = new ExprIndStr("''");
|
2007-12-06 10:20:58 +00:00
|
|
|
return IND_STR;
|
|
|
|
}
|
|
|
|
<IND_STRING>\'\'\\. {
|
2010-10-23 21:11:59 +00:00
|
|
|
yylval->e = unescapeStr(data->symbols, yytext + 2);
|
2007-12-06 10:20:58 +00:00
|
|
|
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>\' {
|
2010-04-12 22:03:27 +00:00
|
|
|
yylval->e = new ExprIndStr("'");
|
2008-02-05 13:38:07 +00:00
|
|
|
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
|
|
|
|
2010-04-12 18:30:11 +00:00
|
|
|
{PATH} { yylval->path = strdup(yytext); return PATH; }
|
2011-08-06 16:05:24 +00:00
|
|
|
{SPATH} { yylval->path = strdup(yytext); return SPATH; }
|
2010-04-12 18:30:11 +00:00
|
|
|
{URI} { yylval->uri = strdup(yytext); return URI; }
|
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
|
|
|
}
|