Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
77 lines (67 sloc) 2.29 KB
EXCLAMATION "!"
VBAR "|"
DOLLAR "$"
COLON ":"
SEMICOLON ";"
LT "<"
GT ">"
COMMA ","
LEX_BEGIN "#lex_begin"
LEX_END "#lex_end"
LEX_DEFAULT "#lex_default"
START "#start"
EXTEND "#extend"
BEGIN "#begin"
END "#end"
DEFAULT "#default"
LABEL /[a-zA-Z_][a-zA-Z0-9_]*/
REGEXP /\/.*\/[gimuy]*/
STRING /".*"/
STRING /'.*'/
START_BLOCK /%*{+/ %%{
const match = /(%*)({+)/.exec(value)!;
const end_delimiter = "}".repeat(match[2].length) + match[1]!;
lex.callState("callback");
lex.addRule("body_block", {token: "BODY_BLOCK", pattern: new RegExp(`(?:.|\\s)*?(?<!})(?=${end_delimiter})(?!${end_delimiter}%+)(?!${end_delimiter}}+)`), state: ["callback"]});
lex.addRule("end_block", {
token: "END_BLOCK", pattern: end_delimiter, state: ["callback"],
callback: (value, token, lex) => {
lex.returnState();
lex.removeRule("body_block");
lex.removeRule("end_block");
}
});
}%%
!ENDLINE /(\r\n|\r|\n)+/
!WHITESPACE /[ \f\t\v\u00a0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]+/
INVALID /./
$LANGUAGE : LEX_OPTIONS LEX EX_CALLBACKS GRAMMAR | LEX_OPTIONS LEX GRAMMAR;
LEX_OPTIONS : OPTIONAL_LEX_EX_CALLBACKS LEX_STATES;
LEX_STATES : LEX_STATES LEXSTATE_DEFINITIONS | ;
LEXSTATE_DEFINITIONS : STARTSTATE | STATE_EXTEND;
STARTSTATE : START LEXSTATE;
STATE_EXTEND : EXTEND MULTIPLE_LEXSTATE LEXSTATE;
OPTIONAL_LEX_EX_CALLBACKS : LEX_EX_CALLBACKS | ;
LEX_EX_CALLBACKS : LEX_EX_CALLBACKS LEX_EX_CALLBACK | LEX_EX_CALLBACK;
LEX_EX_CALLBACK : LEX_EX_CALLBACK_LABEL BLOCK;
LEX_EX_CALLBACK_LABEL : LEX_BEGIN | LEX_END | LEX_DEFAULT;
LEX : LEX LEXSECT | LEXSECT;
LEXSECT : MULTIPLE_LEXSTATE LEXLABEL LEXDEF LEXCALLBACK | LEXLABEL LEXDEF LEXCALLBACK;
LEXLABEL : LABEL | EXCLAMATION | EXCLAMATION LABEL;
LEXDEF : STRING | REGEXP;
MULTIPLE_LEXSTATE : LT LEXSTATE_LIST GT;
LEXSTATE_LIST : LABEL COMMA LEXSTATE_LIST | LABEL;
LEXSTATE : LT LABEL GT;
LEXCALLBACK : BLOCK | ;
EX_CALLBACKS : EX_CALLBACKS EX_CALLBACK | EX_CALLBACK;
EX_CALLBACK : EX_CALLBACK_LABEL BLOCK;
EX_CALLBACK_LABEL : BEGIN | END | DEFAULT;
GRAMMAR : RULES;
RULES : SECT RULES | SECT;
SECT : SECTLABEL COLON DEF SEMICOLON;
SECTLABEL : LABEL | DOLLAR LABEL;
DEF : PATTERN CALLBACK VBAR DEF | PATTERN CALLBACK;
PATTERN : SYMBOLLIST | ;
SYMBOLLIST : LABEL SYMBOLLIST | LABEL;
CALLBACK : BLOCK | ;
BLOCK : START_BLOCK BODY_BLOCK END_BLOCK;