Class: Lrama::Symbol
- Inherits:
-
Struct
- Object
- Struct
- Lrama::Symbol
- Defined in:
- lib/lrama/grammar.rb
Overview
Symbol is both of nterm and term ‘number` is both for nterm and term `token_id` is tokentype for term, internal sequence number for nterm
TODO: Add validation for ASCII code range for Token::Char
Instance Attribute Summary collapse
-
#accept_symbol ⇒ Object
writeonly
Sets the attribute accept_symbol.
-
#alias_name ⇒ Object
Returns the value of attribute alias_name.
-
#eof_symbol ⇒ Object
writeonly
Sets the attribute eof_symbol.
-
#error_symbol ⇒ Object
writeonly
Sets the attribute error_symbol.
-
#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
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
- #nterm? ⇒ Boolean
- #term? ⇒ Boolean
- #undef_symbol? ⇒ Boolean
Instance Attribute Details
#accept_symbol=(value) ⇒ Object (writeonly)
Sets the attribute accept_symbol
45 46 47 |
# File 'lib/lrama/grammar.rb', line 45 def accept_symbol=(value) @accept_symbol = value end |
#alias_name ⇒ Object
Returns the value of attribute alias_name
44 45 46 |
# File 'lib/lrama/grammar.rb', line 44 def alias_name @alias_name end |
#eof_symbol=(value) ⇒ Object (writeonly)
Sets the attribute eof_symbol
45 46 47 |
# File 'lib/lrama/grammar.rb', line 45 def eof_symbol=(value) @eof_symbol = value end |
#error_symbol=(value) ⇒ Object (writeonly)
Sets the attribute error_symbol
45 46 47 |
# File 'lib/lrama/grammar.rb', line 45 def error_symbol=(value) @error_symbol = value end |
#id ⇒ Object
Returns the value of attribute id
44 45 46 |
# File 'lib/lrama/grammar.rb', line 44 def id @id end |
#nullable ⇒ Object
Returns the value of attribute nullable
44 45 46 |
# File 'lib/lrama/grammar.rb', line 44 def nullable @nullable end |
#number ⇒ Object
Returns the value of attribute number
44 45 46 |
# File 'lib/lrama/grammar.rb', line 44 def number @number end |
#precedence ⇒ Object
Returns the value of attribute precedence
44 45 46 |
# File 'lib/lrama/grammar.rb', line 44 def precedence @precedence end |
#printer ⇒ Object
Returns the value of attribute printer
44 45 46 |
# File 'lib/lrama/grammar.rb', line 44 def printer @printer end |
#tag ⇒ Object
Returns the value of attribute tag
44 45 46 |
# File 'lib/lrama/grammar.rb', line 44 def tag @tag end |
#term ⇒ Object
Returns the value of attribute term
44 45 46 |
# File 'lib/lrama/grammar.rb', line 44 def term @term end |
#token_id ⇒ Object
Returns the value of attribute token_id
44 45 46 |
# File 'lib/lrama/grammar.rb', line 44 def token_id @token_id end |
#undef_symbol=(value) ⇒ Object (writeonly)
Sets the attribute undef_symbol
45 46 47 |
# File 'lib/lrama/grammar.rb', line 45 def undef_symbol=(value) @undef_symbol = value end |
Instance Method Details
#accept_symbol? ⇒ Boolean
67 68 69 |
# File 'lib/lrama/grammar.rb', line 67 def accept_symbol? !!@accept_symbol end |
#comment ⇒ Object
comment for yysymbol_kind_t
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/lrama/grammar.rb', line 108 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
71 72 73 74 75 76 77 |
# File 'lib/lrama/grammar.rb', line 71 def display_name if alias_name alias_name else id.s_value end end |
#enum_name ⇒ Object
name for yysymbol_kind_t
See: b4_symbol_kind_base
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/lrama/grammar.rb', line 82 def enum_name case when accept_symbol? name = "YYACCEPT" when eof_symbol? name = "YYEOF" when term? && id.type == Token::Char if alias_name name = number.to_s + alias_name else name = number.to_s + id.s_value end when term? && id.type == 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(/[^a-zA-Z_0-9]+/, "_") end |
#eof_symbol? ⇒ Boolean
55 56 57 |
# File 'lib/lrama/grammar.rb', line 55 def eof_symbol? !!@eof_symbol end |
#error_symbol? ⇒ Boolean
59 60 61 |
# File 'lib/lrama/grammar.rb', line 59 def error_symbol? !!@error_symbol end |
#nterm? ⇒ Boolean
51 52 53 |
# File 'lib/lrama/grammar.rb', line 51 def nterm? !term end |
#term? ⇒ Boolean
47 48 49 |
# File 'lib/lrama/grammar.rb', line 47 def term? term end |
#undef_symbol? ⇒ Boolean
63 64 65 |
# File 'lib/lrama/grammar.rb', line 63 def undef_symbol? !!@undef_symbol end |