Class: Lrama::Grammar::Symbol

Inherits:
Object
  • Object
show all
Defined in:
lib/lrama/grammar/symbol.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute accept_symbol to.



15
16
17
# File 'lib/lrama/grammar/symbol.rb', line 15

def accept_symbol=(value)
  @accept_symbol = value
end

#alias_nameObject

Returns the value of attribute alias_name.



12
13
14
# File 'lib/lrama/grammar/symbol.rb', line 12

def alias_name
  @alias_name
end

#destructorObject

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

Parameters:

  • value

    the value to set the attribute eof_symbol to.



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

Parameters:

  • value

    the value to set the attribute error_symbol to.



15
16
17
# File 'lib/lrama/grammar/symbol.rb', line 15

def error_symbol=(value)
  @error_symbol = value
end

#error_tokenObject

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_setObject

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_bitmapObject

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

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/lrama/grammar/symbol.rb', line 12

def id
  @id
end

#nullableObject

Returns the value of attribute nullable.



12
13
14
# File 'lib/lrama/grammar/symbol.rb', line 12

def nullable
  @nullable
end

#numberObject

Returns the value of attribute number.



12
13
14
# File 'lib/lrama/grammar/symbol.rb', line 12

def number
  @number
end

#precedenceObject

Returns the value of attribute precedence.



12
13
14
# File 'lib/lrama/grammar/symbol.rb', line 12

def precedence
  @precedence
end

#printerObject

Returns the value of attribute printer.



12
13
14
# File 'lib/lrama/grammar/symbol.rb', line 12

def printer
  @printer
end

#tagObject

Returns the value of attribute tag.



12
13
14
# File 'lib/lrama/grammar/symbol.rb', line 12

def tag
  @tag
end

#termObject (readonly)

Returns the value of attribute term.



14
15
16
# File 'lib/lrama/grammar/symbol.rb', line 14

def term
  @term
end

#token_idObject

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

Parameters:

  • value

    the value to set the attribute undef_symbol to.



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

Returns:

  • (Boolean)


50
51
52
# File 'lib/lrama/grammar/symbol.rb', line 50

def accept_symbol?
  !!@accept_symbol
end

#commentObject

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_nameObject



54
55
56
# File 'lib/lrama/grammar/symbol.rb', line 54

def display_name
  alias_name || id.s_value
end

#enum_nameObject

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

Returns:

  • (Boolean)


38
39
40
# File 'lib/lrama/grammar/symbol.rb', line 38

def eof_symbol?
  !!@eof_symbol
end

#error_symbol?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/lrama/grammar/symbol.rb', line 42

def error_symbol?
  !!@error_symbol
end

#nterm?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/lrama/grammar/symbol.rb', line 34

def nterm?
  !term
end

#term?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/lrama/grammar/symbol.rb', line 30

def term?
  term
end

#undef_symbol?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/lrama/grammar/symbol.rb', line 46

def undef_symbol?
  !!@undef_symbol
end