2004-01-30 15:21:42 +00:00
|
|
|
|
%option reentrant bison-bridge bison-locations
|
|
|
|
|
%option noyywrap
|
|
|
|
|
%option never-interactive
|
2015-07-02 16:39:02 +00:00
|
|
|
|
%option stack
|
|
|
|
|
%option nodefault
|
|
|
|
|
%option nounput noyy_top_state
|
2004-01-30 15:21:42 +00:00
|
|
|
|
|
|
|
|
|
|
2006-05-01 14:01:47 +00:00
|
|
|
|
%x STRING
|
2007-11-30 16:48:45 +00:00
|
|
|
|
%x IND_STRING
|
2016-01-12 20:34:31 +00:00
|
|
|
|
%x INSIDE_DOLLAR_CURLY
|
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-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 {
|
|
|
|
|
|
2013-09-02 14:29:15 +00:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2013-09-02 14:29: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 */
|
2013-09-02 14:29:15 +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
|
|
|
|
}
|
|
|
|
|
|
2013-09-02 14:29:15 +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);
|
|
|
|
|
|
2015-07-02 16:39:02 +00:00
|
|
|
|
#define PUSH_STATE(state) yy_push_state(state, yyscanner)
|
|
|
|
|
#define POP_STATE() yy_pop_state(yyscanner)
|
|
|
|
|
|
2004-01-30 15:21:42 +00:00
|
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
|
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\.\_\-\+]+)+
|
2015-02-19 13:05:16 +00:00
|
|
|
|
HPATH \~(\/[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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
2016-01-12 20:34:31 +00:00
|
|
|
|
<INITIAL,INSIDE_DOLLAR_CURLY>{
|
|
|
|
|
|
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; }
|
2013-08-02 16:39:40 +00:00
|
|
|
|
\<\= { return LEQ; }
|
|
|
|
|
\>\= { return GEQ; }
|
2004-01-30 15:21:42 +00:00
|
|
|
|
\&\& { 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; }
|
2013-08-19 10:35:03 +00:00
|
|
|
|
{INT} { errno = 0;
|
|
|
|
|
yylval->n = strtol(yytext, 0, 10);
|
|
|
|
|
if (errno != 0)
|
2014-08-20 15:00:17 +00:00
|
|
|
|
throw ParseError(format("invalid integer ‘%1%’") % yytext);
|
2004-01-30 17:06:03 +00:00
|
|
|
|
return INT;
|
|
|
|
|
}
|
2006-05-01 14:01:47 +00:00
|
|
|
|
|
2016-01-12 20:34:31 +00:00
|
|
|
|
\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }
|
|
|
|
|
\{ { return '{'; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
\} { return '}'; }
|
|
|
|
|
<INSIDE_DOLLAR_CURLY>\} { POP_STATE(); return '}'; }
|
|
|
|
|
|
|
|
|
|
<INITIAL,INSIDE_DOLLAR_CURLY>\" { PUSH_STATE(STRING); return '"'; }
|
2014-01-06 15:27:26 +00:00
|
|
|
|
|
2015-07-02 21:53:04 +00:00
|
|
|
|
<STRING>([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)*\$/\" |
|
|
|
|
|
<STRING>([^\$\"\\]|\$[^\{\"\\]|\\.|\$\\.)+ {
|
|
|
|
|
/* 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.) */
|
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
|
|
|
|
}
|
2016-01-12 20:34:31 +00:00
|
|
|
|
<STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }
|
2015-07-02 16:39:02 +00:00
|
|
|
|
<STRING>\" { POP_STATE(); return '"'; }
|
2006-05-01 14:01:47 +00:00
|
|
|
|
<STRING>. return yytext[0]; /* just in case: shouldn't be reached */
|
|
|
|
|
|
2016-01-12 20:34:31 +00:00
|
|
|
|
<INITIAL,INSIDE_DOLLAR_CURLY>\'\'(\ *\n)? { PUSH_STATE(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
|
|
|
|
}
|
2016-01-12 20:34:31 +00:00
|
|
|
|
<IND_STRING>\$\{ { PUSH_STATE(INSIDE_DOLLAR_CURLY); return DOLLAR_CURLY; }
|
2015-07-02 16:39:02 +00:00
|
|
|
|
<IND_STRING>\'\' { POP_STATE(); 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
|
|
|
|
|
2016-01-12 20:34:31 +00:00
|
|
|
|
<INITIAL,INSIDE_DOLLAR_CURLY>{
|
|
|
|
|
|
2010-04-12 18:30:11 +00:00
|
|
|
|
{PATH} { yylval->path = strdup(yytext); return PATH; }
|
2015-02-19 13:05:16 +00:00
|
|
|
|
{HPATH} { yylval->path = strdup(yytext); return HPATH; }
|
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];
|
|
|
|
|
|
2016-01-12 20:34:31 +00:00
|
|
|
|
}
|
2004-01-30 15:21:42 +00:00
|
|
|
|
|
|
|
|
|
%%
|
2006-05-01 14:01:47 +00:00
|
|
|
|
|