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.



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_nameObject

: String?



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

def alias_name
  @alias_name
end

#destructorObject

: 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_tokenObject

: ErrorToken



22
23
24
# File 'lib/lrama/grammar/symbol.rb', line 22

def error_token
  @error_token
end

#first_setObject

: Set



23
24
25
# File 'lib/lrama/grammar/symbol.rb', line 23

def first_set
  @first_set
end

#first_set_bitmapObject

: Bitmap::bitmap



24
25
26
# File 'lib/lrama/grammar/symbol.rb', line 24

def first_set_bitmap
  @first_set_bitmap
end

#idObject

: Lexer::Token::Base



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

def id
  @id
end

#nullableObject

: bool



18
19
20
# File 'lib/lrama/grammar/symbol.rb', line 18

def nullable
  @nullable
end

#numberObject

: Integer



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

def number
  @number
end

#number_bitmapObject

: Bitmap::bitmap



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

def number_bitmap
  @number_bitmap
end

#precedenceObject

: Precedence?



19
20
21
# File 'lib/lrama/grammar/symbol.rb', line 19

def precedence
  @precedence
end

#printerObject

: Printer?



20
21
22
# File 'lib/lrama/grammar/symbol.rb', line 20

def printer
  @printer
end

#tagObject

: Lexer::Token::Tag?



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

def tag
  @tag
end

#termObject (readonly)

: bool



25
26
27
# File 'lib/lrama/grammar/symbol.rb', line 25

def term
  @term
end

#token_idObject

: 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

Returns:

  • (Boolean)


78
79
80
# File 'lib/lrama/grammar/symbol.rb', line 78

def accept_symbol?
  !!@accept_symbol
end

#commentObject

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_nameObject



95
96
97
# File 'lib/lrama/grammar/symbol.rb', line 95

def display_name
  alias_name || name
end

#enum_nameObject

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

Returns:

  • (Boolean)


63
64
65
# File 'lib/lrama/grammar/symbol.rb', line 63

def eof_symbol?
  !!@eof_symbol
end

#error_symbol?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/lrama/grammar/symbol.rb', line 68

def error_symbol?
  !!@error_symbol
end

#midrule?Boolean

Returns:

  • (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

#nameObject



90
91
92
# File 'lib/lrama/grammar/symbol.rb', line 90

def name
  id.s_value
end

#nterm?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/lrama/grammar/symbol.rb', line 58

def nterm?
  !term
end

#term?Boolean

Returns:

  • (Boolean)


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

def term?
  term
end

#undef_symbol?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/lrama/grammar/symbol.rb', line 73

def undef_symbol?
  !!@undef_symbol
end