[antlr-interest] State of Ruby Support

Curt Sampson cjs at cynic.net
Tue Oct 16 02:44:45 PDT 2012


I've downloaded and installed ANTLR 3.4, intending to use it to generate
some parsers for use in Ruby programs (and perhaps, later, C++). However,
I'm having some difficulties getting things set up, and I'm wondering what
the current state of Ruby support is.

(Note that below I'm using the Ruby support library that is found under
runtime/Ruby/lib/ in the ANTLR 3.4 distribution.)

Given the following grammar in Graphics.g:

    grammar Graphics;

    options { language = Java; }

    file:       command+ ;
    command:    'line' 'from' point 'to' point ;
    point:      INT ',' INT ;

    INT:        '0'..'9'+ ;
    WS:         (' ' | '\t' | '\r' | '\n') { skip(); } ;

Compiling it with "antlr Graphics.g" seems to work fine, producing the
files Graphics.tokens, GraphicsLexer.java and GraphicsParser.java, and
nothing on standard output. However, changing the language above to Ruby
produces the messages appended below, though it still produces the token
file and the .rb versions of the above Java files. Loading them up and
playing about in irb, I seem to be able to get the lexer to work, but
not the parser.

So: is Ruby supported? Working to some degree? What's the canonical way
to use the generated parser?

Here are the messages from antlr when compiling Graphics.g:

----------------------------------------------------------------------
Ruby.stg 204:241: '.' came as a complete surprise to me
Ruby.stg 255:151: '.' came as a complete surprise to me
Ruby.stg 498:23: anonymous template has 0 arg(s) but mapped across 1 value(s)
Ruby.stg 504:24: anonymous template has 0 arg(s) but mapped across 1 value(s)
Ruby.stg 1131:81: required parameters (filterMode) must appear before optional parameters
context [/outputFile] 6:32 no such template: /runtimeLibraryVersion
context [/outputFile] 19:51 no such template: /runtimeLibraryVersion
context [/outputFile] 49:32 no such template: /runtimeLibraryVersion
context [/outputFile] 59:0 no such template: /placeAction
context [/outputFile] 59:1 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile] 59:1 attribute scope isn't defined
context [/outputFile] 59:1 attribute name isn't defined
context [/outputFile] 60:0 no such template: /placeAction
context [/outputFile] 60:1 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile] 60:1 attribute scope isn't defined
context [/outputFile] 60:1 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile] 2:2 no such template: /placeAction
context [/outputFile /rootGrammarOutputFile] 2:3 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile] 2:3 attribute scope isn't defined
context [/outputFile /rootGrammarOutputFile] 2:3 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 25:2 no such template: /placeAction
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 25:3 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 25:3 attribute scope isn't defined
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 25:3 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 26:2 no such template: /placeAction
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 26:3 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 26:3 attribute scope isn't defined
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 26:3 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /parser] 1:27 no such template: /autoloadDelegates
context [/outputFile /rootGrammarOutputFile /parser] 4:2 no such template: /parserBody
context [/outputFile /rootGrammarOutputFile /parser] 4:3 passed 3 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /parser] 4:3 attribute rewriteElementType isn't defined
context [/outputFile /rootGrammarOutputFile /parser] 4:3 attribute actionScope isn't defined
context [/outputFile /rootGrammarOutputFile /parser] 4:3 attribute inputStreamType isn't defined
context [/outputFile /rootGrammarOutputFile] 5:2 no such template: /placeAction
context [/outputFile /rootGrammarOutputFile] 5:3 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile] 5:3 attribute scope isn't defined
context [/outputFile /rootGrammarOutputFile] 5:3 attribute name isn't defined
context [/outputFile] 68:0 no such template: /placeAction
context [/outputFile] 68:1 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile] 68:1 attribute scope isn't defined
context [/outputFile] 68:1 attribute name isn't defined
context [/outputFile] 69:0 no such template: /placeAction
context [/outputFile] 69:1 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile] 69:1 attribute scope isn't defined
context [/outputFile] 69:1 attribute name isn't defined
Ruby.stg 204:241: '.' came as a complete surprise to me
Ruby.stg 255:151: '.' came as a complete surprise to me
Ruby.stg 498:23: anonymous template has 0 arg(s) but mapped across 1 value(s)
Ruby.stg 504:24: anonymous template has 0 arg(s) but mapped across 1 value(s)
Ruby.stg 1131:81: required parameters (filterMode) must appear before optional parameters
context [/outputFile] 6:32 no such template: /runtimeLibraryVersion
context [/outputFile] 19:51 no such template: /runtimeLibraryVersion
context [/outputFile] 49:32 no such template: /runtimeLibraryVersion
context [/outputFile] 59:0 no such template: /placeAction
context [/outputFile] 59:1 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile] 59:1 attribute scope isn't defined
context [/outputFile] 59:1 attribute name isn't defined
context [/outputFile] 60:0 no such template: /placeAction
context [/outputFile] 60:1 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile] 60:1 attribute scope isn't defined
context [/outputFile] 60:1 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile] 2:2 no such template: /placeAction
context [/outputFile /rootGrammarOutputFile] 2:3 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile] 2:3 attribute scope isn't defined
context [/outputFile /rootGrammarOutputFile] 2:3 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 25:2 no such template: /placeAction
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 25:3 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 25:3 attribute scope isn't defined
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 25:3 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 26:2 no such template: /placeAction
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 26:3 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 26:3 attribute scope isn't defined
context [/outputFile /rootGrammarOutputFile /tokenDataModule] 26:3 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /lexer] 1:27 no such template: /autoloadDelegates
context [/outputFile /rootGrammarOutputFile /lexer] 15:54 no such template: /runtimeLibraryVersion
context [/outputFile /rootGrammarOutputFile /lexer] 37:209 no such template: /placeAction
context [/outputFile /rootGrammarOutputFile /lexer] 37:210 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /lexer] 37:210 attribute scope isn't defined
context [/outputFile /rootGrammarOutputFile /lexer] 37:210 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /lexer] 40:2 no such template: /placeAction
context [/outputFile /rootGrammarOutputFile /lexer] 40:3 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /lexer] 40:3 attribute scope isn't defined
context [/outputFile /rootGrammarOutputFile /lexer] 40:3 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:51 no such template: /action
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 attribute code isn't defined
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:51 no such template: /action
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 attribute code isn't defined
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:51 no such template: /action
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 attribute code isn't defined
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:51 no such template: /action
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 attribute code isn't defined
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:51 no such template: /action
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 attribute code isn't defined
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:51 no such template: /action
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 attribute name isn't defined
context [/outputFile /rootGrammarOutputFile /lexer /_sub108 /lexerRule] 20:52 attribute code isn't defined
context [/outputFile /rootGrammarOutputFile] 5:2 no such template: /placeAction
context [/outputFile /rootGrammarOutputFile] 5:3 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile /rootGrammarOutputFile] 5:3 attribute scope isn't defined
context [/outputFile /rootGrammarOutputFile] 5:3 attribute name isn't defined
context [/outputFile] 68:0 no such template: /placeAction
context [/outputFile] 68:1 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile] 68:1 attribute scope isn't defined
context [/outputFile] 68:1 attribute name isn't defined
context [/outputFile] 69:0 no such template: /placeAction
context [/outputFile] 69:1 passed 2 arg(s) to template null with 0 declared arg(s)
context [/outputFile] 69:1 attribute scope isn't defined
context [/outputFile] 69:1 attribute name isn't defined
----------------------------------------------------------------------

cjs
-- 
Curt Sampson         <cjs at cynic.net>         +81 90 7737 2974

It is easier to write an incorrect program than understand a correct one.
    --Alan Perlis, Epigrams on Programming (#7)


More information about the antlr-interest mailing list