2004-01-30 17:21:42 +02:00
|
|
|
%option reentrant bison-bridge bison-locations
|
|
|
|
%option noyywrap
|
|
|
|
%option never-interactive
|
2015-07-02 19:39:02 +03:00
|
|
|
%option stack
|
|
|
|
%option nodefault
|
|
|
|
%option nounput noyy_top_state
|
2004-01-30 17:21:42 +02:00
|
|
|
|
|
|
|
|
2006-05-01 17:01:47 +03:00
|
|
|
%x STRING
|
2007-11-30 18:48:45 +02:00
|
|
|
%x IND_STRING
|
2016-01-20 17:34:42 +02:00
|
|
|
%x INSIDE_DOLLAR_CURLY
|
2006-05-01 17:01:47 +03:00
|
|
|
|
|
|
|
|
2004-01-30 17:21:42 +02:00
|
|
|
%{
|
2006-09-05 00:36:15 +03:00
|
|
|
#include "nixexpr.hh"
|
2006-09-05 00:06:23 +03:00
|
|
|
#include "parser-tab.hh"
|
2004-01-30 17:21:42 +02:00
|
|
|
|
2006-09-05 00:36:15 +03:00
|
|
|
using namespace nix;
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2013-09-02 17:29:15 +03:00
|
|
|
|
2004-01-30 17:21:42 +02:00
|
|
|
static void initLoc(YYLTYPE * loc)
|
|
|
|
{
|
2010-05-06 19:46:48 +03:00
|
|
|
loc->first_line = loc->last_line = 1;
|
|
|
|
loc->first_column = loc->last_column = 1;
|
2004-01-30 17:21:42 +02:00
|
|
|
}
|
|
|
|
|
2013-09-02 17:29:15 +03:00
|
|
|
|
2004-01-30 17:21:42 +02:00
|
|
|
static void adjustLoc(YYLTYPE * loc, const char * s, size_t len)
|
|
|
|
{
|
2010-05-06 19:46:48 +03:00
|
|
|
loc->first_line = loc->last_line;
|
|
|
|
loc->first_column = loc->last_column;
|
|
|
|
|
2004-01-30 17:21:42 +02:00
|
|
|
while (len--) {
|
|
|
|
switch (*s++) {
|
2006-08-16 13:28:44 +03:00
|
|
|
case '\r':
|
|
|
|
if (*s == '\n') /* cr/lf */
|
|
|
|
s++;
|
|
|
|
/* fall through */
|
2013-09-02 17:29:15 +03:00
|
|
|
case '\n':
|
2010-05-06 19:46:48 +03:00
|
|
|
++loc->last_line;
|
|
|
|
loc->last_column = 1;
|
2004-01-30 17:21:42 +02:00
|
|
|
break;
|
|
|
|
default:
|
2010-05-06 19:46:48 +03:00
|
|
|
++loc->last_column;
|
2004-01-30 17:21:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-05 00:36:15 +03:00
|
|
|
|
2010-10-24 00:11:59 +03:00
|
|
|
static Expr * unescapeStr(SymbolTable & symbols, const char * s)
|
2006-09-05 00:06:23 +03:00
|
|
|
{
|
2006-09-05 00:36:15 +03: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-24 00:11:59 +03:00
|
|
|
return new ExprString(symbols.create(t));
|
2006-09-05 00:06:23 +03:00
|
|
|
}
|
|
|
|
|
2013-09-02 17:29:15 +03:00
|
|
|
|
2006-09-05 00:36:15 +03:00
|
|
|
}
|
2006-05-01 17:01:47 +03:00
|
|
|
|
2004-01-30 17:21:42 +02:00
|
|
|
#define YY_USER_INIT initLoc(yylloc)
|
|
|
|
#define YY_USER_ACTION adjustLoc(yylloc, yytext, yyleng);
|
|
|
|
|
2015-07-02 19:39:02 +03:00
|
|
|
#define PUSH_STATE(state) yy_push_state(state, yyscanner)
|
|
|
|
#define POP_STATE() yy_pop_state(yyscanner)
|
|
|
|
|
2004-01-30 17:21:42 +02:00
|
|
|
%}
|
|
|
|
|
|
|
|
|
2012-09-27 22:43:08 +03:00
|
|
|
ID [a-zA-Z\_][a-zA-Z0-9\_\'\-]*
|
2004-01-30 17:21:42 +02:00
|
|
|
INT [0-9]+
|
2016-01-05 10:54:49 +02:00
|
|
|
FLOAT (([1-9][0-9]*\.[0-9]*)|(0?\.[0-9]+))([Ee][+-]?[0-9]+)?
|
2016-06-24 16:30:19 +03:00
|
|
|
PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+\/?
|
|
|
|
HPATH \~(\/[a-zA-Z0-9\.\_\-\+]+)+\/?
|
2011-08-06 19:05:24 +03:00
|
|
|
SPATH \<[a-zA-Z0-9\.\_\-\+]+(\/[a-zA-Z0-9\.\_\-\+]+)*\>
|
2017-11-14 16:10:52 +02:00
|
|
|
URI [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']+
|
2004-01-30 17:21:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2016-01-20 17:34:42 +02:00
|
|
|
<INITIAL,INSIDE_DOLLAR_CURLY>{
|
|
|
|
|
2004-01-30 17:21:42 +02:00
|
|
|
|
|
|
|
if { return IF; }
|
|
|
|
then { return THEN; }
|
|
|
|
else { return ELSE; }
|
|
|
|
assert { return ASSERT; }
|
2004-10-25 19:54:56 +03:00
|
|
|
with { return WITH; }
|
2004-01-30 17:21:42 +02:00
|
|
|
let { return LET; }
|
2006-10-02 18:52:44 +03:00
|
|
|
in { return IN; }
|
2004-01-30 17:21:42 +02:00
|
|
|
rec { return REC; }
|
2004-02-02 23:39:33 +02:00
|
|
|
inherit { return INHERIT; }
|
2011-07-13 15:19:57 +03:00
|
|
|
or { return OR_KW; }
|
2008-08-14 17:00:44 +03:00
|
|
|
\.\.\. { return ELLIPSIS; }
|
2004-01-30 17:21:42 +02:00
|
|
|
|
|
|
|
\=\= { return EQ; }
|
|
|
|
\!\= { return NEQ; }
|
2013-08-02 19:39:40 +03:00
|
|
|
\<\= { return LEQ; }
|
|
|
|
\>\= { return GEQ; }
|
2004-01-30 17:21:42 +02:00
|
|
|
\&\& { return AND; }
|
|
|
|
\|\| { return OR; }
|
|
|
|
\-\> { return IMPL; }
|
2004-02-04 18:49:51 +02:00
|
|
|
\/\/ { return UPDATE; }
|
2005-07-25 18:05:34 +03:00
|
|
|
\+\+ { return CONCAT; }
|
2004-01-30 17:21:42 +02:00
|
|
|
|
2010-04-12 21:30:11 +03:00
|
|
|
{ID} { yylval->id = strdup(yytext); return ID; }
|
2013-08-19 13:35:03 +03:00
|
|
|
{INT} { errno = 0;
|
|
|
|
yylval->n = strtol(yytext, 0, 10);
|
|
|
|
if (errno != 0)
|
2017-07-30 14:27:57 +03:00
|
|
|
throw ParseError(format("invalid integer '%1%'") % yytext);
|
2004-01-30 19:06:03 +02:00
|
|
|
return INT;
|
|
|
|
}
|
2016-01-05 01:40:40 +02:00
|
|
|
{FLOAT} { errno = 0;
|
2016-01-05 10:46:37 +02:00
|
|
|
yylval->nf = strtod(yytext, 0);
|
2016-01-05 01:40:40 +02:00
|
|
|
if (errno != 0)
|
2017-07-30 14:27:57 +03:00
|
|
|
throw ParseError(format("invalid float '%1%'") % yytext);
|
2016-01-05 01:40:40 +02:00
|
|
|
return FLOAT;
|
|
|
|
}
|
2006-05-01 17:01:47 +03:00
|
|
|
|
2016-01-20 17:34:42 +02:00
|
|
|
\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }
|
|
|
|
}
|
|
|
|
|
|
|
|
\} { return '}'; }
|
|
|
|
<INSIDE_DOLLAR_CURLY>\} { POP_STATE(); return '}'; }
|
|
|
|
\{ { return '{'; }
|
|
|
|
<INSIDE_DOLLAR_CURLY>\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return '{'; }
|
2014-01-06 17:27:26 +02:00
|
|
|
|
2017-05-01 02:07:33 +03:00
|
|
|
<INITIAL,INSIDE_DOLLAR_CURLY>\" {
|
|
|
|
PUSH_STATE(STRING); return '"';
|
|
|
|
}
|
2015-07-03 00:53:04 +03:00
|
|
|
<STRING>([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)*\$/\" |
|
|
|
|
<STRING>([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)+ {
|
2017-05-01 02:07:33 +03:00
|
|
|
/* It is impossible to match strings ending with '$' with one
|
|
|
|
regex because trailing contexts are only valid at the end
|
|
|
|
of a rule. (A sane but undocumented limitation.) */
|
|
|
|
yylval->e = unescapeStr(data->symbols, yytext);
|
|
|
|
return STR;
|
|
|
|
}
|
2016-01-20 17:34:42 +02:00
|
|
|
<STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }
|
2017-05-01 02:07:33 +03:00
|
|
|
<STRING>\" { POP_STATE(); return '"'; }
|
|
|
|
<STRING>\$|\\|\$\\ {
|
|
|
|
/* This can only occur when we reach EOF, otherwise the above
|
|
|
|
(...|\$[^\{\"\\]|\\.|\$\\.)+ would have triggered.
|
|
|
|
This is technically invalid, but we leave the problem to the
|
|
|
|
parser who fails with exact location. */
|
|
|
|
return STR;
|
|
|
|
}
|
2006-05-01 17:01:47 +03:00
|
|
|
|
2016-01-20 17:34:42 +02:00
|
|
|
<INITIAL,INSIDE_DOLLAR_CURLY>\'\'(\ *\n)? { PUSH_STATE(IND_STRING); return IND_STRING_OPEN; }
|
2008-02-05 15:38:07 +02:00
|
|
|
<IND_STRING>([^\$\']|\$[^\{\']|\'[^\'\$])+ {
|
2010-04-13 01:03:27 +03:00
|
|
|
yylval->e = new ExprIndStr(yytext);
|
2007-11-30 18:48:45 +02:00
|
|
|
return IND_STR;
|
2007-12-06 12:20:58 +02:00
|
|
|
}
|
2017-05-01 02:05:41 +03:00
|
|
|
<IND_STRING>\'\'\$ |
|
|
|
|
<IND_STRING>\$ {
|
2010-04-13 01:03:27 +03:00
|
|
|
yylval->e = new ExprIndStr("$");
|
2007-12-06 12:20:58 +02:00
|
|
|
return IND_STR;
|
|
|
|
}
|
|
|
|
<IND_STRING>\'\'\' {
|
2010-04-13 01:03:27 +03:00
|
|
|
yylval->e = new ExprIndStr("''");
|
2007-12-06 12:20:58 +02:00
|
|
|
return IND_STR;
|
|
|
|
}
|
|
|
|
<IND_STRING>\'\'\\. {
|
2010-10-24 00:11:59 +03:00
|
|
|
yylval->e = unescapeStr(data->symbols, yytext + 2);
|
2007-12-06 12:20:58 +02:00
|
|
|
return IND_STR;
|
2007-11-30 18:48:45 +02:00
|
|
|
}
|
2016-01-20 17:34:42 +02:00
|
|
|
<IND_STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }
|
2015-07-02 19:39:02 +03:00
|
|
|
<IND_STRING>\'\' { POP_STATE(); return IND_STRING_CLOSE; }
|
2008-02-05 15:38:07 +02:00
|
|
|
<IND_STRING>\' {
|
2010-04-13 01:03:27 +03:00
|
|
|
yylval->e = new ExprIndStr("'");
|
2008-02-05 15:38:07 +02:00
|
|
|
return IND_STR;
|
|
|
|
}
|
2006-05-01 17:01:47 +03:00
|
|
|
|
2016-01-20 17:34:42 +02:00
|
|
|
<INITIAL,INSIDE_DOLLAR_CURLY>{
|
|
|
|
|
2016-06-24 16:30:19 +03:00
|
|
|
{PATH} { if (yytext[yyleng-1] == '/')
|
2017-07-30 14:27:57 +03:00
|
|
|
throw ParseError("path '%s' has a trailing slash", yytext);
|
2016-06-24 16:30:19 +03:00
|
|
|
yylval->path = strdup(yytext);
|
|
|
|
return PATH;
|
|
|
|
}
|
|
|
|
{HPATH} { if (yytext[yyleng-1] == '/')
|
2017-07-30 14:27:57 +03:00
|
|
|
throw ParseError("path '%s' has a trailing slash", yytext);
|
2016-06-24 16:30:19 +03:00
|
|
|
yylval->path = strdup(yytext);
|
|
|
|
return HPATH;
|
|
|
|
}
|
2011-08-06 19:05:24 +03:00
|
|
|
{SPATH} { yylval->path = strdup(yytext); return SPATH; }
|
2010-04-12 21:30:11 +03:00
|
|
|
{URI} { yylval->uri = strdup(yytext); return URI; }
|
2004-01-30 17:21:42 +02:00
|
|
|
|
2006-08-16 13:28:44 +03:00
|
|
|
[ \t\r\n]+ /* eat up whitespace */
|
|
|
|
\#[^\r\n]* /* single-line comments */
|
2016-11-13 18:06:04 +02:00
|
|
|
\/\*([^*]|\*+[^*/])*\*+\/ /* long comments */
|
2004-01-30 17:21:42 +02:00
|
|
|
|
|
|
|
. return yytext[0];
|
|
|
|
|
2016-01-20 17:34:42 +02:00
|
|
|
}
|
2004-01-30 17:21:42 +02:00
|
|
|
|
2016-02-24 12:32:18 +02:00
|
|
|
<<EOF>> { data->atEnd = true; return 0; }
|
|
|
|
|
2004-01-30 17:21:42 +02:00
|
|
|
%%
|
2006-05-01 17:01:47 +03:00
|
|
|
|