-
Notifications
You must be signed in to change notification settings - Fork 1
/
amyplanyy.l
218 lines (201 loc) · 5.2 KB
/
amyplanyy.l
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
%option nounput noinput
%option prefix="amyplanyy"
%{
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "amyplanyyutils.h"
#include "amyplanyy.tab.h"
/*
#define YYSTYPE AMYPLANYYSTYPE
#define YYLTYPE AMYPLANYYLTYPE
*/
/*
#define YY_USER_ACTION yylloc->first_line = yylloc->last_line = yylineno; \
yylloc->first_column = yycolumn; yylloc->last_column = yycolumn+yyleng-1; \
yycolumn += yyleng;
*/
#define YY_USER_ACTION yycolumn += yyleng;
// @listexpand return LISTEXPAND;
%}
%option reentrant bison-bridge
%x PERCENTLUA
%%
%{
struct amyplan_csnippet luaSnippet = {
.data = NULL,
.len = 0,
.capacity = 0,
};
%}
@tostring return TOSTRING;
@tonumber return TONUMBER;
@stdout return STDOUT; /* FIXME make these true streams */
@stderr return STDERR;
@error return ERROR;
@dump return DUMP;
@exit return EXIT;
@abs return ABS;
@acos return ACOS;
@asin return ASIN;
@atan return ATAN;
@ceil return CEIL;
@floor return FLOOR;
@trunc return TRUNC;
@round return ROUND;
@cos return COS;
@sin return SIN;
@tan return TAN;
@exp return EXP;
@log return LOG;
@sqrt return SQRT;
@getenv return GETENV;
@dupnonrec return DUP_NONRECURSIVE;
@pbnew return PB_NEW;
@scopeparent return SCOPE_PARENT;
@scopenew return SCOPE_NEW;
@scope return SCOPE;
@getscopedyn return GETSCOPE_DYN;
@getscopelex return GETSCOPE_LEX;
@beginscope return BEGINSCOPE;
@beginholeyscope return BEGINHOLEYSCOPE;
@endscope return ENDSCOPE;
@for return FOR;
@fordict return FORDICT;
@fordictprev return FORDICTPREV;
@endfor return ENDFOR;
@ return AT;
@type return TYPE;
@[?] return ATQM;
@true return TRUE;
@nil return NIL;
@false return FALSE;
@print return PRINT;
@function return FUNCTION;
@endfunction return ENDFUNCTION;
@locvar return LOCVAR;
@D return D;
@L return L;
@I return I;
@DO return DO;
@LO return LO;
@IO return IO;
@DP return DP;
@LP return LP;
@IP return IP;
@DPO return DPO;
@LPO return LPO;
@IPO return IPO;
@SC return SC;
@SCO return SCO;
@dyn return DYN;
@lex return LEX;
@imm return IMM;
@dyno return DYNO;
@lexo return LEXO;
@immo return IMMO;
@loc return LOC;
@if return IF;
@else return ELSE;
@elseif return ELSEIF;
@endif return ENDIF;
@while return WHILE;
@endwhile return ENDWHILE;
@once return ONCE;
@endonce return ENDONCE;
@break return BREAK;
@continue return CONTINUE;
@return return RETURN;
@append return APPEND;
@dictnext return DICTNEXT;
@dictprev return DICTPREV;
@strstr return STRSTR;
@strrep return STRREP;
@strlistjoin return STRLISTJOIN;
@strappend return STRAPPEND;
@strstrip return STRSTRIP;
@strsub return STRSUB;
@strgsub return STRGSUB;
@strset return STRSET;
@strword return STRWORD;
@strwordcnt return STRWORDCNT;
@strwordlist return STRWORDLIST;
@strcmp return STRCMP;
@strreverse return STR_REVERSE;
@strupper return STR_UPPER;
@strlower return STR_LOWER;
@strfromchr return STR_FROMCHR;
@appendlist return APPEND_LIST;
@dynluacall return DYNLUACALL;
@lexluacall return LEXLUACALL;
[+]= return PLUSEQUALS;
[?]= return QMEQUALS;
: return COLON;
, return COMMA;
= return EQUALS;
&& return LOGICAL_AND;
\|\| return LOGICAL_OR;
!= return NE;
== return EQ;
\<\< return SHL;
\>\> return SHR;
\< return LT;
\> return GT;
[(] return OPEN_PAREN;
[)] return CLOSE_PAREN;
[[] return OPEN_BRACKET;
[]] return CLOSE_BRACKET;
[{] return OPEN_BRACE;
[}] return CLOSE_BRACE;
\/ return DIV;
\* return MUL;
\+ return ADD;
- return SUB;
& return BITWISE_AND;
\| return BITWISE_OR;
~ return BITWISE_NOT;
\^ return BITWISE_XOR;
! return LOGICAL_NOT;
% return MOD;
\>= return GE;
\<= return LE;
\<\> return MAYBE_CALL;
[.] return PERIOD;
[$][A-Za-z0-9_]+ {
yylval->s = strdup(yytext+1);
return VARREF_LITERAL;
}
[$][(][A-Za-z0-9_]+[)] {
yylval->s = strdup(yytext+2);
yylval->s[strlen(yylval->s)-1] = '\0';
return VARREF_LITERAL;
}
[$][{][A-Za-z0-9_]+[}] {
yylval->s = strdup(yytext+2);
yylval->s[strlen(yylval->s)-1] = '\0';
return VARREF_LITERAL;
}
[-+]?[0-9]+([.][0-9]+)?([eE][-+]?[0-9]+)? {
yylval->d = atof(yytext);
return NUMBER;
}
\"([^\\\"]|\\.)*\" yylval->str=amyplanyy_escape_string(yytext, '"'); return STRING_LITERAL;
\'([^\\\']|\\.)*\' yylval->str=amyplanyy_escape_string(yytext, '\''); return STRING_LITERAL;
#[^\n]* /* ignore */;
"%lua{" { BEGIN(PERCENTLUA); luaSnippet.capacity = 0; luaSnippet.len = 0; luaSnippet.data = NULL; }
<PERCENTLUA>%\} {
BEGIN(INITIAL);
yylval->s = luaSnippet.data;
luaSnippet.data = NULL;
luaSnippet.capacity = 0;
luaSnippet.len = 0;
return PERCENTLUA_LITERAL;
}
<PERCENTLUA>. { amyplan_csadd(&luaSnippet, yytext[0]); }
<PERCENTLUA>"\n" { amyplan_csadd(&luaSnippet, yytext[0]); ++yylineno; yycolumn=1; }
\n { ++yylineno; yycolumn=1; return NEWLINE; }
\\\n { ++yylineno; yycolumn=1; }
[ \t] /* ignore whitespaces */;
. return ERROR_TOK;
%%