Class: Antelope::Generator::CHeader
- Inherits:
-
Base
- Object
- Base
- Antelope::Generator::CHeader
show all
- Defined in:
- lib/antelope/generator/c_header.rb
Constant Summary
Constants inherited
from Base
Base::Boolean
Instance Attribute Summary
Attributes inherited from Base
#file, #grammar, #mods
Instance Method Summary
collapse
Methods inherited from Base
directive, directives, inherited, #initialize, register_as, source_root, #template
#productions, #table
#coerce_directive_class, #coerce_directive_value, #coerce_nested_hash, #directives
Instance Method Details
#define_stype? ⇒ Boolean
20
21
22
|
# File 'lib/antelope/generator/c_header.rb', line 20
def define_stype?
!!directives.union[0] && !directives.api.value.type
end
|
#generate ⇒ Object
100
101
102
|
# File 'lib/antelope/generator/c_header.rb', line 100
def generate
template "c_header", "#{file}.h"
end
|
#guard_name ⇒ Object
96
97
98
|
# File 'lib/antelope/generator/c_header.rb', line 96
def guard_name
"#{prefix.upcase}#{file.gsub(/[\W]/, "_").upcase}"
end
|
#lex_params ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/antelope/generator/c_header.rb', line 24
def lex_params
params = [directives.lex_param, directives.param].compact.
flatten
if params.any?
", " << params.join(", ")
else
""
end
end
|
#params ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/antelope/generator/c_header.rb', line 40
def params
if directives.param
directives.param.join(", ")
else
""
end
end
|
#parse_params ⇒ Object
35
36
37
38
|
# File 'lib/antelope/generator/c_header.rb', line 35
def parse_params
[directives.parse_param, directives.param].compact.flatten.
join(", ")
end
|
#prefix ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/antelope/generator/c_header.rb', line 76
def prefix
if directives.api.prefix
directives.api.prefix
else
"yy"
end
end
|
16
17
18
|
# File 'lib/antelope/generator/c_header.rb', line 16
def push?
directives.api.push_pull == "push"
end
|
#stype ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/antelope/generator/c_header.rb', line 48
def stype
prefix.upcase << if directives.api.value.type
directives.api.value.type
elsif directives.union.size > 1
directives.union[0]
else
"STYPE"
end
end
|
#symbols ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/antelope/generator/c_header.rb', line 88
def symbols
@_symbols ||= begin
sym = grammar.terminals.map(&:name) + grammar.nonterminals
nums = sym.each_with_index.map { |v, i| [v, i + 257] }
Hash[nums]
end
end
|
#terminal_type ⇒ Object
62
63
64
|
# File 'lib/antelope/generator/c_header.rb', line 62
def terminal_type
"int" end
|
#token_prefix ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/antelope/generator/c_header.rb', line 66
def token_prefix
if directives.api.token.prefix
directives.api.token.prefix
elsif directives.api.prefix
prefix.upcase
else
""
end
end
|
#union_body ⇒ Object
58
59
60
|
# File 'lib/antelope/generator/c_header.rb', line 58
def union_body
directives.union.last
end
|
#upper_prefix ⇒ Object
84
85
86
|
# File 'lib/antelope/generator/c_header.rb', line 84
def upper_prefix
prefix.upcase
end
|