Class: ANTLR3::Test::Grammar
- Inherits:
-
Object
- Object
- ANTLR3::Test::Grammar
show all
- Includes:
- DependantFile
- Defined in:
- lib/antlr3/test/grammar.rb
Overview
Defined Under Namespace
Classes: CompilationFailure, FormatError, InlineGrammar
Constant Summary
- GRAMMAR_TYPES =
%w(lexer
- TYPE_TO_CLASS =
{
'lexer' => 'Lexer',
'parser' => 'Parser',
'tree' => 'TreeParser'
}
- CLASS_TO_TYPE =
TYPE_TO_CLASS.invert
DependantFile::GLOBAL_DEPENDENCIES
Instance Attribute Summary (collapse)
-
- (Object) name
readonly
################################################################ ######
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
################################################################.
-
- (Object) output_directory
Returns the value of attribute output_directory.
-
- (Object) source
readonly
################################################################ ######
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
################################################################.
-
- (Object) type
readonly
################################################################ ######
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
################################################################.
-
- (Object) verbose
Returns the value of attribute verbose.
#force, #path
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
#dependencies, #depends_on, #stale?
Constructor Details
- (Grammar) initialize(path, options = {}) {|_self| ... }
################################################################ ######
CONSTRUCTOR #############################################
################################################################
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/antlr3/test/grammar.rb', line 66
def initialize( path, options = {} )
@path = path.to_s
@source = File.read( @path )
@output_directory = options.fetch( :output_directory, '.' )
@verbose = options.fetch( :verbose, $VERBOSE )
study
build_dependencies
yield( self ) if block_given?
end
|
Instance Attribute Details
- (Object) name
################################################################ ######
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
################################################################
80
81
82
|
# File 'lib/antlr3/test/grammar.rb', line 80
def name
@name
end
|
- (Object) output_directory
Returns the value of attribute output_directory
81
82
83
|
# File 'lib/antlr3/test/grammar.rb', line 81
def output_directory
@output_directory
end
|
- (Object) source
################################################################ ######
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
################################################################
80
81
82
|
# File 'lib/antlr3/test/grammar.rb', line 80
def source
@source
end
|
- (Object) type
################################################################ ######
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
################################################################
80
81
82
|
# File 'lib/antlr3/test/grammar.rb', line 80
def type
@type
end
|
- (Object) verbose
Returns the value of attribute verbose
81
82
83
|
# File 'lib/antlr3/test/grammar.rb', line 81
def verbose
@verbose
end
|
Class Method Details
+ (Object) global_dependency(path)
53
54
55
56
57
|
# File 'lib/antlr3/test/grammar.rb', line 53
def self.global_dependency( path )
path = File.expand_path path.to_s
GLOBAL_DEPENDENCIES << path if test( ?f, path )
return path
end
|
+ (Object) inline(source, *args)
59
60
61
|
# File 'lib/antlr3/test/grammar.rb', line 59
def self.inline( source, *args )
InlineGrammar.new( source, *args )
end
|
Instance Method Details
- (Object) clean!
190
191
192
193
194
195
196
197
198
199
|
# File 'lib/antlr3/test/grammar.rb', line 190
def clean!
deleted = []
for target in target_files
if test( ?f, target )
File.delete( target )
deleted << target
end
end
return deleted
end
|
- (Boolean) combined?
137
138
139
|
# File 'lib/antlr3/test/grammar.rb', line 137
def combined?
@type == "combined"
end
|
- (Object) compile(options = {})
################################################################ ###
COMMAND METHODS ############################################
################################################################
167
168
169
170
171
|
# File 'lib/antlr3/test/grammar.rb', line 167
def compile( options = {} )
if options[ :force ] or stale?
compile!( options )
end
end
|
- (Object) compile!(options = {})
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/antlr3/test/grammar.rb', line 173
def compile!( options = {} )
command = build_command( options )
blab( command )
output = IO.popen( command ) do |pipe|
pipe.read
end
case status = $?.exitstatus
when 0, 130
post_compile( options )
else compilation_failure!( command, status, output )
end
return target_files
end
|
- (Boolean) has_lexer?
115
116
117
|
# File 'lib/antlr3/test/grammar.rb', line 115
def has_lexer?
@type == 'combined' || @type == 'lexer'
end
|
- (Boolean) has_parser?
119
120
121
|
# File 'lib/antlr3/test/grammar.rb', line 119
def has_parser?
@type == 'combined' || @type == 'parser'
end
|
- (Object) imported_target_files
158
159
160
161
162
|
# File 'lib/antlr3/test/grammar.rb', line 158
def imported_target_files
imports.map! do |delegate|
output_directory / "#{ @name }_#{ delegate }.rb"
end
end
|
- (Object) imports
153
154
155
156
|
# File 'lib/antlr3/test/grammar.rb', line 153
def imports
@source.scan( /^\s*import\s+(\w+)\s*;/ ).
tap { |list| list.flatten! }
end
|
- (Object) inspect
201
202
203
|
# File 'lib/antlr3/test/grammar.rb', line 201
def inspect
sprintf( "grammar %s (%s)", @name, @path )
end
|
- (Boolean) lexer?
123
124
125
|
# File 'lib/antlr3/test/grammar.rb', line 123
def lexer?
@type == "lexer"
end
|
- (Object) lexer_class_name
83
84
85
|
# File 'lib/antlr3/test/grammar.rb', line 83
def lexer_class_name
self.name + "::Lexer"
end
|
- (Object) lexer_file_name
87
88
89
90
91
92
93
|
# File 'lib/antlr3/test/grammar.rb', line 87
def lexer_file_name
if lexer? then base = name
elsif combined? then base = name + 'Lexer'
else return( nil )
end
return( base + '.rb' )
end
|
- (Boolean) parser?
127
128
129
|
# File 'lib/antlr3/test/grammar.rb', line 127
def parser?
@type == "parser"
end
|
- (Object) parser_class_name
95
96
97
|
# File 'lib/antlr3/test/grammar.rb', line 95
def parser_class_name
name + "::Parser"
end
|
- (Object) parser_file_name
99
100
101
102
103
104
105
|
# File 'lib/antlr3/test/grammar.rb', line 99
def parser_file_name
if parser? then base = name
elsif combined? then base = name + 'Parser'
else return( nil )
end
return( base + '.rb' )
end
|
- (Object) target_files(include_imports = true)
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/antlr3/test/grammar.rb', line 141
def target_files( include_imports = true )
targets = []
for target_type in %w(lexer parser tree_parser)
target_name = self.send( :#{ target_type }_file_name" ) and
targets.push( output_directory / target_name )
end
targets.concat( imported_target_files ) if include_imports
return targets
end
|
- (Boolean) tree?
Also known as:
has_tree?
131
132
133
|
# File 'lib/antlr3/test/grammar.rb', line 131
def tree?
@type == "tree"
end
|
- (Object) tree_parser_class_name
107
108
109
|
# File 'lib/antlr3/test/grammar.rb', line 107
def tree_parser_class_name
name + "::TreeParser"
end
|
- (Object) tree_parser_file_name
111
112
113
|
# File 'lib/antlr3/test/grammar.rb', line 111
def tree_parser_file_name
tree? and name + '.rb'
end
|