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
collapse
- GRAMMAR_TYPES =
%w(lexer parser tree combined)
- TYPE_TO_CLASS =
{
'lexer' => 'Lexer',
'parser' => 'Parser',
'tree' => 'TreeParser'
}
- CLASS_TO_TYPE =
TYPE_TO_CLASS.invert
DependantFile::GLOBAL_DEPENDENCIES
Instance Attribute Summary collapse
#force, #path
Class Method Summary
collapse
Instance Method Summary
collapse
#dependencies, #depends_on, #stale?
Constructor Details
#initialize(path, options = {}) {|_self| ... } ⇒ Grammar
CONSTRUCTOR #############################################
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/antlr3/test/grammar.rb', line 60
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
#name ⇒ Object
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
74
75
76
|
# File 'lib/antlr3/test/grammar.rb', line 74
def name
@name
end
|
#output_directory ⇒ Object
Returns the value of attribute output_directory.
75
76
77
|
# File 'lib/antlr3/test/grammar.rb', line 75
def output_directory
@output_directory
end
|
#source ⇒ Object
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
74
75
76
|
# File 'lib/antlr3/test/grammar.rb', line 74
def source
@source
end
|
#type ⇒ Object
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
74
75
76
|
# File 'lib/antlr3/test/grammar.rb', line 74
def type
@type
end
|
#verbose ⇒ Object
Returns the value of attribute verbose.
75
76
77
|
# File 'lib/antlr3/test/grammar.rb', line 75
def verbose
@verbose
end
|
Class Method Details
.global_dependency(path) ⇒ Object
47
48
49
50
51
|
# File 'lib/antlr3/test/grammar.rb', line 47
def self.global_dependency( path )
path = File.expand_path path.to_s
GLOBAL_DEPENDENCIES << path if test( ?f, path )
return path
end
|
.inline(source, *args) ⇒ Object
53
54
55
|
# File 'lib/antlr3/test/grammar.rb', line 53
def self.inline( source, *args )
InlineGrammar.new( source, *args )
end
|
Instance Method Details
#clean! ⇒ Object
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/antlr3/test/grammar.rb', line 184
def clean!
deleted = []
for target in target_files
if test( ?f, target )
File.delete( target )
deleted << target
end
end
return deleted
end
|
#combined? ⇒ Boolean
131
132
133
|
# File 'lib/antlr3/test/grammar.rb', line 131
def combined?
@type == "combined"
end
|
#compile(options = {}) ⇒ Object
COMMAND METHODS ############################################
161
162
163
164
165
|
# File 'lib/antlr3/test/grammar.rb', line 161
def compile( options = {} )
if options[ :force ] or stale?
compile!( options )
end
end
|
#compile!(options = {}) ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/antlr3/test/grammar.rb', line 167
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
|
#has_lexer? ⇒ Boolean
109
110
111
|
# File 'lib/antlr3/test/grammar.rb', line 109
def has_lexer?
@type == 'combined' || @type == 'lexer'
end
|
#has_parser? ⇒ Boolean
113
114
115
|
# File 'lib/antlr3/test/grammar.rb', line 113
def has_parser?
@type == 'combined' || @type == 'parser'
end
|
#imported_target_files ⇒ Object
152
153
154
155
156
|
# File 'lib/antlr3/test/grammar.rb', line 152
def imported_target_files
imports.map! do |delegate|
output_directory / "#{ @name }_#{ delegate }.rb"
end
end
|
#imports ⇒ Object
147
148
149
150
|
# File 'lib/antlr3/test/grammar.rb', line 147
def imports
@source.scan( /^\s*import\s+(\w+)\s*;/ ).
tap { |list| list.flatten! }
end
|
#inspect ⇒ Object
195
196
197
|
# File 'lib/antlr3/test/grammar.rb', line 195
def inspect
sprintf( "grammar %s (%s)", @name, @path )
end
|
#lexer? ⇒ Boolean
117
118
119
|
# File 'lib/antlr3/test/grammar.rb', line 117
def lexer?
@type == "lexer"
end
|
#lexer_class_name ⇒ Object
77
78
79
|
# File 'lib/antlr3/test/grammar.rb', line 77
def lexer_class_name
self.name + "::Lexer"
end
|
#lexer_file_name ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/antlr3/test/grammar.rb', line 81
def lexer_file_name
if lexer? then base = name
elsif combined? then base = name + 'Lexer'
else return( nil )
end
return( base + '.rb' )
end
|
#parser? ⇒ Boolean
121
122
123
|
# File 'lib/antlr3/test/grammar.rb', line 121
def parser?
@type == "parser"
end
|
#parser_class_name ⇒ Object
89
90
91
|
# File 'lib/antlr3/test/grammar.rb', line 89
def parser_class_name
name + "::Parser"
end
|
#parser_file_name ⇒ Object
93
94
95
96
97
98
99
|
# File 'lib/antlr3/test/grammar.rb', line 93
def parser_file_name
if parser? then base = name
elsif combined? then base = name + 'Parser'
else return( nil )
end
return( base + '.rb' )
end
|
#target_files(include_imports = true) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/antlr3/test/grammar.rb', line 135
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
|
#tree? ⇒ Boolean
Also known as:
has_tree?
125
126
127
|
# File 'lib/antlr3/test/grammar.rb', line 125
def tree?
@type == "tree"
end
|
#tree_parser_class_name ⇒ Object
101
102
103
|
# File 'lib/antlr3/test/grammar.rb', line 101
def tree_parser_class_name
name + "::TreeParser"
end
|
#tree_parser_file_name ⇒ Object
105
106
107
|
# File 'lib/antlr3/test/grammar.rb', line 105
def tree_parser_file_name
tree? and name + '.rb'
end
|