net.sourceforge.nrl.parser
Class NRLParser

java.lang.Object
  extended by net.sourceforge.nrl.parser.NRLParser
All Implemented Interfaces:
INRLParser

public class NRLParser
extends Object
implements INRLParser

The main parser interface for creating an NRL AST. This supports both the action and constraint language, and is based on ANTLR.

See Also:
INRLParser

Constructor Summary
NRLParser()
           
 
Method Summary
 List<NRLError> getErrors()
          After any call to the parse or resolve methods, this method returns a list of errors, if any.
 IRuleFile parse(InputStream stream)
          Parse an NRL file using a stream.
 IRuleFile parse(Reader reader)
          Parse an NRL file using a reader, and return an AST.
 void resolveModelReferences(IRuleFile ruleFile, IModelCollection models)
          Attach model information to a parsed rule file AST.
 void resolveOperatorReferences(IRuleFile ruleFile, IOperators[] operators)
          Resolve reference to operator invocations given an operator collection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NRLParser

public NRLParser()
Method Detail

parse

public IRuleFile parse(Reader reader)
                throws Exception
Parse an NRL file using a reader, and return an AST. The AST will already be fully resolved and checked for basic semantic errors, but will have no model information associated.

IMPORTANT: Call getErrors() after calling this method to check if any syntax or semantic errors occurred.

Use resolveModelReferences(IRuleFile, IModelCollection) to attach model information.

Specified by:
parse in interface INRLParser
Parameters:
reader - the reader to use
Returns:
the rule file or null
Throws:
Exception

parse

public IRuleFile parse(InputStream stream)
                throws Exception
Parse an NRL file using a stream. See parse(Reader) for more information.

Specified by:
parse in interface INRLParser
Parameters:
stream - the stream
Returns:
the rule file or null if there are errors
Throws:
Exception - if a severe error occurred. The result is that even INRLParser.getErrors() will not return a meaningful result.

resolveModelReferences

public void resolveModelReferences(IRuleFile ruleFile,
                                   IModelCollection models)
Attach model information to a parsed rule file AST. This traverses the AST and decorates any model references with actual elements from the model.

After calling this, you must call getErrors() to check if any errors occurred. If so, the AST may be unstable.

Specified by:
resolveModelReferences in interface INRLParser
Parameters:
ruleFile - the rule file to decorate
models - the models to use

resolveOperatorReferences

public void resolveOperatorReferences(IRuleFile ruleFile,
                                      IOperators[] operators)
Resolve reference to operator invocations given an operator collection. The operator collection has to be loaded separately from an XML descriptor file, if one is available.

Specified by:
resolveOperatorReferences in interface INRLParser
Parameters:
ruleFile - the file to resolve
operators - the collection of operator files
See Also:
XmlOperatorPersistence

getErrors

public List<NRLError> getErrors()
After any call to the parse or resolve methods, this method returns a list of errors, if any.

Specified by:
getErrors in interface INRLParser
Returns:
the collection of errors, empty if no errors occurred


Copyright © 2006-2010 Christian Nentwich and others