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 "nixexpr.hh"
|
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 {
|
|
|
|
|
|
2013-09-02 16:29:15 +02:00
|
|
|
|
|
2004-01-30 16:21:42 +01:00
|
|
|
|
static void initLoc(YYLTYPE * loc)
|
|
|
|
|
{
|
2010-05-06 18:46:48 +02:00
|
|
|
|
loc->first_line = loc->last_line = 1;
|
|
|
|
|
loc->first_column = loc->last_column = 1;
|
2004-01-30 16:21:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-02 16:29:15 +02:00
|
|
|
|
|
2004-01-30 16:21:42 +01:00
|
|
|
|
static void adjustLoc(YYLTYPE * loc, const char * s, size_t len)
|
|
|
|
|
{
|
2010-05-06 18:46:48 +02:00
|
|
|
|
loc->first_line = loc->last_line;
|
|
|
|
|
loc->first_column = loc->last_column;
|
|
|
|
|
|
2004-01-30 16:21:42 +01:00
|
|
|
|
while (len--) {
|
|
|
|
|
switch (*s++) {
|
2006-08-16 12:28:44 +02:00
|
|
|
|
case '\r':
|
|
|
|
|
if (*s == '\n') /* cr/lf */
|
|
|
|
|
s++;
|
|
|
|
|
/* fall through */
|
2013-09-02 16:29:15 +02:00
|
|
|
|
case '\n':
|
2010-05-06 18:46:48 +02:00
|
|
|
|
++loc->last_line;
|
|
|
|
|
loc->last_column = 1;
|
2004-01-30 16:21:42 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2010-05-06 18:46:48 +02:00
|
|
|
|
++loc->last_column;
|
2004-01-30 16:21:42 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-04 23:36:15 +02:00
|
|
|
|
|
2010-10-23 23:11:59 +02:00
|
|
|
|
static Expr * unescapeStr(SymbolTable & symbols, 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;
|
|
|
|
|
}
|
2010-10-23 23:11:59 +02:00
|
|
|
|
return new ExprString(symbols.create(t));
|
2006-09-04 23:06:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-02 16:29:15 +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);
|
|
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
|
2012-09-27 21:43:08 +02:00
|
|
|
|
ID [a-zA-Z\_][a-zA-Z0-9\_\'\-]*
|
2004-01-30 16:21:42 +01:00
|
|
|
|
INT [0-9]+
|
|
|
|
|
PATH [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+
|
2015-02-19 14:05:16 +01:00
|
|
|
|
HPATH \~(\/[a-zA-Z0-9\.\_\-\+]+)+
|
2011-08-06 18:05:24 +02:00
|
|
|
|
SPATH \<[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; }
|
2011-07-13 14:19:57 +02:00
|
|
|
|
or { return OR_KW; }
|
2008-08-14 16:00:44 +02:00
|
|
|
|
\.\.\. { return ELLIPSIS; }
|
2004-01-30 16:21:42 +01:00
|
|
|
|
|
|
|
|
|
\=\= { return EQ; }
|
|
|
|
|
\!\= { return NEQ; }
|
2013-08-02 18:39:40 +02:00
|
|
|
|
\<\= { return LEQ; }
|
|
|
|
|
\>\= { return GEQ; }
|
2004-01-30 16:21:42 +01:00
|
|
|
|
\&\& { 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
|
|
|
|
|
2010-04-12 20:30:11 +02:00
|
|
|
|
{ID} { yylval->id = strdup(yytext); return ID; }
|
2013-08-19 12:35:03 +02:00
|
|
|
|
{INT} { errno = 0;
|
|
|
|
|
yylval->n = strtol(yytext, 0, 10);
|
|
|
|
|
if (errno != 0)
|
2014-08-20 17:00:17 +02:00
|
|
|
|
throw ParseError(format("invalid integer ‘%1%’") % yytext);
|
2004-01-30 18:06:03 +01:00
|
|
|
|
return INT;
|
|
|
|
|
}
|
2006-05-01 16:01:47 +02:00
|
|
|
|
|
2014-01-06 16:27:26 +01:00
|
|
|
|
\$\{ { return DOLLAR_CURLY; }
|
|
|
|
|
|
2006-05-01 16:01:47 +02:00
|
|
|
|
\" { BEGIN(STRING); return '"'; }
|
2006-09-01 14:04:06 +02:00
|
|
|
|
<STRING>([^\$\"\\]|\$[^\{\"]|\\.)+ {
|
2010-04-13 00:03:27 +02: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 23:11:59 +02:00
|
|
|
|
yylval->e = unescapeStr(data->symbols, yytext);
|
2006-05-01 16:01:47 +02:00
|
|
|
|
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>([^\$\']|\$[^\{\']|\'[^\'\$])+ {
|
2010-04-13 00:03:27 +02:00
|
|
|
|
yylval->e = new ExprIndStr(yytext);
|
2007-11-30 17:48:45 +01:00
|
|
|
|
return IND_STR;
|
2007-12-06 11:20:58 +01:00
|
|
|
|
}
|
|
|
|
|
<IND_STRING>\'\'\$ {
|
2010-04-13 00:03:27 +02:00
|
|
|
|
yylval->e = new ExprIndStr("$");
|
2007-12-06 11:20:58 +01:00
|
|
|
|
return IND_STR;
|
|
|
|
|
}
|
|
|
|
|
<IND_STRING>\'\'\' {
|
2010-04-13 00:03:27 +02:00
|
|
|
|
yylval->e = new ExprIndStr("''");
|
2007-12-06 11:20:58 +01:00
|
|
|
|
return IND_STR;
|
|
|
|
|
}
|
|
|
|
|
<IND_STRING>\'\'\\. {
|
2010-10-23 23:11:59 +02:00
|
|
|
|
yylval->e = unescapeStr(data->symbols, yytext + 2);
|
2007-12-06 11:20:58 +01:00
|
|
|
|
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>\' {
|
2010-04-13 00:03:27 +02:00
|
|
|
|
yylval->e = new ExprIndStr("'");
|
2008-02-05 14:38:07 +01:00
|
|
|
|
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
|
|
|
|
|
2010-04-12 20:30:11 +02:00
|
|
|
|
{PATH} { yylval->path = strdup(yytext); return PATH; }
|
2015-02-19 14:05:16 +01:00
|
|
|
|
{HPATH} { yylval->path = strdup(yytext); return HPATH; }
|
2011-08-06 18:05:24 +02:00
|
|
|
|
{SPATH} { yylval->path = strdup(yytext); return SPATH; }
|
2010-04-12 20:30:11 +02:00
|
|
|
|
{URI} { yylval->uri = strdup(yytext); return URI; }
|
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 {
|
2013-09-02 16:29:15 +02:00
|
|
|
|
|
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
|
|
|
|
}
|