mirror of https://github.com/vitalif/lime
Made lime_scan_tokens.l somewhat more elegant to read
parent
6163fdac49
commit
f669d69163
|
@ -14,9 +14,9 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
%{
|
%{
|
||||||
void out(char*t, char*v);
|
void out(char* t, char* v);
|
||||||
void lit();
|
void lit();
|
||||||
void tok(char*t);
|
void tok(char* t);
|
||||||
void php();
|
void php();
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
@ -28,55 +28,53 @@ void php();
|
||||||
%x dquote
|
%x dquote
|
||||||
%x squote
|
%x squote
|
||||||
|
|
||||||
CHAR \n|.
|
CHAR \n|.
|
||||||
|
|
||||||
ALPHA [a-zA-Z]
|
ALPHA [a-zA-Z]
|
||||||
DIGIT [0-9]
|
DIGIT [0-9]
|
||||||
ALNUM {ALPHA}|{DIGIT}
|
ALNUM {ALPHA}|{DIGIT}
|
||||||
WORD {ALNUM}|_
|
WORD {ALNUM}|_
|
||||||
STOP "."|";"
|
STOP "."|";"
|
||||||
|
|
||||||
SYM {ALPHA}{WORD}*'*
|
SYM {ALPHA}{WORD}*'*
|
||||||
LIT '.'
|
LIT '.'
|
||||||
|
|
||||||
ESC "\"{CHAR}
|
ESC "\"{CHAR}
|
||||||
SCHAR [^\']|ESC
|
SCHAR [^\']|ESC
|
||||||
DCHAR [^\"]|ESC
|
DCHAR [^\"]|ESC
|
||||||
COM "//"|"#"
|
COM "//"|"#"
|
||||||
|
|
||||||
CC [^*\n]
|
CC [^*\n]
|
||||||
CX "*"+{CC}+
|
CX "*"+{CC}+
|
||||||
CT "*"+"/"
|
CT "*"+"/"
|
||||||
BLOCKCMT "/*"({CC}|{CX})*{CT}
|
BLOCKCMT "/*"({CC}|{CX})*{CT}
|
||||||
|
|
||||||
%x pragma
|
%x pragma
|
||||||
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
[[:space:]]+ {}
|
[[:space:]]+ {}
|
||||||
#.* {}
|
#.* {}
|
||||||
|
|
||||||
{STOP} out("stop", ".");
|
{STOP} out("stop", ".");
|
||||||
{SYM} tok("sym");
|
{SYM} tok("sym");
|
||||||
{LIT} tok("lit");
|
{LIT} tok("lit");
|
||||||
{BLOCKCMT} {}
|
{BLOCKCMT} {}
|
||||||
"/"{WORD}+ |
|
"/"{WORD}+ |
|
||||||
"/$" out("lambda", yytext+1);
|
"/$" out("lambda", yytext+1);
|
||||||
"%prec" {
|
"%prec" tok("prec");
|
||||||
tok("prec");
|
"%"{WORD}+ {
|
||||||
}
|
|
||||||
"%"{WORD}+ {
|
|
||||||
out("pragma", yytext+1);
|
out("pragma", yytext+1);
|
||||||
yy_push_state(pragma);
|
yy_push_state(pragma);
|
||||||
}
|
}
|
||||||
|
|
||||||
<*>"{" {
|
<*>"{" {
|
||||||
lit();
|
lit();
|
||||||
yy_push_state(code);
|
yy_push_state(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
. lit();
|
. lit();
|
||||||
|
|
||||||
|
|
||||||
<pragma>{
|
<pragma>{
|
||||||
|
@ -95,16 +93,16 @@ BLOCKCMT "/*"({CC}|{CX})*{CT}
|
||||||
}
|
}
|
||||||
|
|
||||||
<code>{
|
<code>{
|
||||||
"}" {
|
"}" {
|
||||||
lit();
|
lit();
|
||||||
yy_pop_state();
|
yy_pop_state();
|
||||||
}
|
}
|
||||||
'{SCHAR}*' php();
|
'{SCHAR}*' php();
|
||||||
\"{DCHAR}*\" php();
|
\"{DCHAR}*\" php();
|
||||||
{COM}.* php();
|
{COM}.* php();
|
||||||
{BLOCKCMT} php();
|
{BLOCKCMT} php();
|
||||||
[^{}'"#/]+ php();
|
[^{}'"#/]+ php();
|
||||||
. php();
|
. php();
|
||||||
}
|
}
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
@ -115,7 +113,7 @@ void lit() {
|
||||||
out(lit, yytext);
|
out(lit, yytext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tok(char*t) {
|
void tok(char* t) {
|
||||||
out(t, yytext);
|
out(t, yytext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +121,7 @@ void php() {
|
||||||
out("php", yytext);
|
out("php", yytext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void out(char*type, char*value) {
|
void out(char* type, char* value) {
|
||||||
printf("%d\001%s\001%s", yylineno, type, value);
|
printf("%d\001%s\001%s", yylineno, type, value);
|
||||||
fputc(0, stdout);
|
fputc(0, stdout);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue