Package quickparse
Class QGLCompiler
java.lang.Object
quickparse.QGLCompiler
public class QGLCompiler
extends java.lang.Object
This class implements a compiler for grammars. It allows to build
A QGL source string is composed by two macro blocks:
The second rule body specifies a token that has no name (starts directly with the separator ':') and is produced by the 'my_regex2' pattern.
Grammar objects
represented through the Quick Grammar Language.Quick Grammar Language (QGL) specifications
It is a simple formal language designed to quickly describe grammars.A QGL source string is composed by two macro blocks:
- Ignored Patterns: a list of Regular Expressions that represents text pattern to be ignored
everywhere in the source of the built grammar (e.g., white-spaces or comments); See
Grammarfor more details. - Grammar Rules: the list of grammar rules; each rule is encoded by specifying a construct that is the rule head, followed by '->' or '=' symbols, and by the list of symbols that produce the head construct.
Ignored Patterns
Each ignored pattern must be specified on a single line, before any grammar rule, in the following way:ignore:pattern/$
where 'pattern' is the Regular Expression as supported by the Java Language, and '/$' is the termination
character sequence. Note that the pattern starts just after the ':' separator.
Grammar Rules
Each grammar rule must be specified on a single line in one of the following ways:HEAD -> SYMBOL1 SYMBOL2 ...
HEAD = SYMBOL1 SYMBOL2 ...
Where 'HEAD' is the name of the construct that is produce by the rule, 'SYMBOL#' are the names of the constructs or
the token symbols that produce the 'HEAD' construct.
A token symbol can be specified as a component of the rule body, by specifying a name (that can be empty) and a
pattern, as in the following example:my_construct -> my_token:my_regex1/$ ...
my_construct -> :my_regex2/$ ...
The first rule body specifies a token that is named 'my_token' and is produced by the 'my_regex1' pattern.The second rule body specifies a token that has no name (starts directly with the separator ':') and is produced by the 'my_regex2' pattern.
-
Constructor Summary
Constructors Constructor Description QGLCompiler() -
Method Summary
-
Constructor Details
-
QGLCompiler
public QGLCompiler()
-
-
Method Details
-
fromResource
public static Grammar fromResource(java.lang.ClassLoader classLoader, java.lang.String resource) throws java.io.IOException, ExpectedSymbolsException, UnexpectedSymbolExceptionCompiles agrammarfrom a resource text file.- Parameters:
classLoader- the class loader to use to load the resourceresource- the resource path- Returns:
- the compiled
grammar - Throws:
java.io.IOException- if an I/O error occurs while reading the resourcejava.lang.IllegalArgumentException- if the specified resource cannot be found through the specified class loaderExpectedSymbolsException- if an expected symbol is not found at some positionUnexpectedSymbolException- if an unexpected symbol is found at the end of the source
-
compile
public static Grammar compile(java.lang.CharSequence source) throws ExpectedSymbolsException, UnexpectedSymbolExceptionCompiles agrammarfrom a resource text file.- Parameters:
source- the source string- Returns:
- the compiled
grammar - Throws:
ExpectedSymbolsException- if an expected symbol is not found at some positionUnexpectedSymbolException- if an unexpected symbol is found at the end of the source
-