mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-06 03:38:39 +00:00
Use our own lexer, not jison's
Summary: Build our own lexer and inject it into jison's parser, because jison's lexer notation is confusing and annoying, and it doesn't let us do some fun stuff. Test Plan: Run stuff, make sure it still works. Reviewers: spicyj Reviewed By: spicyj Differential Revision: http://phabricator.benalpert.com/D40
This commit is contained in:
32
parser.jison
32
parser.jison
@@ -4,22 +4,6 @@
|
||||
%lex
|
||||
%%
|
||||
|
||||
\s+ /* skip whitespace */
|
||||
cdot return 'CDOT'
|
||||
frac return 'FRAC'
|
||||
lvert return 'LVERT'
|
||||
rvert return 'RVERT'
|
||||
pm return 'PM'
|
||||
div return 'DIV'
|
||||
[/|a-zA-Z0-9] return 'ORD'
|
||||
[*+-] return 'BIN'
|
||||
\^ return '^'
|
||||
[_] return '_'
|
||||
[{] return '{'
|
||||
[}] return '}'
|
||||
[(] return 'OPEN'
|
||||
[)] return 'CLOSE'
|
||||
[\\] return '\\'
|
||||
<<EOF>> return 'EOF'
|
||||
|
||||
/lex
|
||||
@@ -37,7 +21,7 @@ div return 'DIV'
|
||||
%% /* language grammar */
|
||||
|
||||
expression
|
||||
: ex EOF
|
||||
: ex 'EOF'
|
||||
{return $1;}
|
||||
;
|
||||
|
||||
@@ -61,22 +45,22 @@ group
|
||||
{$$ = $1;}
|
||||
| '{' ex '}'
|
||||
{$$ = $2;}
|
||||
| '\\' func
|
||||
| '\' func
|
||||
{$$ = $2;}
|
||||
;
|
||||
|
||||
func
|
||||
: 'CDOT'
|
||||
: 'cdot'
|
||||
{$$ = [{type: 'bin', value: yytext}];}
|
||||
| 'PM'
|
||||
| 'pm'
|
||||
{$$ = [{type: 'bin', value: yytext}];}
|
||||
| 'DIV'
|
||||
| 'div'
|
||||
{$$ = [{type: 'bin', value: yytext}];}
|
||||
| 'FRAC' group group
|
||||
| 'frac' group group
|
||||
{$$ = [{type: 'frac', value: {numer: $2, denom: $3}}];}
|
||||
| 'LVERT'
|
||||
| 'lvert'
|
||||
{$$ = [{type: 'open', value: yytext}];}
|
||||
| 'RVERT'
|
||||
| 'rvert'
|
||||
{$$ = [{type: 'close', value: yytext}];}
|
||||
;
|
||||
|
||||
|
Reference in New Issue
Block a user