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
|
|
|
|
|
|
|
|
|
2004-01-30 16:21:42 +01:00
|
|
|
%{
|
|
|
|
#include <string.h>
|
|
|
|
#include <aterm2.h>
|
|
|
|
#include "parser-tab.h"
|
|
|
|
|
|
|
|
static void initLoc(YYLTYPE * loc)
|
|
|
|
{
|
|
|
|
loc->first_line = 1;
|
|
|
|
loc->first_column = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void adjustLoc(YYLTYPE * loc, const char * s, size_t len)
|
|
|
|
{
|
|
|
|
while (len--) {
|
|
|
|
switch (*s++) {
|
|
|
|
case '\n':
|
|
|
|
++loc->first_line;
|
|
|
|
loc->first_column = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
++loc->first_column;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-01 16:01:47 +02:00
|
|
|
ATerm toATerm(const char * s);
|
|
|
|
ATerm unescapeStr(const char * s);
|
|
|
|
|
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; }
|
|
|
|
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-05-01 17:29:46 +02:00
|
|
|
<STRING>([^\$\"\\]|\\.)+ {
|
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 */
|
|
|
|
|
|
|
|
|
|
|
|
{PATH} { yylval->t = toATerm(yytext); return PATH; /* !!! alloc */ }
|
|
|
|
{URI} { yylval->t = toATerm(yytext); return URI; /* !!! alloc */ }
|
2004-01-30 16:21:42 +01:00
|
|
|
|
|
|
|
[ \t\n]+ /* eat up whitespace */
|
|
|
|
\#[^\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
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
struct yyguts_t * yyg = (struct yyguts_t*) scanner;
|
|
|
|
BEGIN(STRING);
|
|
|
|
}
|