Geertjan's Blog

  • January 10, 2012

From JavaCC Grammar to NetBeans Code Editor

Geertjan Wielenga
Product Manager

You can get pretty far without much coding, if you start off with a JavaCC grammar file and want to end up with an editor for your language, as these two new tutorials show:



These tutorials are based on some notes in the Wiki, created by various NetBeans Platform developers. That document should now be considered obsolete and the above two documents replace them.

More features will be described and the features described so far will be expanded. An ANTLR version of these tutorials is also in the works, though the majority of the above two tutorials, i.e., the parts describing integration with NetBeans editor features, is the same regardless of the parser/lexer generator you choose to use.

Though some parts are a bit basic, a lot of it has never been documented before. If there are parts that you know how to add in the context of the tutorials, please let me know and I will pass the sources on to you so that you can expand on them. Feedback is extremely welcome.

Update: Here's a YouTube movie to help you get started with the above!

Join the discussion

Comments ( 10 )
  • Jirka Wednesday, January 11, 2012

    This is great! Could the resulting sources be made available? (To see first where it is going, for troubleshooting, etc.)

  • Geertjan Wednesday, January 11, 2012

    Hi Jirka, the sources are here, will add this link to the tutorials too:


    Can you help me by going through the tutorials and giving me any comments about anything you find that isn't completely correct? There are a lot of gaps to be filled, so your help would be much appreciated.

  • Jirka Wednesday, January 11, 2012

    Thanks. I will go through the tutorial in detail early next week. Now, I have just downloaded the project and everything seems to work fine.

    One note though: The nb-api-samples archive contains a directory named "con". This means it is impossible to check out the whole archive on Windows, because they do not allow directories to be called "con" (or lpt1 or ...).

  • Geertjan Wednesday, January 11, 2012

    No, there's isn't any directory named "con" in nb-api-samples.

  • Jirka Wednesday, January 11, 2012
  • Geertjan Thursday, January 12, 2012

    OK, thanks, will change that.

  • guest Friday, January 13, 2012

    I love that the new tutorials put in features like code folding, brace matching, and especially indentation (as that one was a little tough to find previously).

  • Jirka Saturday, February 4, 2012

    Sorry for the delay, here are the first comments:

    - Link to the resolver documentation under SJResolver.xml points to an expired domain full of ads:


    - You say "In the layer.xml file, you should see the following:" and a long xml file follows, could you actually provide a brief comment about what it does?

    I mean something like:

    - Each <file> under ../<folder name="Actions">/ associates the files of the text/x-sj mime type with one of the predefined actions provided by the platform.

    - .shadow means the action specification is actually somewhere else in the layer - as specified by the originalFile attribute.

    - To add more actions for the .sj files follow http://wiki.netbeans.org/DevFaqActionAddFileMime

    It is all in FAQ but there is split over several files, buried in way too much detail.

    - When run, there is the Visual and History view buttons. Could you provide information about how to hide them and/or link to info on how make them work?

    - typo: There is a line break missing in the compilation by javacc:

    cd /myprojects/simplejava/src/org/simplejava/jcclexer /myjavacc40/bin/javacc Java1.5.jj

    should be changed

    cd /myprojects/simplejava/src/org/simplejava/jcclexer

    /myjavacc40/bin/javacc Java1.5.jj

  • Geertjan Sunday, February 5, 2012

    Hi Jirka, thanks for the comments. If you look at the tutorial again, you'll see most items are now fixed.

  • Geertjan Monday, February 13, 2012

    Here's a YouTube movie to help you get started with the above: https://blogs.oracle.com/geertjan/entry/video_how_to_generate_colors

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.