Skip to content

Commit

Permalink
Add OctetLiteral support;
Browse files Browse the repository at this point in the history
  • Loading branch information
Student Main committed Jun 5, 2019
1 parent 201ecef commit 4f5984d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
1 change: 0 additions & 1 deletion kirikiri-tjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Tested on [KAG3](https://github.com/krkrz/kag3), [KAG3-HAM](https://github.com/k
Only Java Runtime have tested. All other runtime is directly copy-paste-rename without test.

Known issue:
- OctetLiteral (e.g: `<% 00 a2 f3 45%>`) is a parser rule, not a single token.
- Now consider `¥`(`\u00a5`,japanese yen) as UnexpectedCharacter insteadof Backslash(`\`,`\u005c`).
- TJS2 bytecode also use *.tjs extension, this script can't parse them.
- Need an preprocessor (`preprocessor.js`) to handle preprocess command.
4 changes: 1 addition & 3 deletions kirikiri-tjs/TJSLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ options { superClass=TJSBaseLexer; }
MultiLineComment: '/*' .*? '*/' -> channel(HIDDEN);
SingleLineComment: '//' ~[\r\n\u2028\u2029]* -> channel(HIDDEN);
RegularExpressionLiteral: {this.IsRegexPossible()}? '/' RegularExpressionFirstChar RegularExpressionChar* '/' IdentifierPart*;

StartOctet: '<%';
EndOctet: '%>';
OctetLiteral: '<%' .*? '%>';

OpenBracket: '[';
CloseBracket: ']';
Expand Down
20 changes: 5 additions & 15 deletions kirikiri-tjs/TJSParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ ifStatement
;

iterationStatement
: Do statement While '(' expressions ')' eos # DoStatement
| While '(' expressions ')' statement # WhileStatement
| For '(' expressions? ';' expressions? ';' expressions? ')' statement # ForStatement
| For '(' varModifier variables ';' expressions? ';' expressions? ')' statement # ForVarStatement
: Do statement While '(' expressions ')' eos # DoStatement
| While '(' expressions ')' statement # WhileStatement
| For '(' expressions? ';' expressions? ';' expressions? ')' statement # ForStatement
| For '(' varModifier variables ';' expressions? ';' expressions? ')' statement # ForVarStatement
;

varModifier
Expand Down Expand Up @@ -179,7 +179,6 @@ expressions
: expression (',' expression)*
;


// TODO: can we optimize it?
expression
: anoymousFunctionDeclaration # FunctionExpression
Expand Down Expand Up @@ -253,21 +252,12 @@ literal
: NullLiteral
| BooleanLiteral
| (StringLiteral | TemplateStringLiteral)+
| octetLiteral
| OctetLiteral
| RegularExpressionLiteral
| numericLiteral
| Void
;

octetLiteral
: '<%' // Hack for octet literal
( NonIdentHexByte // 0f 7a 08.....
| OctalIntegerLiteral // 00 07 .....
| DecimalLiteral // 13 75 .....
| Identifier)* // ef b9 .....
'%>' // Remember handle it in type recognization
;

numericLiteral
: DecimalLiteral
| HexIntegerLiteral
Expand Down

0 comments on commit 4f5984d

Please sign in to comment.