Class: Lrama::Symbol

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#accept_symbol=(value) ⇒ Object (writeonly)

Sets the attribute accept_symbol

Parameters:

  • value

    the value to set the attribute accept_symbol to.



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

def accept_symbol=(value)
  @accept_symbol = value
end

#alias_nameObject

Returns the value of attribute alias_name

Returns:

  • (Object)

    the current value of 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

Parameters:

  • value

    the value to set the attribute eof_symbol to.



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

Parameters:

  • value

    the value to set the attribute error_symbol to.



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

def error_symbol=(value)
  @error_symbol = value
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



44
45
46
# File 'lib/lrama/grammar.rb', line 44

def id
  @id
end

#nullableObject

Returns the value of attribute nullable

Returns:

  • (Object)

    the current value of nullable



44
45
46
# File 'lib/lrama/grammar.rb', line 44

def nullable
  @nullable
end

#numberObject

Returns the value of attribute number

Returns:

  • (Object)

    the current value of number



44
45
46
# File 'lib/lrama/grammar.rb', line 44

def number
  @number
end

#precedenceObject

Returns the value of attribute precedence

Returns:

  • (Object)

    the current value of precedence



44
45
46
# File 'lib/lrama/grammar.rb', line 44

def precedence
  @precedence
end

#printerObject

Returns the value of attribute printer

Returns:

  • (Object)

    the current value of printer



44
45
46
# File 'lib/lrama/grammar.rb', line 44

def printer
  @printer
end

#tagObject

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



44
45
46
# File 'lib/lrama/grammar.rb', line 44

def tag
  @tag
end

#termObject

Returns the value of attribute term

Returns:

  • (Object)

    the current value of term



44
45
46
# File 'lib/lrama/grammar.rb', line 44

def term
  @term
end

#token_idObject

Returns the value of attribute token_id

Returns:

  • (Object)

    the current value of 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

Parameters:

  • value

    the value to set the attribute undef_symbol to.



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

def undef_symbol=(value)
  @undef_symbol = value
end

Instance Method Details

#accept_symbol?Boolean

Returns:

  • (Boolean)


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

def accept_symbol?
  !!@accept_symbol
end

#commentObject

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_nameObject



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_nameObject

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

Returns:

  • (Boolean)


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

def eof_symbol?
  !!@eof_symbol
end

#error_symbol?Boolean

Returns:

  • (Boolean)


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

def error_symbol?
  !!@error_symbol
end

#nterm?Boolean

Returns:

  • (Boolean)


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

def nterm?
  !term
end

#term?Boolean

Returns:

  • (Boolean)


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

def term?
  term
end

#undef_symbol?Boolean

Returns:

  • (Boolean)


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

def undef_symbol?
  !!@undef_symbol
end