Module: ANTLR3::Test::GrammarManager
- Includes:
- Location, NameSpace
- Included in:
- Functional
- Defined in:
- lib/antlr3/test/functional.rb
Constant Summary
- DEFAULT_COMPILE_OPTIONS =
{}
Instance Attribute Summary
Attributes included from Location
#test_path
Instance Method Summary
(collapse)
Methods included from NameSpace
#import, #import_grammar_targets
Methods included from Location
#local_path, #output_directory, #test_directory, #test_group
Instance Method Details
- (Object) add_default_compile_option(name, value)
62
63
64
|
# File 'lib/antlr3/test/functional.rb', line 62
def add_default_compile_option( name, value )
DEFAULT_COMPILE_OPTIONS[ name ] = value
end
|
- (Object) compile(grammar, options = {})
133
134
135
136
137
|
# File 'lib/antlr3/test/functional.rb', line 133
def compile( grammar, options = {} )
grammar.compile( compile_options.merge( options ) )
import_grammar_targets( grammar )
return grammar
end
|
- (Object) compile_options(defaults = nil)
127
128
129
130
131
|
# File 'lib/antlr3/test/functional.rb', line 127
def compile_options( defaults = nil )
@compile_options ||= DEFAULT_COMPILE_OPTIONS.clone
@compile_options.update( defaults ) if defaults
return @compile_options
end
|
- (Object) const_missing(name)
Compile and load inline grammars on demand when their constant name is
referenced in the code. This makes it easier to catch big errors quickly as
test cases are run, instead of waiting a few minutes for all grammars to
compile, and then discovering there's a big dumb error ruining most of
the grammars.
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/antlr3/test/functional.rb', line 80
def const_missing( name )
if g = grammars[ name.to_s ]
compile( g )
grammars.delete( name.to_s )
const_get( name )
elsif superclass.respond_to?( :grammars )
superclass.const_missing( name )
else
super
end
end
|
- (Object) grammar_count
105
106
107
|
# File 'lib/antlr3/test/functional.rb', line 105
def grammar_count
grammars.length
end
|
- (Object) grammars
An index of grammar file objects created in the test class (defined inline
or loaded from a file)
101
102
103
|
# File 'lib/antlr3/test/functional.rb', line 101
def grammars
@grammars ||= {}
end
|
- (Object) inline_grammar(source, options = {})
117
118
119
120
121
122
123
124
125
|
# File 'lib/antlr3/test/functional.rb', line 117
def inline_grammar( source, options = {} )
call = call_stack.find { |call| call.file != __FILE__ }
grammar = Grammar.inline source,
:output_directory => output_directory,
:file => ( call.file rescue nil ),
:line => ( call.line rescue nil )
register_grammar( grammar )
return grammar
end
|
- (Object) load_grammar(name)
109
110
111
112
113
114
115
|
# File 'lib/antlr3/test/functional.rb', line 109
def load_grammar( name )
path = local_path( name.to_s )
path =~ /\.g$/ or path << '.g'
grammar = Grammar.new( path, :output_directory => output_directory )
register_grammar( grammar )
return grammar
end
|