I have been using my PonderTalk (Smalltalk like) language for a while now
and I have just noticed that leaving a block empty causes a parser error.
This is with ANTLRWorks 1.2.3. I have refined the grammar to show the point.
The problem line is ^(statements). With that taken out the parsing works.
grammar Trial;

options {
output = AST;
        k = 2;
}

start : sentences EOF
 ;
sentences
: sentence? (DOT sentences)?
 -> sentence? sentences?
;
sentence: WORD | block;
block : '[' sentences ']'
-> ^(sentences)
 ;

WORD : LETTER LETTER+;
LETTER : 'a'..'z';
DOT : '.';

The following input works as expected:
hello. [ block ]. goodbye

The following  just terminates the parser after processing the ']' with no
AST being produced at all:
hello. [ ] . goodbye

There are no errors. However with my PonderTalk parser I get

Exception thrown: rule sentences

org.antlr.runtime.tree.RewriteEmptyStreamException: rule sentences

at org.antlr.runtime.tree.RewriteRuleElementStream._next(
RewriteRuleElementStream.java:158)

at org.antlr.runtime.tree.RewriteRuleElementStream.nextTree(
RewriteRuleElementStream.java:145)

at net.ponder2.parser.PonderTalkParser.block(PonderTalkParser.java:1061)

at net.ponder2.parser.PonderTalkParser.object(PonderTalkParser.java:693)

at net.ponder2.parser.PonderTalkParser.objectMessage(
PonderTalkParser.java:470)

at net.ponder2.parser.PonderTalkParser.sentence(PonderTalkParser.java:323)

at net.ponder2.parser.PonderTalkParser.sentence(PonderTalkParser.java:341)

at net.ponder2.parser.PonderTalkParser.sentences(PonderTalkParser.java:194)

at net.ponder2.parser.PonderTalkParser.start(PonderTalkParser.java:129)

at net.ponder2.parser.P2Compiler.parse(P2Compiler.java:495)

at net.ponder2.parser.P2Compiler.parse(P2Compiler.java:440)

at net.ponder2.ShellInstance.doPonderTalk(ShellInstance.java:211)

at net.ponder2.ShellInstance.run(ShellInstance.java:163)

at java.lang.Thread.run(Thread.java:613)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to