Loading ...
Sorry, an error occurred while loading the content.
 

Problems getting ANTLR lexer to distinguish ML comments from JavaDoc comments

Expand Messages
  • lfastrup
    Hi, I writing a small Java parser using ANTLR 2.7.1. I have based it on the java.g for the Java 1.3 grammer. But I also need to parse all JavaDoc comments. But
    Message 1 of 2 , Jul 1, 2002
      Hi,

      I writing a small Java parser using ANTLR 2.7.1. I have based it on
      the java.g for the Java 1.3 grammer. But I also need to parse all
      JavaDoc comments. But I hit a wall when trying to get the JavaLexer to
      skip normal multiline (/* ... */) comments but not JavaDoc comments
      (/** .... */). Here is an excerpt from my java.g file where I have
      tried to implement this separation:

      ML_COMMENT
      :
      "/*" ~'*'
      ( // see comments on NEWLINE
      options {
      generateAmbigWarnings=false;
      }
      :
      { LA(2)!='/' }? '*'
      | NEWLINE
      | ~('*'|'\n'|'\r')
      )*
      "*/"
      { $setType(Token.SKIP); }
      ;*/

      JAVADOC_OPEN
      : "/**" { Main.selector.push("doclexer"); }
      ;

      It compiles ok, but when I run it I get the following error message:

      Exception in thread "main" java.lang.ClassFormatError: JavaLexer (Code
      of a method longer than 65535 bytes)

      Do you know this bug or just a smarter way to solve my problem in the
      lexer?

      Cheers
      Lars Fastrup
    • Marco Hunsicker
      ... This problem is fixed with ANTLR 2.7.2a1 or later. It s more a problem of the JRE because of some huge static blocks generated by ANTLR. BTW, I m currently
      Message 2 of 2 , Jul 1, 2002
        >It compiles ok, but when I run it I get the following error message:
        >
        >Exception in thread "main" java.lang.ClassFormatError: JavaLexer (Code
        >of a method longer than 65535 bytes)
        >
        >Do you know this bug or just a smarter way to solve my problem in the
        >lexer?

        This problem is fixed with ANTLR 2.7.2a1 or later. It's more a problem
        of the JRE because of some huge static blocks generated by ANTLR.

        BTW, I'm currently developing yet another Java Source Code Formatter
        and already implemented a Javadoc parser. It's heavily based upon the
        HTML 3.2 grammar that ships with ANTLR and works quite good albite not
        the way you outline in your mail (I don't use multi-plexing). Anyway,
        if you want to download the sources and take a look, visit
        http://jalopy.sf.net/download.html

        Cheers,
        Marco
      Your message has been successfully submitted and would be delivered to recipients shortly.