Class: Lrama::Grammar::Symbol
- Inherits:
-
Object
- Object
- Lrama::Grammar::Symbol
- Defined in:
- lib/lrama/grammar/symbol.rb
Instance Attribute Summary collapse
-
#accept_symbol ⇒ Object
writeonly
: bool.
-
#alias_name ⇒ Object
: String?.
-
#destructor ⇒ Object
: Destructor?.
-
#eof_symbol ⇒ Object
writeonly
: bool.
-
#error_symbol ⇒ Object
writeonly
: bool.
-
#error_token ⇒ Object
: ErrorToken.
-
#first_set ⇒ Object
: Set.
-
#first_set_bitmap ⇒ Object
: Bitmap::bitmap.
-
#id ⇒ Object
: Lexer::Token::Base.
-
#nullable ⇒ Object
: bool.
-
#number ⇒ Object
: Integer.
-
#number_bitmap ⇒ Object
: Bitmap::bitmap.
-
#precedence ⇒ Object
: Precedence?.
-
#printer ⇒ Object
: Printer?.
-
#tag ⇒ Object
: Lexer::Token::Tag?.
-
#term ⇒ Object
readonly
: bool.
-
#token_id ⇒ Object
: Integer.
-
#undef_symbol ⇒ Object
writeonly
: bool.
Instance Method Summary collapse
- #accept_symbol? ⇒ Boolean
-
#comment ⇒ Object
comment for yysymbol_kind_t.
- #display_name ⇒ Object
-
#enum_name ⇒ Object
name for yysymbol_kind_t.
- #eof_symbol? ⇒ Boolean
- #error_symbol? ⇒ Boolean
-
#initialize(id:, term:, alias_name: nil, number: nil, tag: nil, token_id: nil, nullable: nil, precedence: nil, printer: nil, destructor: nil) ⇒ Symbol
constructor
A new instance of Symbol.
- #midrule? ⇒ Boolean
- #name ⇒ Object
- #nterm? ⇒ Boolean
- #term? ⇒ Boolean
- #undef_symbol? ⇒ Boolean
Constructor Details
#initialize(id:, term:, alias_name: nil, number: nil, tag: nil, token_id: nil, nullable: nil, precedence: nil, printer: nil, destructor: nil) ⇒ Symbol
Returns a new instance of Symbol.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lrama/grammar/symbol.rb', line 33 def initialize(id:, term:, alias_name: nil, number: nil, tag: nil, token_id: nil, nullable: nil, precedence: nil, printer: nil, destructor: nil) @id = id @alias_name = alias_name @number = number @tag = tag @term = term @token_id = token_id @nullable = nullable @precedence = precedence @printer = printer @destructor = destructor end |
Instance Attribute Details
#accept_symbol=(value) ⇒ Object (writeonly)
: bool
29 30 31 |
# File 'lib/lrama/grammar/symbol.rb', line 29 def accept_symbol=(value) @accept_symbol = value end |
#alias_name ⇒ Object
: String?
13 14 15 |
# File 'lib/lrama/grammar/symbol.rb', line 13 def alias_name @alias_name end |
#destructor ⇒ Object
: Destructor?
21 22 23 |
# File 'lib/lrama/grammar/symbol.rb', line 21 def destructor @destructor end |
#eof_symbol=(value) ⇒ Object (writeonly)
: bool
26 27 28 |
# File 'lib/lrama/grammar/symbol.rb', line 26 def eof_symbol=(value) @eof_symbol = value end |
#error_symbol=(value) ⇒ Object (writeonly)
: bool
27 28 29 |
# File 'lib/lrama/grammar/symbol.rb', line 27 def error_symbol=(value) @error_symbol = value end |
#error_token ⇒ Object
: ErrorToken
22 23 24 |
# File 'lib/lrama/grammar/symbol.rb', line 22 def error_token @error_token end |
#first_set ⇒ Object
: Set
23 24 25 |
# File 'lib/lrama/grammar/symbol.rb', line 23 def first_set @first_set end |
#first_set_bitmap ⇒ Object
: Bitmap::bitmap
24 25 26 |
# File 'lib/lrama/grammar/symbol.rb', line 24 def first_set_bitmap @first_set_bitmap end |
#id ⇒ Object
: Lexer::Token::Base
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def id @id end |
#nullable ⇒ Object
: bool
18 19 20 |
# File 'lib/lrama/grammar/symbol.rb', line 18 def nullable @nullable end |
#number ⇒ Object
: Integer
14 15 16 |
# File 'lib/lrama/grammar/symbol.rb', line 14 def number @number end |
#number_bitmap ⇒ Object
: Bitmap::bitmap
15 16 17 |
# File 'lib/lrama/grammar/symbol.rb', line 15 def number_bitmap @number_bitmap end |
#precedence ⇒ Object
: Precedence?
19 20 21 |
# File 'lib/lrama/grammar/symbol.rb', line 19 def precedence @precedence end |
#printer ⇒ Object
: Printer?
20 21 22 |
# File 'lib/lrama/grammar/symbol.rb', line 20 def printer @printer end |
#tag ⇒ Object
: Lexer::Token::Tag?
16 17 18 |
# File 'lib/lrama/grammar/symbol.rb', line 16 def tag @tag end |
#term ⇒ Object (readonly)
: bool
25 26 27 |
# File 'lib/lrama/grammar/symbol.rb', line 25 def term @term end |
#token_id ⇒ Object
: Integer
17 18 19 |
# File 'lib/lrama/grammar/symbol.rb', line 17 def token_id @token_id end |
#undef_symbol=(value) ⇒ Object (writeonly)
: bool
28 29 30 |
# File 'lib/lrama/grammar/symbol.rb', line 28 def undef_symbol=(value) @undef_symbol = value end |
Instance Method Details
#accept_symbol? ⇒ Boolean
78 79 80 |
# File 'lib/lrama/grammar/symbol.rb', line 78 def accept_symbol? !!@accept_symbol end |
#comment ⇒ Object
comment for yysymbol_kind_t
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/lrama/grammar/symbol.rb', line 128 def comment case when accept_symbol? # YYSYMBOL_YYACCEPT name when eof_symbol? # YYEOF alias_name when (term? && 0 < token_id && token_id < 128) # YYSYMBOL_3_backslash_, YYSYMBOL_14_ display_name when midrule? # YYSYMBOL_21_1 name else # YYSYMBOL_keyword_class, YYSYMBOL_strings_1 display_name end end |
#display_name ⇒ Object
95 96 97 |
# File 'lib/lrama/grammar/symbol.rb', line 95 def display_name alias_name || name end |
#enum_name ⇒ Object
name for yysymbol_kind_t
See: b4_symbol_kind_base
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/lrama/grammar/symbol.rb', line 104 def enum_name case when accept_symbol? res = "YYACCEPT" when eof_symbol? res = "YYEOF" when term? && id.is_a?(Lrama::Lexer::Token::Char) res = number.to_s + display_name when term? && id.is_a?(Lrama::Lexer::Token::Ident) res = name when midrule? res = number.to_s + name when nterm? res = name else raise "Unexpected #{self}" end "YYSYMBOL_" + res.gsub(/\W+/, "_") end |
#eof_symbol? ⇒ Boolean
63 64 65 |
# File 'lib/lrama/grammar/symbol.rb', line 63 def eof_symbol? !!@eof_symbol end |
#error_symbol? ⇒ Boolean
68 69 70 |
# File 'lib/lrama/grammar/symbol.rb', line 68 def error_symbol? !!@error_symbol end |
#midrule? ⇒ Boolean
83 84 85 86 87 |
# File 'lib/lrama/grammar/symbol.rb', line 83 def midrule? return false if term? name.include?("$") || name.include?("@") end |
#name ⇒ Object
90 91 92 |
# File 'lib/lrama/grammar/symbol.rb', line 90 def name id.s_value end |
#nterm? ⇒ Boolean
58 59 60 |
# File 'lib/lrama/grammar/symbol.rb', line 58 def nterm? !term end |
#term? ⇒ Boolean
53 54 55 |
# File 'lib/lrama/grammar/symbol.rb', line 53 def term? term end |
#undef_symbol? ⇒ Boolean
73 74 75 |
# File 'lib/lrama/grammar/symbol.rb', line 73 def undef_symbol? !!@undef_symbol end |