Module: ANTLR3::Test::GrammarManager
Constant Summary
collapse
- DEFAULT_COMPILE_OPTIONS =
{}
Instance Attribute Summary
Attributes included from Location
#test_path
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from NameSpace
#import, #import_grammar_targets
Methods included from Location
#local_path, #output_directory, #test_directory, #test_group
Class Method Details
.add_default_compile_option(name, value) ⇒ Object
63
64
65
|
# File 'lib/antlr3/test/functional.rb', line 63
def add_default_compile_option( name, value )
DEFAULT_COMPILE_OPTIONS[ name ] = value
end
|
Instance Method Details
#compile(grammar, options = {}) ⇒ Object
134
135
136
137
138
|
# File 'lib/antlr3/test/functional.rb', line 134
def compile( grammar, options = {} )
grammar.compile( compile_options.merge( options ) )
import_grammar_targets( grammar )
return grammar
end
|
#compile_options(defaults = nil) ⇒ Object
128
129
130
131
132
|
# File 'lib/antlr3/test/functional.rb', line 128
def compile_options( defaults = nil )
@compile_options ||= DEFAULT_COMPILE_OPTIONS.clone
@compile_options.update( defaults ) if defaults
return @compile_options
end
|
#const_missing(name) ⇒ Object
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.
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/antlr3/test/functional.rb', line 81
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
|
#grammar_count ⇒ Object
106
107
108
|
# File 'lib/antlr3/test/functional.rb', line 106
def grammar_count
grammars.length
end
|
#grammars ⇒ Object
An index of grammar file objects created in the test class (defined inline or loaded from a file)
102
103
104
|
# File 'lib/antlr3/test/functional.rb', line 102
def grammars
@grammars ||= {}
end
|
#inline_grammar(source, options = {}) ⇒ Object
118
119
120
121
122
123
124
125
126
|
# File 'lib/antlr3/test/functional.rb', line 118
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
|
#load_grammar(name) ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/antlr3/test/functional.rb', line 110
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
|