2
@brief ANTLR3 runtime package
4
This module contains all support classes, which are needed to use recognizers
9
\note Please be warned that the line numbers in the API documentation do not
10
match the real locations in the source code of the package. This is an
11
unintended artifact of doxygen, which I could only convince to use the
12
correct module names by concatenating all files from the package into a single
15
Here is a little overview over the most commonly used classes provided by
18
@section recognizers Recognizers
20
These recognizers are baseclasses for the code which is generated by ANTLR3.
22
- BaseRecognizer: Base class with common recognizer functionality.
23
- Lexer: Base class for lexers.
24
- Parser: Base class for parsers.
25
- tree.TreeParser: Base class for %tree parser.
27
@section streams Streams
29
Each recognizer pulls its input from one of the stream classes below. Streams
30
handle stuff like buffering, look-ahead and seeking.
32
A character stream is usually the first element in the pipeline of a typical
33
ANTLR3 application. It is used as the input for a Lexer.
35
- ANTLRStringStream: Reads from a string objects. The input should be a unicode
36
object, or ANTLR3 will have trouble decoding non-ascii data.
37
- ANTLRFileStream: Opens a file and read the contents, with optional character
39
- ANTLRInputStream: Reads the date from a file-like object, with optional
42
A Parser needs a TokenStream as input (which in turn is usually fed by a
45
- CommonTokenStream: A basic and most commonly used TokenStream
47
- TokenRewriteStream: A modification of CommonTokenStream that allows the
48
stream to be altered (by the Parser). See the 'tweak' example for a usecase.
50
And tree.TreeParser finally fetches its input from a tree.TreeNodeStream:
52
- tree.CommonTreeNodeStream: A basic and most commonly used tree.TreeNodeStream
56
@section tokenstrees Tokens and Trees
58
A Lexer emits Token objects which are usually buffered by a TokenStream. A
59
Parser can build a Tree, if the output=AST option has been set in the grammar.
61
The runtime provides these Token implementations:
63
- CommonToken: A basic and most commonly used Token implementation.
64
- ClassicToken: A Token object as used in ANTLR 2.x, used to %tree
67
Tree objects are wrapper for Token objects.
69
- tree.CommonTree: A basic and most commonly used Tree implementation.
71
A tree.TreeAdaptor is used by the parser to create tree.Tree objects for the
74
- tree.CommonTreeAdaptor: A basic and most commonly used tree.TreeAdaptor
80
RecognitionException are generated, when a recognizer encounters incorrect
83
- RecognitionException
84
- MismatchedRangeException
85
- MismatchedSetException
86
- MismatchedNotSetException
88
- MismatchedTokenException
89
- MismatchedTreeNodeException
90
- NoViableAltException
92
- FailedPredicateException
96
A tree.RewriteCardinalityException is raised, when the parsers hits a
97
cardinality mismatch during AST construction. Although this is basically a
98
bug in your grammar, it can only be detected at runtime.
100
- tree.RewriteCardinalityException
101
- tree.RewriteEarlyExitException
102
- tree.RewriteEmptyStreamException
108
# tree.RewriteRuleElementStream
109
# tree.RewriteRuleSubtreeStream
110
# tree.RewriteRuleTokenStream
115
# [The "BSD licence"]
116
# Copyright (c) 2005-2008 Terence Parr
117
# All rights reserved.
119
# Redistribution and use in source and binary forms, with or without
120
# modification, are permitted provided that the following conditions
122
# 1. Redistributions of source code must retain the above copyright
123
# notice, this list of conditions and the following disclaimer.
124
# 2. Redistributions in binary form must reproduce the above copyright
125
# notice, this list of conditions and the following disclaimer in the
126
# documentation and/or other materials provided with the distribution.
127
# 3. The name of the author may not be used to endorse or promote products
128
# derived from this software without specific prior written permission.
130
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
131
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
132
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
133
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
134
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
135
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
136
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
137
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
138
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
139
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
141
__version__ = '3.1.1'
143
def version_str_to_tuple(version_str):
147
if version_str == 'HEAD':
148
return (sys.maxint, sys.maxint, sys.maxint, sys.maxint)
150
m = re.match(r'(\d+)\.(\d+)(\.(\d+))?(b(\d+))?', version_str)
152
raise ValueError("Bad version string %r" % version_str)
154
major = int(m.group(1))
155
minor = int(m.group(2))
156
patch = int(m.group(4) or 0)
157
beta = int(m.group(6) or sys.maxint)
159
return (major, minor, patch, beta)
162
runtime_version_str = __version__
163
runtime_version = version_str_to_tuple(runtime_version_str)
166
from constants import *
168
from exceptions import *
169
from recognizers import *
170
from streams import *