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
Sets the attribute accept_symbol.
-
#alias_name ⇒ Object
Returns the value of attribute alias_name.
-
#destructor ⇒ Object
Returns the value of attribute destructor.
-
#eof_symbol ⇒ Object
writeonly
Sets the attribute eof_symbol.
-
#error_symbol ⇒ Object
writeonly
Sets the attribute error_symbol.
-
#error_token ⇒ Object
Returns the value of attribute error_token.
-
#first_set ⇒ Object
Returns the value of attribute first_set.
-
#first_set_bitmap ⇒ Object
Returns the value of attribute first_set_bitmap.
-
#id ⇒ Object
Returns the value of attribute id.
-
#nullable ⇒ Object
Returns the value of attribute nullable.
-
#number ⇒ Object
Returns the value of attribute number.
-
#precedence ⇒ Object
Returns the value of attribute precedence.
-
#printer ⇒ Object
Returns the value of attribute printer.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#term ⇒ Object
readonly
Returns the value of attribute term.
-
#token_id ⇒ Object
Returns the value of attribute token_id.
-
#undef_symbol ⇒ Object
writeonly
Sets the attribute undef_symbol.
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.
- #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.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lrama/grammar/symbol.rb', line 17 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)
Sets the attribute accept_symbol
15 16 17 |
# File 'lib/lrama/grammar/symbol.rb', line 15 def accept_symbol=(value) @accept_symbol = value end |
#alias_name ⇒ Object
Returns the value of attribute alias_name.
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def alias_name @alias_name end |
#destructor ⇒ Object
Returns the value of attribute destructor.
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def destructor @destructor end |
#eof_symbol=(value) ⇒ Object (writeonly)
Sets the attribute eof_symbol
15 16 17 |
# File 'lib/lrama/grammar/symbol.rb', line 15 def eof_symbol=(value) @eof_symbol = value end |
#error_symbol=(value) ⇒ Object (writeonly)
Sets the attribute error_symbol
15 16 17 |
# File 'lib/lrama/grammar/symbol.rb', line 15 def error_symbol=(value) @error_symbol = value end |
#error_token ⇒ Object
Returns the value of attribute error_token.
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def error_token @error_token end |
#first_set ⇒ Object
Returns the value of attribute first_set.
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def first_set @first_set end |
#first_set_bitmap ⇒ Object
Returns the value of attribute first_set_bitmap.
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def first_set_bitmap @first_set_bitmap end |
#id ⇒ Object
Returns the value of attribute id.
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def id @id end |
#nullable ⇒ Object
Returns the value of attribute nullable.
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def nullable @nullable end |
#number ⇒ Object
Returns the value of attribute number.
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def number @number end |
#precedence ⇒ Object
Returns the value of attribute precedence.
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def precedence @precedence end |
#printer ⇒ Object
Returns the value of attribute printer.
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def printer @printer end |
#tag ⇒ Object
Returns the value of attribute tag.
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def tag @tag end |
#term ⇒ Object (readonly)
Returns the value of attribute term.
14 15 16 |
# File 'lib/lrama/grammar/symbol.rb', line 14 def term @term end |
#token_id ⇒ Object
Returns the value of attribute token_id.
12 13 14 |
# File 'lib/lrama/grammar/symbol.rb', line 12 def token_id @token_id end |
#undef_symbol=(value) ⇒ Object (writeonly)
Sets the attribute undef_symbol
15 16 17 |
# File 'lib/lrama/grammar/symbol.rb', line 15 def undef_symbol=(value) @undef_symbol = value end |
Instance Method Details
#accept_symbol? ⇒ Boolean
50 51 52 |
# File 'lib/lrama/grammar/symbol.rb', line 50 def accept_symbol? !!@accept_symbol end |
#comment ⇒ Object
comment for yysymbol_kind_t
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/lrama/grammar/symbol.rb', line 84 def comment case when accept_symbol? # YYSYMBOL_YYACCEPT id.s_value when eof_symbol? # YYEOF alias_name when (term? && 0 < token_id && token_id < 128) # YYSYMBOL_3_backslash_, YYSYMBOL_14_ alias_name || id.s_value when id.s_value.include?("$") || id.s_value.include?("@") # YYSYMBOL_21_1 id.s_value else # YYSYMBOL_keyword_class, YYSYMBOL_strings_1 alias_name || id.s_value end end |
#display_name ⇒ Object
54 55 56 |
# File 'lib/lrama/grammar/symbol.rb', line 54 def display_name alias_name || id.s_value end |
#enum_name ⇒ Object
name for yysymbol_kind_t
See: b4_symbol_kind_base
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/lrama/grammar/symbol.rb', line 62 def enum_name case when accept_symbol? name = "YYACCEPT" when eof_symbol? name = "YYEOF" when term? && id.is_a?(Lrama::Lexer::Token::Char) name = number.to_s + display_name when term? && id.is_a?(Lrama::Lexer::Token::Ident) name = id.s_value when nterm? && (id.s_value.include?("$") || id.s_value.include?("@")) name = number.to_s + id.s_value when nterm? name = id.s_value else raise "Unexpected #{self}" end "YYSYMBOL_" + name.gsub(/\W+/, "_") end |
#eof_symbol? ⇒ Boolean
38 39 40 |
# File 'lib/lrama/grammar/symbol.rb', line 38 def eof_symbol? !!@eof_symbol end |
#error_symbol? ⇒ Boolean
42 43 44 |
# File 'lib/lrama/grammar/symbol.rb', line 42 def error_symbol? !!@error_symbol end |
#nterm? ⇒ Boolean
34 35 36 |
# File 'lib/lrama/grammar/symbol.rb', line 34 def nterm? !term end |
#term? ⇒ Boolean
30 31 32 |
# File 'lib/lrama/grammar/symbol.rb', line 30 def term? term end |
#undef_symbol? ⇒ Boolean
46 47 48 |
# File 'lib/lrama/grammar/symbol.rb', line 46 def undef_symbol? !!@undef_symbol end |