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 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 Grammar for 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

    Modifier and Type Method Description
    static Grammar compile​(java.lang.CharSequence source)
    Compiles a grammar from a resource text file.
    static Grammar fromResource​(java.lang.ClassLoader classLoader, java.lang.String resource)
    Compiles a grammar from a resource text file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait