net.sourceforge.nrl.parser
Interface INRLParser

All Known Implementing Classes:
NRLParser

public interface INRLParser

An INRLParser is a parser that can return a fully-resolved NRL abstract syntax tree.

The way this is normally used is as follows:

  1. Call parse(InputStream) to read in an AST
  2. If an exception is thrown, process it - the result will be null
  3. Call getErrors(), which may return a mixture of syntax and semantic errors if any occurred. If so, the AST is unsafe and the errors need to be displayed to a user (or some other processing).
  4. Call resolveModelReferences(IRuleFile, IModelCollection) to resolve model references in the AST. Without this, no model information can be accessed through the AST.
  5. Call getErrors() again to check if any errors occurred during model processing. If so, the AST is unsafe and needs to be discarded.

The reason why parsing and resolving, and on the other hand resolving against a model are kept separate is that the basic AST can be validated even before a model is available, for example in an editor. For any sort of processing, a full resolution against the model should be performed.


Method Summary
 List<NRLError> getErrors()
          Returns a collection of SyntaxError and SemanticError objects.
 IRuleFile parse(InputStream stream)
          Deprecated. Use parse(URI, IResolverFactory)
 IRuleFile parse(Reader reader)
          Deprecated. Use parse(URI, IResolverFactory)
 IRuleFile parse(URI uri, IResolverFactory resolverFactory)
          Parse an input stream and construct an AST.
 void resolveModelReferences(IRuleFile ruleFile, IModelCollection models)
          Deprecated. Use parse(URI, IResolverFactory)
 void resolveOperatorReferences(IRuleFile ruleFile, IOperators[] operators)
          Deprecated. Use parse(URI, IResolverFactory)
 

Method Detail

parse

@Deprecated
IRuleFile parse(InputStream stream)
                throws Exception
Deprecated. Use parse(URI, IResolverFactory)

Throws:
Exception

parse

@Deprecated
IRuleFile parse(Reader reader)
                throws Exception
Deprecated. Use parse(URI, IResolverFactory)

Throws:
Exception

parse

IRuleFile parse(URI uri,
                IResolverFactory resolverFactory)
                throws IOException,
                       org.antlr.runtime.RecognitionException,
                       ResolverException,
                       ModelLoadingException,
                       OperatorLoadingException
Parse an input stream and construct an AST. Then resolve model references. After a call to this method, clients must:

If no check on errors is made after parsing, the AST is unstable and will cause null pointer and other exceptions.

Parameters:
uri - the NRL file URI
resolverFactory - the factory to use to load additional resources
Returns:
the rule file, which may contain errors
Throws:
IOException
org.antlr.runtime.RecognitionException
ResolverException
ModelLoadingException
OperatorLoadingException
Since:
1.4.9

resolveModelReferences

@Deprecated
void resolveModelReferences(IRuleFile ruleFile,
                                       IModelCollection models)
Deprecated. Use parse(URI, IResolverFactory)

Resolve model reference in the AST by looking up model elements. This can be called after parse(InputStream), if no errors occurred.

After a call to this method, getErrors() may contain a number of semantic errors where model references could not be looked up.

Parameters:
ruleFile - the rule file to resolve
models - the models to look at

resolveOperatorReferences

@Deprecated
void resolveOperatorReferences(IRuleFile ruleFile,
                                          IOperators[] operators)
Deprecated. Use parse(URI, IResolverFactory)

Resolve operator references in the AST by looking up operator definitions in a collection of operators. This can only be called after parse(InputStream), and after resolveModelReferences(IRuleFile, IModelCollection), if no errors occurred.

This call is kept separate to enable callers to check operator references separately - because missing definitions may or may not be treated as errors depending on the state of the rule file.

After a call to this, getErrors() will contain semantic error objects if any operators could not be resolved properly.

Parameters:
ruleFile - the file to resolve
operators - the collection of operator files

getErrors

List<NRLError> getErrors()
Returns a collection of SyntaxError and SemanticError objects. This is intended for use after parse(InputStream), and returns a different result after every call to parse.

Returns:
the collection of errors, empty if no errors occurred


Copyright © 2006-2013. All Rights Reserved.