mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Add Jison (#3488)
This commit is contained in:
committed by
Brandon Black
parent
9ca6a5841e
commit
733ef63193
39
samples/Jison Lex/classy.jisonlex
Normal file
39
samples/Jison Lex/classy.jisonlex
Normal file
@@ -0,0 +1,39 @@
|
||||
digit [0-9]
|
||||
id [a-zA-Z][a-zA-Z0-9]*
|
||||
|
||||
%%
|
||||
"//".* /* ignore comment */
|
||||
"main" return 'MAIN';
|
||||
"class" return 'CLASS';
|
||||
"extends" return 'EXTENDS';
|
||||
"nat" return 'NATTYPE';
|
||||
"if" return 'IF';
|
||||
"else" return 'ELSE';
|
||||
"for" return 'FOR';
|
||||
"printNat" return 'PRINTNAT';
|
||||
"readNat" return 'READNAT';
|
||||
"this" return 'THIS';
|
||||
"new" return 'NEW';
|
||||
"var" return 'VAR';
|
||||
"null" return 'NUL';
|
||||
{digit}+ return 'NATLITERAL';
|
||||
{id} return 'ID';
|
||||
"==" return 'EQUALITY';
|
||||
"=" return 'ASSIGN';
|
||||
"+" return 'PLUS';
|
||||
"-" return 'MINUS';
|
||||
"*" return 'TIMES';
|
||||
">" return 'GREATER';
|
||||
"||" return 'OR';
|
||||
"!" return 'NOT';
|
||||
"." return 'DOT';
|
||||
"{" return 'LBRACE';
|
||||
"}" return 'RBRACE';
|
||||
"(" return 'LPAREN';
|
||||
")" return 'RPAREN';
|
||||
";" return 'SEMICOLON';
|
||||
\s+ /* skip whitespace */
|
||||
"." throw 'Illegal character';
|
||||
<<EOF>> return 'ENDOFFILE';
|
||||
|
||||
|
||||
29
samples/Jison Lex/lex_grammar.jisonlex
Normal file
29
samples/Jison Lex/lex_grammar.jisonlex
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
%%
|
||||
\n+ {yy.freshLine = true;}
|
||||
\s+ {yy.freshLine = false;}
|
||||
"y{"[^}]*"}" {yytext = yytext.substr(2, yyleng - 3); return 'ACTION';}
|
||||
[a-zA-Z_][a-zA-Z0-9_-]* {return 'NAME';}
|
||||
'"'([^"]|'\"')*'"' {return 'STRING_LIT';}
|
||||
"'"([^']|"\'")*"'" {return 'STRING_LIT';}
|
||||
"|" {return '|';}
|
||||
"["("\]"|[^\]])*"]" {return 'ANY_GROUP_REGEX';}
|
||||
"(" {return '(';}
|
||||
")" {return ')';}
|
||||
"+" {return '+';}
|
||||
"*" {return '*';}
|
||||
"?" {return '?';}
|
||||
"^" {return '^';}
|
||||
"/" {return '/';}
|
||||
"\\"[a-zA-Z0] {return 'ESCAPE_CHAR';}
|
||||
"$" {return '$';}
|
||||
"<<EOF>>" {return '$';}
|
||||
"." {return '.';}
|
||||
"%%" {return '%%';}
|
||||
"{"\d+(","\s?\d+|",")?"}" {return 'RANGE_REGEX';}
|
||||
/"{" %{if (yy.freshLine) { this.input('{'); return '{'; } else { this.unput('y'); }%}
|
||||
"}" %{return '}';%}
|
||||
"%{"(.|\n)*?"}%" {yytext = yytext.substr(2, yyleng - 4); return 'ACTION';}
|
||||
. {/* ignore bad characters */}
|
||||
<<EOF>> {return 'EOF';}
|
||||
|
||||
Reference in New Issue
Block a user