Skip to content

Commit

Permalink
Merge pull request antlr#1433 from studentmain/tjs-optimize
Browse files Browse the repository at this point in the history
Kirikiri-TJS parser optimization
  • Loading branch information
teverett authored Jun 5, 2019
2 parents 1f08713 + 4f5984d commit c457713
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 196 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
265 changes: 102 additions & 163 deletions kirikiri-tjs/TJSParser.g4

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion kirikiri-tjs/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Link: https://github.com/krkrz/kwidgets

### test_scripts

Official TJS2 test script
Official TJS2 test script, modified to work without preprocessor.

Link: https://github.com/krkrz/test_scripts

Expand Down
5 changes: 3 additions & 2 deletions kirikiri-tjs/example/kwidgets/manual.tjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// official compiler report error... modified
class Layer
{
/**
* このレイヤー上でのX座標が、スクリーン上ではいくつになるかを返す
* @param x レイヤー上でのX座標
* @return スクリーン上でのX座標
*/
function getScreenLeft(x)
function getScreenLeft(x){}

/**
* このレイヤー上でのY座標が、スクリーン上ではいくつになるかを返す
* @param y レイヤー上でのY座標
* @return スクリーン上でのY座標
*/
function getScreenTop(y)
function getScreenTop(y){}
}
48 changes: 24 additions & 24 deletions kirikiri-tjs/example/test_scripts/test_variant.tjs
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,19 @@ function testVariant() {
}
tmp = -1;
tmp >>>= 1;
@if(environment > 0) // java
/*@if(environment > 0) // java
if( tmp != 2147483647 ) {
Debug.message("faild:-1 >>>= 1");
Debug.message("int型ではこうなるが、longが内部型になるとこのテストは正しくない。値を変えるべき");
isFaild = true;
}
@endif
@if(environment == 0) // windows
@endif*/
//@if(environment == 0) // windows
if( tmp != 9223372036854775807 ) {
Debug.message("faild:-1 >>>= 1,"+tmp);
isFaild = true;
}
@endif
//@endif
tmp = 10;
if( int10 == 9 || tmp == 10 ) {
} else {
Expand All @@ -366,20 +366,20 @@ function testVariant() {
isFaild = true;
}
tmp = -1 >>> 1;
@if(environment > 0) // java
/*@if(environment > 0) // java
if( tmp != 2147483647 ) {
Debug.message("faild:-1 >>> 1");
Debug.message("int型ではこうなるが、longが内部型になるとこのテストは正しくない。値を変えるべき");
isFaild = true;
}
@endif
@if(environment == 0) // windows
@endif*/
//@if(environment == 0) // windows
if( tmp != 9223372036854775807 ) {
Debug.message("faild:-1 >>> 1,"+tmp);
Debug.message("int型ではこうなるが、longが内部型になるとこのテストは正しくない。値を変えるべき");
isFaild = true;
}
@endif
//@endif
tmp = int5 == 5 ? 1 : 0;
if( tmp != 1 ) {
Debug.message("faild:tmp = int5 == 5 ? 1 : 0;");
Expand Down Expand Up @@ -702,19 +702,19 @@ function testVariant() {
}
tmp = -1.0;
tmp >>>= 1;
@if(environment > 0) // java
/*@if(environment > 0) // java
if( tmp != 2147483647 ) {
Debug.message("faild:-1 >>>= 1");
Debug.message("int型ではこうなるが、longが内部型になるとこのテストは正しくない。値を変えるべき");
isFaild = true;
}
@endif
@if(environment == 0) // windows
@endif*/
//@if(environment == 0) // windows
if( tmp != 9223372036854775807 ) {
Debug.message("faild:-1 >>>= 1,"+tmp);
isFaild = true;
}
@endif
//@endif
tmp = 10.0;
if( real10 == 9.0 || tmp == 10.0 ) {
} else {
Expand All @@ -739,20 +739,20 @@ function testVariant() {
isFaild = true;
}
tmp = -1.0 >>> 1;
@if(environment > 0) // java
/*@if(environment > 0) // java
if( tmp != 2147483647 ) {
Debug.message("faild:-1 >>> 1");
Debug.message("int型ではこうなるが、longが内部型になるとこのテストは正しくない。値を変えるべき");
isFaild = true;
}
@endif
@if(environment == 0) // windows
@endif*/
//@if(environment == 0) // windows
if( tmp != 9223372036854775807 ) {
Debug.message("faild:-1 >>> 1,"+tmp);
Debug.message("int型ではこうなるが、longが内部型になるとこのテストは正しくない。値を変えるべき");
isFaild = true;
}
@endif
//@endif
tmp = real5 == 5.0 ? 1.0 : 0.0;
if( tmp != 1 ) {
Debug.message("faild:tmp = real5 == 5 ? 1 : 0;");
Expand Down Expand Up @@ -1037,19 +1037,19 @@ function testVariant() {
}
tmp = "-1";
tmp >>>= 1;
@if(environment > 0) // java
/*@if(environment > 0) // java
if( tmp != 2147483647 ) {
Debug.message("faild:-1 >>>= 1");
Debug.message("int型ではこうなるが、longが内部型になるとこのテストは正しくない。値を変えるべき");
isFaild = true;
}
@endif
@if(environment == 0) // windows
@endif*/
//@if(environment == 0) // windows
if( tmp != 9223372036854775807 ) {
Debug.message("faild:-1 >>>= 1,"+tmp);
isFaild = true;
}
@endif
//@endif
tmp = "10";
if( str10 == 9 || tmp == 10 ) {
} else {
Expand All @@ -1074,20 +1074,20 @@ function testVariant() {
isFaild = true;
}
tmp = "-1" >>> 1;
@if(environment > 0) // java
/*@if(environment > 0) // java
if( tmp != 2147483647 ) {
Debug.message("faild:-1 >>> 1");
Debug.message("int型ではこうなるが、longが内部型になるとこのテストは正しくない。値を変えるべき");
isFaild = true;
}
@endif
@if(environment == 0) // windows
@endif*/
//@if(environment == 0) // windows
if( tmp != 9223372036854775807 ) {
Debug.message("faild:-1 >>> 1,"+tmp);
Debug.message("int型ではこうなるが、longが内部型になるとこのテストは正しくない。値を変えるべき");
isFaild = true;
}
@endif
//@endif
tmp = str5 == "5" ? 1 : 0;
if( tmp != 1 ) {
Debug.message("faild:tmp = str5 == 5 ? 1 : 0;");
Expand Down
2 changes: 1 addition & 1 deletion kirikiri-tjs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<entryPoint>program</entryPoint>
<grammarName>TJS</grammarName>
<packageName></packageName>
<exampleFiles>example/kag3_ham</exampleFiles>
<exampleFiles>example/test_scripts</exampleFiles>
</configuration>
<executions>
<execution>
Expand Down
2 changes: 1 addition & 1 deletion kirikiri-tjs/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ERR=lasterror.txt
DEFAULTTEST=example/**/*.tjs
TEST=${@:-$DEFAULTTEST}
FAIL=0
for i in $TEST
time for i in $TEST
do
echo Test $i
cat $i | node preprocess.js | grun TJS program 2> $ERR
Expand Down

0 comments on commit c457713

Please sign in to comment.