[antlr-interest] Antlr 2.7.2a2 and NetBeans

Sinan sinan.karasu at boeing.com
Wed Mar 13 09:47:05 PST 2002



I am currently trying to revamp the antlr module in netbeans.

What they have done esentially is take antlr.g and modify it to
suit their prupose. Looking thru it it appears that what is really
needed is a simple grammar inheritance. So here is a modest proposal
for a simple way to do that. 

The following code snippet ( other than the ignored bodies for
a couple of methods) shgould be the complete .g file for
antlreditor.g

/// ---begin------------
header {
/*
 * ............bunch of netbeans comments
 */
package org.netbeans.modules.antlr.editor.g;
}


class ANTLREditorParser extends ANTLRParser;


{
	SecondaryFileHandler behavior;

	public void reportError(String s) {
		behaviour.reportError(s);
	}
	
	public ANTLRParser(
		TokenBuffer tokenBuf, 
		SecondaryFileHandler behavior_
			) {
			super(tokenBuf, 1);
			tokenNames = _tokenNames;
			behavior = behavior_;
	}

	public static void dump (PrintStream out, SecondaryFileHandler
behavior)
	{
		// some code here...
	}

	public static void scan (String filename)
	{
		// some more code here.....
	}

	public static void main (String[] args)
	{
	// some some more more code here......
	}
}
	
// ---end---------

However looking thru antlr.g in 2.7.2a2 	


The following lines cause a little grief ( who wrote this stuff
anyway?).

Specifically the problems re that the messages should be directed to the
editor infrastructure in netbeans. I can do that by overriding
reportError
method, and I can modify the lines that talks to antlrTool.error(),
antlrTool.warning(). However. If theselines were changed to call

error() , and warning() , then I can override them without any
modification
to the antlr. g...

Ric, Ter, any comments???

Sinan


// ----------problematic lines------------
//				reportError("line "+ex.line+": JAVADOC comments may only prefix
rules and grammars");
				antlrTool.error("JAVADOC comments may only prefix rules and
grammars", getFilename(), ex.getLine(), ex.getColumn());
---------
				antlrTool.error(ex.getMessage(), getFilename(), ex.getLine(),
ex.getColumn());
//				reportError("rule classDef trapped:\n"+ex.toString());
			antlrTool.error(ex.getMessage(), getFilename(), ex.getLine(),
ex.getColumn());
//			reportError("rule classDef trapped:\n"+ex.toString());
----------
			antlrTool.warning("did you forget to terminate previous rule?",
getFilename(), label.getLine(), label.getColumn());


----------	
		antlrTool.error("Malformed range line ", getFilename(), c1.getLine(),
c1.getColumn());
		
----------
 			antlrTool.warning("use 'class X extends Parser'", getFilename(),
idTok.getLine(), idTok.getColumn());
//			System.out.println("warning: line " +
//				idTok.getLine() + ": use 'class X extends Parser'");

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list