[antlr-interest] Bug or Error

Mikesell, Darin B. Darin.Mikesell at gd-ais.com
Wed Jun 30 14:30:50 PDT 2010


I have an interesting error/bug that just started coming up.

First here's a description of the bug.  If I enter a Line Comment, then the next keyword that is encountered (however many lines below that comment) will seem to have its first letter incorrectly 'read'. If I enter a 2nd or 3rd line of comments after that 1st comment, then the 2nd and 3rd letter of that same keyword will not be 'read'.  When I say 'read', I mean to say that the word will have its 1st-3rd letter grayed out, almost like it was considered still part of the comment(s) from the line above.

The weird part is that everything seems to run fine (i.e. the parse tree builds correctly), other than the Exception below being thrown if enough comments are read as to gray out the entire keyword.  Here's the other kicker, I only get the Exception being thrown if I debug from an input file... if I copy/paste the data from the file into the Text window and debug, the Exception never gets thrown.

The interesting part is that I never received this Exception being thrown before, it just started coming up. I've been testing this grammar for about a week and then just yesterday this Exception starting popping up.  The only thing that I can recall doing that may have caused it was that I clicked on the Refactor, Remove All Left Recursion.

I wish I was using versioning software, so I can just revert, but I don't think that would help anyway because the Exception is still being thrown even when I run the example grammars (the comments in the example grammars are having the same effect).

I'm using ANTLRWorks 1.4  I've tried deleting and reinstalling (including deleting the registry keys) to no avail.
I've tried using Java 1.5 and Java 1.6 and it doesn't matter, the Exception still gets thrown.

Here is a subset of my language, I've broken it down to its smallest possible pieces for the debugging purposes I was performing, and have determined (as stated above) that the Exceptions seem to be caused by the comments section.


grammar myLang;

my_program
        : 'begin'
           statement+
          'end'
        ;

// S t a t e m e n t s
statement
        : print_statement
        ;

print_statement
        : 'print' STRING_LITERAL
        ;

STRING_LITERAL
        :  '"' ( ~('\\'|'"') )* '"'
        ;

WS
        :  (' '|'\t'|'\u000C'|'\r'|'\n') {$channel=HIDDEN;}
        ;

LINE_COMMENT
        : (';' | '!') ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
        ;


Here is the input program that I'm using:
begin
   ; Comment Line 1
   ; Comment Line 2
   ; Comment Line 3
   ; Comment Line 4
   ; Comment Line 5
   ; Comment Line 6
   print "This is a test print statement"
end



Here is the exception that is being thrown:
[14:19:10] javax.swing.text.BadLocationException: Position not represented by view
        at javax.swing.text.CompositeView.modelToView(Unknown Source)
        at javax.swing.text.BoxView.modelToView(Unknown Source)
        at javax.swing.plaf.basic.BasicTextUI$RootView.modelToView(Unknown Source)
        at javax.swing.plaf.basic.BasicTextUI.modelToView(Unknown Source)
        at javax.swing.plaf.basic.BasicTextUI.modelToView(Unknown Source)
        at javax.swing.text.JTextComponent.modelToView(Unknown Source)
        at org.antlr.works.debugger.input.DBInputProcessorToken$1.run(DBInputProcessorToken.java:304)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

Any advice would be greatly appreciated.


- Darin



More information about the antlr-interest mailing list