about summary refs log tree commit diff
path: root/src/libexpr/lexer.l
blob: 705b31b41a771eab237e987a9de20eeea227beb1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
%option reentrant bison-bridge bison-locations
%option noyywrap
%option never-interactive


%{
#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;
       }
    }
}

#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]+
STR         \"[^\n\"]*\"
PATH        [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+
URI         [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']*


%%


if          { return IF; }
then        { return THEN; }
else        { return ELSE; }
assert      { return ASSERT; }
let         { return LET; }
rec         { return REC; }

\=\=        { return EQ; }
\!\=        { return NEQ; }
\&\&        { return AND; }
\|\|        { return OR; }
\-\>        { return IMPL; }

{ID}        { yylval->t = ATmake("<str>", yytext); return ID; /* !!! alloc */ }
{INT}       { return INT; }
{STR}       { int len = strlen(yytext);
              yytext[len - 1] = 0;
              yylval->t = ATmake("<str>", yytext + 1);
              yytext[len - 1] = '\"';
              return STR; /* !!! alloc */
            }
{PATH}      { yylval->t = ATmake("<str>", yytext); return PATH; /* !!! alloc */ }
{URI}       { yylval->t = ATmake("<str>", yytext); return URI; /* !!! alloc */ }

[ \t\n]+    /* eat up whitespace */
\#[^\n]*    /* single-line comments */
\/\*(.|\n)*\*\/  /* long comments */

.           return yytext[0];


%%