From 282aa9fd2f98759c827f82147f73fc5d9b2fa5ab Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Sat, 13 Oct 2018 07:32:06 -0400 Subject: [PATCH] Update the JavaScript codegen target --- runtime/JavaScript/build/README | 7 +- runtime/JavaScript/build/antlr3.properties | 2 +- .../tests/functional/t009lexer.html | 4 +- .../tests/functional/t044trace.html | 8 +- .../codegen/templates/JavaScript/AST.stg | 101 ++--- .../templates/JavaScript/ASTParser.stg | 76 ++-- .../templates/JavaScript/ASTTreeParser.stg | 103 +++-- .../templates/JavaScript/JavaScript.stg | 382 ++++++++++++------ 8 files changed, 430 insertions(+), 253 deletions(-) diff --git a/runtime/JavaScript/build/README b/runtime/JavaScript/build/README index 4095054db..c7b30bde2 100755 --- a/runtime/JavaScript/build/README +++ b/runtime/JavaScript/build/README @@ -19,9 +19,8 @@ party open source libraries: * Unzip the downloaded file. * Move the unzipped folder to runtime/JavaScript/third/jsdoc-toolkit - * jsunit: Download here: https://sourceforge.net/project/showfiles.php?group_id=28041&package_id=19823&release_id=404277 - * Unzip the downloaded file. - * Move the unzipped folder to runtime/JavaScript/tests/jsunit + * jsunit: + * cd runtime/JavaScript/tests && git clone https://github.com/pivotal-legacy/jsunit.git ### BUILD ### 1) In a shell cd to runtime/JavaScript/build. @@ -32,7 +31,7 @@ party open source libraries: Compile Tests: 1) Build the Antlr tool itself (see main Antlr documentation for details). This is most easily done by cd'ing to the root of the antlr code and running - 'mvn -Dmaven.test.skip=true package assembly:assembly'. If using a + 'mvn -Dmaven.test.skip=true package'. If using a different build method, update runtime/JavaScript/build/antlr3.properties to point to the alternative jar. 2) In a shell cd to runtime/JavaScript/build. diff --git a/runtime/JavaScript/build/antlr3.properties b/runtime/JavaScript/build/antlr3.properties index 81014e70d..2e1b6fc84 100755 --- a/runtime/JavaScript/build/antlr3.properties +++ b/runtime/JavaScript/build/antlr3.properties @@ -55,4 +55,4 @@ antlr3.cli.list=\ org/antlr/runtime/ANTLRFileStream.js # path to antlr tool jar -antlr3.tool=../../target/antlr-master-3.2.1-SNAPSHOT-completejar.jar +antlr3.tool=../../antlr-complete/target/antlr-complete-3.5.3-SNAPSHOT.jar diff --git a/runtime/JavaScript/tests/functional/t009lexer.html b/runtime/JavaScript/tests/functional/t009lexer.html index 68f6289bd..2a8353302 100755 --- a/runtime/JavaScript/tests/functional/t009lexer.html +++ b/runtime/JavaScript/tests/functional/t009lexer.html @@ -60,8 +60,8 @@ token = lexer.nextToken(); fail("nextToken should have thrown error on invalid input"); } catch (e) { - assertEquals(e.a, '0'); - assertEquals(e.b, '9'); + /* TODO: This shoud provide more useful information */ + assertEquals(e.expecting, null); assertEquals(e.getUnexpectedType(), 'a'); assertEquals(e.charPositionInLine, 1); assertEquals(e.line, 1); diff --git a/runtime/JavaScript/tests/functional/t044trace.html b/runtime/JavaScript/tests/functional/t044trace.html index e0b99cf5b..fb4466d0c 100755 --- a/runtime/JavaScript/tests/functional/t044trace.html +++ b/runtime/JavaScript/tests/functional/t044trace.html @@ -57,10 +57,10 @@ parser.a(); assertArrayEquals(lexer.traces, - [ '>T__6', 'WS', 'INT', 'WS', 'T__8', 'WS', 'INT', 'WS', 'T__8', 'WS', 'INT', 'WS', 'T__7', 'T__7', 'WS', 'INT', 'WS', 'T__6', 'WS', 'INT', 'WS', 'T__6', 'WS', 'INT', 'WS', 'T__8', 'a', '>synpred1_t044trace_fragment', 'b', '>c', diff --git a/tool/src/main/resources/org/antlr/codegen/templates/JavaScript/AST.stg b/tool/src/main/resources/org/antlr/codegen/templates/JavaScript/AST.stg index 678038764..46b4f3315 100755 --- a/tool/src/main/resources/org/antlr/codegen/templates/JavaScript/AST.stg +++ b/tool/src/main/resources/org/antlr/codegen/templates/JavaScript/AST.stg @@ -25,7 +25,16 @@ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -group AST; + +finishedBacktracking(block) ::= << + +if( ) { + +} + + + +>> @outputFile.imports() ::= << <@super.imports()> @@ -33,15 +42,15 @@ group AST; @genericParser.members() ::= << <@super.members()> - + >> /** Add an adaptor property that knows how to build trees */ -parserMembers() ::= << +astAccessor() ::= << !> setTreeAdaptor: function(adaptor) { this.adaptor = adaptor; - .setTreeAdaptor(this.adaptor);}> + .setTreeAdaptor(this.adaptor);}; separator="\n"> }, getTreeAdaptor: function() { return this.adaptor; @@ -60,12 +69,14 @@ var root_0 = null;<\n> ruleLabelDefs() ::= << -_tree=null;}; separator="\n"> -_tree=null;}; separator="\n"> +<[ruleDescriptor.tokenLabels,ruleDescriptor.wildcardTreeLabels, + ruleDescriptor.wildcardTreeListLabels] + :{it | var _tree=null;}; separator="\n"> +_tree=null;}; separator="\n"> =new org.antlr.runtime.tree.RewriteRuleTokenStream(this.adaptor,"token ");}; separator="\n"> + :{it | var stream_=new org.antlr.runtime.tree.RewriteRuleTokenStream(this.adaptor,"token ");}; separator="\n"> =new org.antlr.runtime.tree.RewriteRuleSubtreeStream(this.adaptor,"rule ");}; separator="\n"> + :{it | var stream_=new org.antlr.runtime.tree.RewriteRuleSubtreeStream(this.adaptor,"rule ");}; separator="\n"> >> /** When doing auto AST construction, we must define some variables; @@ -86,57 +97,53 @@ root_0 = this.adaptor.nil();<\n> // T r a c k i n g R u l e E l e m e n t s /** ID and track it for use in a rewrite rule */ -tokenRefTrack(token,label,elementIndex,terminalOptions) ::= << +tokenRefTrack(token,label,elementIndex,terminalOptions={}) ::= << -if ( ) stream_.add(