antlr3 1.6.0 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +8 -0
- data/Manifest.txt +94 -0
- data/README.txt +1 -1
- data/Rakefile +58 -0
- data/bin/antlr4ruby +101 -7
- data/java/antlr-full-3.2.1.jar +0 -0
- data/lib/antlr3.rb +38 -10
- data/lib/antlr3/constants.rb +13 -5
- data/lib/antlr3/debug.rb +57 -57
- data/lib/antlr3/dfa.rb +138 -68
- data/lib/antlr3/dot.rb +32 -32
- data/lib/antlr3/error.rb +85 -78
- data/lib/antlr3/main.rb +191 -187
- data/lib/antlr3/profile.rb +71 -70
- data/lib/antlr3/recognizers.rb +261 -226
- data/lib/antlr3/streams.rb +85 -84
- data/lib/antlr3/streams/interactive.rb +20 -27
- data/lib/antlr3/streams/rewrite.rb +89 -89
- data/lib/antlr3/task.rb +42 -33
- data/lib/antlr3/template.rb +2 -2
- data/lib/antlr3/template/group-lexer.rb +1 -1
- data/lib/antlr3/token.rb +76 -68
- data/lib/antlr3/tree.rb +125 -121
- data/lib/antlr3/tree/visitor.rb +1 -1
- data/lib/antlr3/tree/wizard.rb +1 -1
- data/lib/antlr3/util.rb +32 -33
- data/lib/antlr3/version.rb +3 -3
- data/templates/Ruby.stg +1 -1
- data/test/unit/test-streams.rb +11 -10
- data/test/unit/test-template.rb +206 -204
- metadata +4 -2
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
=== 1.6.3 / 02-12-10
|
2
|
+
|
3
|
+
* 4 Minor Enhancements
|
4
|
+
- added --help and --version options to antlr4ruby
|
5
|
+
- documented the antlr4ruby source and added license information
|
6
|
+
- prettied up the source code in all of the library files a little
|
7
|
+
- added a hoe-based rakefile with the gem distribution of the source code
|
8
|
+
|
1
9
|
=== 1.6.0 / 01-27-10
|
2
10
|
|
3
11
|
* 4 Minor Enhancements to runtime library
|
data/Manifest.txt
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
bin/antlr4ruby
|
2
|
+
lib/antlr3/main.rb
|
3
|
+
lib/antlr3/recognizers.rb
|
4
|
+
lib/antlr3/modes/ast-builder.rb
|
5
|
+
lib/antlr3/modes/filter.rb
|
6
|
+
lib/antlr3/streams/rewrite.rb
|
7
|
+
lib/antlr3/streams/interactive.rb
|
8
|
+
lib/antlr3/debug.rb
|
9
|
+
lib/antlr3/dot.rb
|
10
|
+
lib/antlr3/streams.rb
|
11
|
+
lib/antlr3/debug/record-event-listener.rb
|
12
|
+
lib/antlr3/debug/rule-tracer.rb
|
13
|
+
lib/antlr3/debug/socket.rb
|
14
|
+
lib/antlr3/debug/trace-event-listener.rb
|
15
|
+
lib/antlr3/debug/event-hub.rb
|
16
|
+
lib/antlr3/version.rb
|
17
|
+
lib/antlr3/error.rb
|
18
|
+
lib/antlr3/tree.rb
|
19
|
+
lib/antlr3/test/functional.rb
|
20
|
+
lib/antlr3/test/call-stack.rb
|
21
|
+
lib/antlr3/test/grammar.rb
|
22
|
+
lib/antlr3/test/core-extensions.rb
|
23
|
+
lib/antlr3/template.rb
|
24
|
+
lib/antlr3/dfa.rb
|
25
|
+
lib/antlr3/profile.rb
|
26
|
+
lib/antlr3/template/parameter.rb
|
27
|
+
lib/antlr3/template/group-lexer.rb
|
28
|
+
lib/antlr3/template/group-parser.rb
|
29
|
+
lib/antlr3/tree/visitor.rb
|
30
|
+
lib/antlr3/tree/debug.rb
|
31
|
+
lib/antlr3/tree/wizard.rb
|
32
|
+
lib/antlr3/token.rb
|
33
|
+
lib/antlr3/task.rb
|
34
|
+
lib/antlr3/constants.rb
|
35
|
+
lib/antlr3/util.rb
|
36
|
+
lib/antlr3.rb
|
37
|
+
test/unit/test-dfa.rb
|
38
|
+
test/unit/sample-input/file-stream-1
|
39
|
+
test/unit/sample-input/template-group
|
40
|
+
test/unit/sample-input/teststreams.input2
|
41
|
+
test/unit/test-tree-wizard.rb
|
42
|
+
test/unit/test-streams.rb
|
43
|
+
test/unit/test-recognizers.rb
|
44
|
+
test/unit/test-trees.rb
|
45
|
+
test/unit/test-exceptions.rb
|
46
|
+
test/unit/test-scheme.rb
|
47
|
+
test/unit/test-template.rb
|
48
|
+
test/functional/delegation/import.rb
|
49
|
+
test/functional/lexer/xml.rb
|
50
|
+
test/functional/lexer/properties.rb
|
51
|
+
test/functional/lexer/nuances.rb
|
52
|
+
test/functional/lexer/basic.rb
|
53
|
+
test/functional/lexer/filter-mode.rb
|
54
|
+
test/functional/lexer/syn-pred.rb
|
55
|
+
test/functional/debugging/rule-tracing.rb
|
56
|
+
test/functional/debugging/profile-mode.rb
|
57
|
+
test/functional/debugging/debug-mode.rb
|
58
|
+
test/functional/ast-output/hetero-nodes.rb
|
59
|
+
test/functional/ast-output/construction.rb
|
60
|
+
test/functional/ast-output/rewrites.rb
|
61
|
+
test/functional/ast-output/tree-rewrite.rb
|
62
|
+
test/functional/ast-output/auto-ast.rb
|
63
|
+
test/functional/main/main-scripts.rb
|
64
|
+
test/functional/tree-parser/basic.rb
|
65
|
+
test/functional/parser/predicates.rb
|
66
|
+
test/functional/parser/backtracking.rb
|
67
|
+
test/functional/parser/properties.rb
|
68
|
+
test/functional/parser/nuances.rb
|
69
|
+
test/functional/parser/rule-methods.rb
|
70
|
+
test/functional/parser/basic.rb
|
71
|
+
test/functional/parser/actions.rb
|
72
|
+
test/functional/parser/calc.rb
|
73
|
+
test/functional/parser/ll-star.rb
|
74
|
+
test/functional/parser/scopes.rb
|
75
|
+
test/functional/template-output/template-output.rb
|
76
|
+
test/functional/token-rewrite/via-parser.rb
|
77
|
+
test/functional/token-rewrite/basic.rb
|
78
|
+
templates/ASTDbg.stg
|
79
|
+
templates/AST.stg
|
80
|
+
templates/Ruby.stg
|
81
|
+
templates/ST.stg
|
82
|
+
templates/Dbg.stg
|
83
|
+
templates/ASTParser.stg
|
84
|
+
templates/ASTTreeParser.stg
|
85
|
+
samples/CPP.g
|
86
|
+
samples/ANTLRv3Grammar.g
|
87
|
+
README.txt
|
88
|
+
ANTLR-LICENSE.txt
|
89
|
+
History.txt
|
90
|
+
Manifest.txt
|
91
|
+
java/antlr-full-3.2.1.jar
|
92
|
+
java/RubyTarget.java
|
93
|
+
Manifest.txt
|
94
|
+
Rakefile
|
data/README.txt
CHANGED
@@ -111,7 +111,7 @@ ANTLR provides for other language targets, such as Java and Python. It contains:
|
|
111
111
|
== LICENSE
|
112
112
|
|
113
113
|
[The "BSD licence"]
|
114
|
-
Copyright (c) 2009 Kyle Yetter
|
114
|
+
Copyright (c) 2009-2010 Kyle Yetter
|
115
115
|
All rights reserved.
|
116
116
|
|
117
117
|
Redistribution and use in source and binary forms, with or without
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'antlr3'
|
5
|
+
require 'hoe'
|
6
|
+
|
7
|
+
Hoe.spec "antlr3" do
|
8
|
+
self.version = ANTLR3::VERSION_STRING
|
9
|
+
self.rubyforge_name = "antlr3"
|
10
|
+
|
11
|
+
developer "Kyle Yetter", "kcy5b@yahoo.com"
|
12
|
+
|
13
|
+
spec_extras.update(
|
14
|
+
:required_ruby_version => ">= 1.8.7"
|
15
|
+
)
|
16
|
+
|
17
|
+
self.test_globs = [
|
18
|
+
"test/unit/test-dfa.rb",
|
19
|
+
"test/unit/test-tree-wizard.rb",
|
20
|
+
"test/unit/test-streams.rb",
|
21
|
+
"test/unit/test-recognizers.rb",
|
22
|
+
"test/unit/test-trees.rb",
|
23
|
+
"test/unit/test-exceptions.rb",
|
24
|
+
"test/unit/test-scheme.rb",
|
25
|
+
"test/unit/test-template.rb",
|
26
|
+
"test/functional/delegation/import.rb",
|
27
|
+
"test/functional/lexer/xml.rb",
|
28
|
+
"test/functional/lexer/properties.rb",
|
29
|
+
"test/functional/lexer/nuances.rb",
|
30
|
+
"test/functional/lexer/basic.rb",
|
31
|
+
"test/functional/lexer/filter-mode.rb",
|
32
|
+
"test/functional/lexer/syn-pred.rb",
|
33
|
+
"test/functional/debugging/rule-tracing.rb",
|
34
|
+
"test/functional/debugging/profile-mode.rb",
|
35
|
+
"test/functional/debugging/debug-mode.rb",
|
36
|
+
"test/functional/ast-output/hetero-nodes.rb",
|
37
|
+
"test/functional/ast-output/construction.rb",
|
38
|
+
"test/functional/ast-output/rewrites.rb",
|
39
|
+
"test/functional/ast-output/tree-rewrite.rb",
|
40
|
+
"test/functional/ast-output/auto-ast.rb",
|
41
|
+
"test/functional/main/main-scripts.rb",
|
42
|
+
"test/functional/tree-parser/basic.rb",
|
43
|
+
"test/functional/parser/predicates.rb",
|
44
|
+
"test/functional/parser/backtracking.rb",
|
45
|
+
"test/functional/parser/properties.rb",
|
46
|
+
"test/functional/parser/nuances.rb",
|
47
|
+
"test/functional/parser/rule-methods.rb",
|
48
|
+
"test/functional/parser/basic.rb",
|
49
|
+
"test/functional/parser/actions.rb",
|
50
|
+
"test/functional/parser/calc.rb",
|
51
|
+
"test/functional/parser/ll-star.rb",
|
52
|
+
"test/functional/parser/scopes.rb",
|
53
|
+
"test/functional/template-output/template-output.rb",
|
54
|
+
"test/functional/token-rewrite/via-parser.rb",
|
55
|
+
"test/functional/token-rewrite/basic.rb"
|
56
|
+
]
|
57
|
+
|
58
|
+
end
|
data/bin/antlr4ruby
CHANGED
@@ -1,12 +1,106 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
=begin LICENSE
|
5
|
+
|
6
|
+
[The "BSD licence"]
|
7
|
+
Copyright (c) 2009 Kyle Yetter
|
8
|
+
All rights reserved.
|
9
|
+
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
11
|
+
modification, are permitted provided that the following conditions
|
12
|
+
are met:
|
13
|
+
|
14
|
+
1. Redistributions of source code must retain the above copyright
|
15
|
+
notice, this list of conditions and the following disclaimer.
|
16
|
+
2. Redistributions in binary form must reproduce the above copyright
|
17
|
+
notice, this list of conditions and the following disclaimer in the
|
18
|
+
documentation and/or other materials provided with the distribution.
|
19
|
+
3. The name of the author may not be used to endorse or promote products
|
20
|
+
derived from this software without specific prior written permission.
|
21
|
+
|
22
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
23
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
24
|
+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
25
|
+
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
26
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
27
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
28
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
29
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
30
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
31
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
|
33
|
+
=end
|
34
|
+
|
35
|
+
=begin rdoc antlr4ruby
|
36
|
+
|
37
|
+
A simple wrapper script to run the ANTLR tool with the ruby antlr3
|
38
|
+
target modifications in place of the default Ruby target data.
|
39
|
+
It essentially does two things:
|
40
|
+
|
41
|
+
* locate the `customized' ANTLR v.3 JAR archive file
|
42
|
+
* exec the command <tt>java -cp path/to/jar $ARGV</tt>
|
43
|
+
|
44
|
+
Thus, for ANTLR tool usage, refer to ANTLR's main documentation
|
45
|
+
at http://www.antlr.org .
|
46
|
+
|
47
|
+
There are a small number of additional options available
|
48
|
+
in addition to ANTLR's options:
|
49
|
+
|
50
|
+
--version display the Ruby target version and then the
|
51
|
+
ANTLR tool's version information
|
52
|
+
|
53
|
+
--help, -h as ANTLR does not provide these standard switches,
|
54
|
+
it executes the ANTLR tool without arguments to make
|
55
|
+
it print out usage information
|
56
|
+
|
57
|
+
--keep-classpath Do not unset the CLASSPATH environmental variable before
|
58
|
+
executing the java command (*)
|
59
|
+
|
60
|
+
|
61
|
+
(*) This script unsets CLASSPATH to avoid interference from system installations
|
62
|
+
of prior versions of ANTLR. The jar that is distributed with this package
|
63
|
+
is complete, and thus does not generally require any external libraries, so
|
64
|
+
this shouldn't cause any major problems. However, if for some reason you
|
65
|
+
need to keep this variable to execute the command properly, you can use
|
66
|
+
the --keep-classpath option.
|
67
|
+
=end
|
68
|
+
|
69
|
+
$0 = 'antlr4ruby'
|
70
|
+
|
71
|
+
begin
|
72
|
+
require 'antlr3'
|
73
|
+
rescue LoadError
|
74
|
+
__DIR__ = File.expand_path( File.dirname __FILE__ )
|
75
|
+
project_top = File.dirname __DIR__
|
76
|
+
lib = File.join( project_top, 'lib' )
|
77
|
+
$LOAD_PATH.unshift( lib )
|
78
|
+
require 'antlr3'
|
79
|
+
end
|
9
80
|
|
10
81
|
jar = ANTLR3.antlr_jar or fail( "cannot find antlr4ruby's customized ANTLR jar" )
|
11
82
|
|
12
|
-
|
83
|
+
run = proc do | *args |
|
84
|
+
exec( 'java', '-jar', jar, *args )
|
85
|
+
end
|
86
|
+
|
87
|
+
ARGV.delete( '--keep-classpath' ) or
|
88
|
+
ENV.delete( 'CLASSPATH' )
|
89
|
+
|
90
|
+
if ARGV.include?( '--version' )
|
91
|
+
|
92
|
+
puts( "Ruby Target and Runtime Library Version: #{ ANTLR3::VERSION_STRING }" )
|
93
|
+
run.call( '-version' )
|
94
|
+
|
95
|
+
elsif ARGV.include?( '--help' ) or ARGV.include?( '-h' )
|
96
|
+
|
97
|
+
# the ANTLR tool doesn't follow the --help/-h convention
|
98
|
+
# -- it provides help only if no arguments are specified
|
99
|
+
run.call
|
100
|
+
|
101
|
+
else
|
102
|
+
|
103
|
+
# run the tool
|
104
|
+
run.call( *ARGV )
|
105
|
+
|
106
|
+
end
|
data/java/antlr-full-3.2.1.jar
CHANGED
Binary file
|
data/lib/antlr3.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
=begin LICENSE
|
5
5
|
|
6
6
|
[The "BSD licence"]
|
7
|
-
Copyright (c) 2009 Kyle Yetter
|
7
|
+
Copyright (c) 2009-2010 Kyle Yetter
|
8
8
|
All rights reserved.
|
9
9
|
|
10
10
|
Redistribution and use in source and binary forms, with or without
|
@@ -93,10 +93,13 @@ antlr3/dot.rb::
|
|
93
93
|
extra utilities to generate DOT map specifications for graphical.
|
94
94
|
representations of ASTs
|
95
95
|
|
96
|
+
@author Kyle Yetter
|
97
|
+
|
96
98
|
=end
|
97
99
|
|
98
100
|
module ANTLR3
|
99
|
-
|
101
|
+
|
102
|
+
# :stopdoc:
|
100
103
|
LIBRARY_PATH = ::File.expand_path(::File.dirname(__FILE__))
|
101
104
|
# :startdoc:
|
102
105
|
|
@@ -126,8 +129,27 @@ module ANTLR3
|
|
126
129
|
raise(bug)
|
127
130
|
end
|
128
131
|
|
132
|
+
@antlr_jar = nil
|
133
|
+
|
134
|
+
def self.antlr_jar=( path )
|
135
|
+
@antlr_jar = path ? File.expand_path( path.to_s ) : path
|
136
|
+
end
|
137
|
+
|
129
138
|
def self.antlr_jar
|
130
|
-
|
139
|
+
@antlr_jar and return( @antlr_jar )
|
140
|
+
|
141
|
+
path = project_path "java/antlr-full-#{ ANTLR_VERSION_STRING }.jar"
|
142
|
+
if env_path = ENV[ 'RUBY_ANTLR_JAR' ]
|
143
|
+
if File.file?( env_path ) then return File.expand_path( env_path ) end
|
144
|
+
|
145
|
+
warn(
|
146
|
+
"#{ __FILE__ }:#{ __LINE__ }: " <<
|
147
|
+
"ignoring environmental variable RUBY_ANTLR_JAR (=%p) " % env_path <<
|
148
|
+
"as it is not the path to an existing file\n" <<
|
149
|
+
" -> trying default jar path %p instead" % path
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
131
153
|
File.exists?( path ) ? path : nil
|
132
154
|
end
|
133
155
|
|
@@ -138,6 +160,8 @@ module ANTLR3
|
|
138
160
|
# Tree classes are only used by tree parsers or AST-building parsers
|
139
161
|
# Thus, they're not essential for everything ANTLR generates and
|
140
162
|
# are autoloaded on-demand
|
163
|
+
autoload :AST, 'antlr3/tree'
|
164
|
+
|
141
165
|
tree_classes = [
|
142
166
|
:Tree, :TreeAdaptor, :BaseTree, :BaseTreeAdaptor,
|
143
167
|
:CommonTree, :CommonErrorNode, :CommonTreeAdaptor,
|
@@ -146,7 +170,7 @@ module ANTLR3
|
|
146
170
|
:RewriteRuleTokenStream, :RewriteRuleSubtreeStream,
|
147
171
|
:RewriteRuleNodeStream
|
148
172
|
]
|
149
|
-
|
173
|
+
|
150
174
|
for klass in tree_classes
|
151
175
|
autoload klass, 'antlr3/tree'
|
152
176
|
end
|
@@ -167,12 +191,16 @@ module ANTLR3
|
|
167
191
|
|
168
192
|
end # module ANTLR3
|
169
193
|
|
194
|
+
|
170
195
|
require 'set'
|
171
196
|
require 'antlr3/util'
|
172
197
|
require 'antlr3/version'
|
173
|
-
|
174
|
-
|
175
|
-
require 'antlr3/
|
176
|
-
require 'antlr3/
|
177
|
-
require 'antlr3/
|
178
|
-
require 'antlr3/
|
198
|
+
|
199
|
+
unless $0 == 'antlr4ruby'
|
200
|
+
require 'antlr3/constants'
|
201
|
+
require 'antlr3/error'
|
202
|
+
require 'antlr3/token'
|
203
|
+
require 'antlr3/recognizers'
|
204
|
+
require 'antlr3/dfa'
|
205
|
+
require 'antlr3/streams'
|
206
|
+
end
|
data/lib/antlr3/constants.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
=begin LICENSE
|
5
5
|
|
6
6
|
[The "BSD licence"]
|
7
|
-
Copyright (c) 2009 Kyle Yetter
|
7
|
+
Copyright (c) 2009-2010 Kyle Yetter
|
8
8
|
All rights reserved.
|
9
9
|
|
10
10
|
Redistribution and use in source and binary forms, with or without
|
@@ -45,18 +45,26 @@ module Constants
|
|
45
45
|
# built-in token channel IDs
|
46
46
|
|
47
47
|
# the channel to which most tokens will be assigned
|
48
|
-
DEFAULT = DEFAULT_CHANNEL = :default
|
48
|
+
DEFAULT = DEFAULT_CHANNEL = DEFAULT_TOKEN_CHANNEL = :default
|
49
49
|
|
50
50
|
# the channel for tokens which should not be passed to a parser by a token stream
|
51
51
|
HIDDEN = HIDDEN_CHANNEL = :hidden
|
52
52
|
|
53
|
+
# flag used by recognizers during memoization to
|
54
|
+
# represent a previous prediction failure
|
55
|
+
MEMO_RULE_FAILED = -2
|
56
|
+
|
57
|
+
# flag used by recognizers during memoization to indicate
|
58
|
+
# that the rule has not been memoized yet
|
59
|
+
MEMO_RULE_UNKNOWN = -1
|
60
|
+
|
53
61
|
# built-in token types used internally by ANTLR3
|
54
62
|
|
55
63
|
INVALID_TOKEN_TYPE = 0
|
56
64
|
|
57
|
-
# End of File / End of Input character and token type
|
58
65
|
EOF = -1
|
59
66
|
|
67
|
+
|
60
68
|
# Imaginary tree-navigation token type indicating the ascent after moving through the
|
61
69
|
# children of a node
|
62
70
|
UP = 3
|
@@ -74,10 +82,10 @@ module Constants
|
|
74
82
|
# returning a string "<UNKNOWN: #{type}>" for non-builtin token
|
75
83
|
# types
|
76
84
|
BUILT_IN_TOKEN_NAMES = Hash.new do |h, k|
|
77
|
-
"<UNKNOWN: #{k}>"
|
85
|
+
"<UNKNOWN: #{ k }>"
|
78
86
|
end
|
79
87
|
|
80
|
-
BUILT_IN_TOKEN_NAMES.update(
|
88
|
+
BUILT_IN_TOKEN_NAMES.update(
|
81
89
|
0 => "<invalid>".freeze, 1 => "<EOR>".freeze,
|
82
90
|
2 => "<DOWN>".freeze, 3 => "<UP>".freeze,
|
83
91
|
-1 => "<EOF>".freeze
|
data/lib/antlr3/debug.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
=begin LICENSE
|
5
5
|
|
6
6
|
[The "BSD licence"]
|
7
|
-
Copyright (c) 2009 Kyle Yetter
|
7
|
+
Copyright (c) 2009-2010 Kyle Yetter
|
8
8
|
All rights reserved.
|
9
9
|
|
10
10
|
Redistribution and use in source and binary forms, with or without
|
@@ -58,7 +58,7 @@ autoload :EventHub, 'antlr3/debug/event-hub'
|
|
58
58
|
autoload :TreeAdaptor, 'antlr3/tree/debug'
|
59
59
|
autoload :TreeNodeStream, 'antlr3/tree/debug'
|
60
60
|
|
61
|
-
RecognizerSharedState = Struct.new(
|
61
|
+
RecognizerSharedState = Struct.new(
|
62
62
|
# the rule invocation depth
|
63
63
|
:rule_invocation_stack,
|
64
64
|
# a boolean flag to indicate whether or not the current decision is cyclic
|
@@ -101,7 +101,7 @@ generated in debug or profiling mode.
|
|
101
101
|
=end
|
102
102
|
class RecognizerSharedState
|
103
103
|
def initialize
|
104
|
-
super([], false, [], false, -1, 0, nil, 0, nil, -1)
|
104
|
+
super( [], false, [], false, -1, 0, nil, 0, nil, -1 )
|
105
105
|
# ^-- same as this --v
|
106
106
|
# self.following = []
|
107
107
|
# self.error_recovery = false
|
@@ -141,9 +141,9 @@ switch.
|
|
141
141
|
module ParserEvents
|
142
142
|
include ANTLR3::Error
|
143
143
|
|
144
|
-
def self.included(klass)
|
144
|
+
def self.included( klass )
|
145
145
|
super
|
146
|
-
if klass.is_a?(::Class)
|
146
|
+
if klass.is_a?( ::Class )
|
147
147
|
def klass.debug?
|
148
148
|
true
|
149
149
|
end
|
@@ -153,16 +153,16 @@ module ParserEvents
|
|
153
153
|
|
154
154
|
attr_reader :debug_listener
|
155
155
|
|
156
|
-
def initialize(stream, options = {})
|
157
|
-
@debug_listener = options[:debug_listener] ||= begin
|
156
|
+
def initialize( stream, options = {} )
|
157
|
+
@debug_listener = options[ :debug_listener ] ||= begin
|
158
158
|
EventSocketProxy.new( self, options ).handshake
|
159
159
|
end
|
160
|
-
options[:state] ||= Debug::RecognizerSharedState.new
|
161
|
-
super(stream, options)
|
162
|
-
if @input.is_a?(Debug::TokenStream)
|
160
|
+
options[ :state ] ||= Debug::RecognizerSharedState.new
|
161
|
+
super( stream, options )
|
162
|
+
if @input.is_a?( Debug::TokenStream )
|
163
163
|
@input.debug_listener ||= @debug_listener
|
164
164
|
else
|
165
|
-
@input = Debug::TokenStream.wrap(@input, @debug_listener)
|
165
|
+
@input = Debug::TokenStream.wrap( @input, @debug_listener )
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -174,14 +174,14 @@ module ParserEvents
|
|
174
174
|
@state.cyclic_decision
|
175
175
|
end
|
176
176
|
|
177
|
-
def cyclic_decision=(flag)
|
177
|
+
def cyclic_decision=( flag )
|
178
178
|
@state.cyclic_decision = flag
|
179
179
|
end
|
180
180
|
|
181
181
|
# custom attribute writer for debug_listener
|
182
182
|
# propegates the change in listener to the
|
183
183
|
# parser's debugging input stream
|
184
|
-
def debug_listener=(dbg)
|
184
|
+
def debug_listener=( dbg )
|
185
185
|
@debug_listener = dbg
|
186
186
|
@input.debug_listener = dbg rescue nil
|
187
187
|
end
|
@@ -199,22 +199,22 @@ module ParserEvents
|
|
199
199
|
# TO-DO: is this pointless?
|
200
200
|
def resync
|
201
201
|
begin_resync
|
202
|
-
yield(self)
|
202
|
+
yield( self )
|
203
203
|
ensure
|
204
204
|
end_resync
|
205
205
|
end
|
206
206
|
|
207
207
|
def begin_backtrack
|
208
|
-
@debug_listener.begin_backtrack(@state.backtracking)
|
208
|
+
@debug_listener.begin_backtrack( @state.backtracking )
|
209
209
|
end
|
210
210
|
|
211
|
-
def end_backtrack(successful)
|
212
|
-
@debug_listener.end_backtrack(@state.backtracking, successful)
|
211
|
+
def end_backtrack( successful )
|
212
|
+
@debug_listener.end_backtrack( @state.backtracking, successful )
|
213
213
|
end
|
214
214
|
|
215
215
|
def backtrack
|
216
216
|
@state.backtracking += 1
|
217
|
-
@debug_listener.begin_backtrack(@state.backtracking)
|
217
|
+
@debug_listener.begin_backtrack( @state.backtracking )
|
218
218
|
start = @input.mark
|
219
219
|
success =
|
220
220
|
begin yield
|
@@ -223,8 +223,8 @@ module ParserEvents
|
|
223
223
|
end
|
224
224
|
return success
|
225
225
|
ensure
|
226
|
-
@input.rewind(start)
|
227
|
-
@debug_listener.end_backtrack(@state.backtracking, (success rescue nil))
|
226
|
+
@input.rewind( start )
|
227
|
+
@debug_listener.end_backtrack( @state.backtracking, ( success rescue nil ) )
|
228
228
|
@state.backtracking -= 1
|
229
229
|
end
|
230
230
|
|
@@ -240,43 +240,43 @@ module ParserEvents
|
|
240
240
|
return( symbol )
|
241
241
|
end
|
242
242
|
|
243
|
-
def in_rule(grammar_file, rule_name)
|
243
|
+
def in_rule( grammar_file, rule_name )
|
244
244
|
@state.rule_invocation_stack.empty? and @debug_listener.commence
|
245
|
-
@debug_listener.enter_rule(grammar_file, rule_name)
|
246
|
-
@state.rule_invocation_stack.push(grammar_file, rule_name)
|
245
|
+
@debug_listener.enter_rule( grammar_file, rule_name )
|
246
|
+
@state.rule_invocation_stack.push( grammar_file, rule_name )
|
247
247
|
yield
|
248
248
|
ensure
|
249
|
-
@state.rule_invocation_stack.pop(2)
|
250
|
-
@debug_listener.exit_rule(grammar_file, rule_name)
|
249
|
+
@state.rule_invocation_stack.pop( 2 )
|
250
|
+
@debug_listener.exit_rule( grammar_file, rule_name )
|
251
251
|
@state.rule_invocation_stack.empty? and @debug_listener.terminate
|
252
252
|
end
|
253
253
|
|
254
254
|
def rule_invocation_stack
|
255
|
-
@state.rule_invocation_stack.each_slice(2).to_a
|
255
|
+
@state.rule_invocation_stack.each_slice( 2 ).to_a
|
256
256
|
end
|
257
257
|
|
258
|
-
def predicate?(description)
|
258
|
+
def predicate?( description )
|
259
259
|
result = yield
|
260
|
-
@debug_listener.semantic_predicate(result, description)
|
260
|
+
@debug_listener.semantic_predicate( result, description )
|
261
261
|
return result
|
262
262
|
end
|
263
263
|
|
264
|
-
def in_alternative(alt_number)
|
265
|
-
@debug_listener.enter_alternative(alt_number)
|
264
|
+
def in_alternative( alt_number )
|
265
|
+
@debug_listener.enter_alternative( alt_number )
|
266
266
|
end
|
267
267
|
|
268
|
-
def in_subrule(decision_number)
|
269
|
-
@debug_listener.enter_subrule(decision_number)
|
268
|
+
def in_subrule( decision_number )
|
269
|
+
@debug_listener.enter_subrule( decision_number )
|
270
270
|
yield
|
271
271
|
ensure
|
272
|
-
@debug_listener.exit_subrule(decision_number)
|
272
|
+
@debug_listener.exit_subrule( decision_number )
|
273
273
|
end
|
274
274
|
|
275
|
-
def in_decision(decision_number)
|
276
|
-
@debug_listener.enter_decision(decision_number)
|
275
|
+
def in_decision( decision_number )
|
276
|
+
@debug_listener.enter_decision( decision_number )
|
277
277
|
yield
|
278
278
|
ensure
|
279
|
-
@debug_listener.exit_decision(decision_number)
|
279
|
+
@debug_listener.exit_decision( decision_number )
|
280
280
|
end
|
281
281
|
end
|
282
282
|
|
@@ -290,14 +290,14 @@ not already a Debug::TokenStream.
|
|
290
290
|
=end
|
291
291
|
module TokenStream
|
292
292
|
|
293
|
-
def self.wrap(stream, debug_listener = nil)
|
294
|
-
stream.extend(self)
|
293
|
+
def self.wrap( stream, debug_listener = nil )
|
294
|
+
stream.extend( self )
|
295
295
|
stream.instance_eval do
|
296
296
|
@initial_stream_state = true
|
297
297
|
@debug_listener = debug_listener
|
298
298
|
@last_marker = nil
|
299
299
|
end
|
300
|
-
return(stream)
|
300
|
+
return( stream )
|
301
301
|
end
|
302
302
|
attr_reader :last_marker
|
303
303
|
attr_accessor :debug_listener
|
@@ -307,11 +307,11 @@ module TokenStream
|
|
307
307
|
a = index + 1 # the next position IF there are no hidden tokens in between
|
308
308
|
t = super
|
309
309
|
b = index # the actual position after consuming
|
310
|
-
@debug_listener.consume_token(t) if @debug_listener
|
310
|
+
@debug_listener.consume_token( t ) if @debug_listener
|
311
311
|
|
312
312
|
# if b > a, report the consumption of hidden tokens
|
313
313
|
for i in a...b
|
314
|
-
@debug_listener.consume_hidden_token at(i)
|
314
|
+
@debug_listener.consume_hidden_token at( i )
|
315
315
|
end
|
316
316
|
end
|
317
317
|
|
@@ -330,7 +330,7 @@ module TokenStream
|
|
330
330
|
def consume_initial_hidden_tokens
|
331
331
|
first_on_channel_token_index = self.index
|
332
332
|
first_on_channel_token_index.times do |index|
|
333
|
-
@debug_listener.consume_hidden_token at(index)
|
333
|
+
@debug_listener.consume_hidden_token at( index )
|
334
334
|
end
|
335
335
|
@initial_stream_state = false
|
336
336
|
end
|
@@ -341,20 +341,20 @@ module TokenStream
|
|
341
341
|
###################################### Stream Methods ######################################
|
342
342
|
############################################################################################
|
343
343
|
|
344
|
-
def look(steps = 1)
|
344
|
+
def look( steps = 1 )
|
345
345
|
@initial_stream_state and consume_initial_hidden_tokens
|
346
|
-
token = super(steps)
|
347
|
-
@debug_listener.look(steps, token)
|
346
|
+
token = super( steps )
|
347
|
+
@debug_listener.look( steps, token )
|
348
348
|
return token
|
349
349
|
end
|
350
350
|
|
351
|
-
def peek(steps = 1)
|
352
|
-
look(steps).type
|
351
|
+
def peek( steps = 1 )
|
352
|
+
look( steps ).type
|
353
353
|
end
|
354
354
|
|
355
355
|
def mark
|
356
356
|
@last_marker = super
|
357
|
-
@debug_listener.mark(@last_marker)
|
357
|
+
@debug_listener.mark( @last_marker )
|
358
358
|
return @last_marker
|
359
359
|
end
|
360
360
|
|
@@ -379,14 +379,14 @@ module EventListener
|
|
379
379
|
# The grammarFileName allows composite grammars to jump around among
|
380
380
|
# multiple grammar files.
|
381
381
|
|
382
|
-
def enter_rule(grammar_file, rule_name)
|
382
|
+
def enter_rule( grammar_file, rule_name )
|
383
383
|
# do nothing
|
384
384
|
end
|
385
385
|
|
386
386
|
# Because rules can have lots of alternatives, it is very useful to
|
387
387
|
# know which alt you are entering. This is 1..n for n alts.
|
388
388
|
|
389
|
-
def enter_alternative(alt)
|
389
|
+
def enter_alternative( alt )
|
390
390
|
# do nothing
|
391
391
|
end
|
392
392
|
|
@@ -397,7 +397,7 @@ module EventListener
|
|
397
397
|
# The grammarFileName allows composite grammars to jump around among
|
398
398
|
# multiple grammar files.
|
399
399
|
|
400
|
-
def exit_rule(grammar_file, rule_name)
|
400
|
+
def exit_rule( grammar_file, rule_name )
|
401
401
|
# do nothing
|
402
402
|
end
|
403
403
|
|
@@ -476,7 +476,7 @@ module EventListener
|
|
476
476
|
|
477
477
|
def backtrack( level )
|
478
478
|
begin_backtrack( level )
|
479
|
-
successful = yield(self)
|
479
|
+
successful = yield( self )
|
480
480
|
end_backtrack( level, successful )
|
481
481
|
end
|
482
482
|
|
@@ -567,7 +567,7 @@ module EventListener
|
|
567
567
|
|
568
568
|
def resync
|
569
569
|
begin_resync
|
570
|
-
yield(self)
|
570
|
+
yield( self )
|
571
571
|
end_resync
|
572
572
|
end
|
573
573
|
|
@@ -670,16 +670,16 @@ module EventListener
|
|
670
670
|
# do nothing
|
671
671
|
end
|
672
672
|
|
673
|
-
def examine_rule_memoization(rule)
|
673
|
+
def examine_rule_memoization( rule )
|
674
674
|
# do nothing
|
675
675
|
end
|
676
676
|
|
677
|
-
def on(event_name, &block)
|
677
|
+
def on( event_name, &block )
|
678
678
|
sclass = class << self; self; end
|
679
|
-
sclass.send(:define_method, event_name, &block)
|
679
|
+
sclass.send( :define_method, event_name, &block )
|
680
680
|
end
|
681
681
|
|
682
|
-
EVENTS = [
|
682
|
+
EVENTS = [
|
683
683
|
:add_child, :backtrack, :become_root, :begin_backtrack,
|
684
684
|
:begin_resync, :commence, :consume_hidden_token,
|
685
685
|
:consume_node, :consume_token, :create_node, :end_backtrack,
|