Class: Ibex::Frontend::TokenAdapter::DeclarationState

Inherits:
Object
  • Object
show all
Includes:
DeclarationDocumentState, DeclarationLexerState
Defined in:
lib/ibex/frontend/token_adapter/declaration_state.rb,
sig/ibex/frontend/token_adapter/declaration_state.rbs

Overview

Classifies tokens through the class header and declaration section. rubocop:disable Metrics/ClassLength, Metrics/CyclomaticComplexity One state machine owns declaration-boundary classification.

Constant Summary collapse

DECLARATIONS =

Returns:

  • (Hash[String, [ external_token, Symbol ]])
{
  "include" => %i[INCLUDE include_path],
  "import" => %i[IMPORT include_path],
  "token" => %i[TOKEN token_symbols], "options" => %i[OPTIONS options_identifiers],
  "expect" => %i[EXPECT expect_integer], "start" => %i[START start_first_symbol],
  "expect_rr" => %i[EXPECT_RR expect_rr_integer],
  "recover" => %i[RECOVER recover_kind],
  "on_error_reduce" => %i[ON_ERROR_REDUCE on_error_reduce_first_symbol],
  "test" => %i[TEST test_expectation],
  "lexer" => %i[LEXER lexer_entries],
  "convert" => %i[CONVERT convert_name], "pragma" => %i[PRAGMA pragma_value],
  "display" => %i[DISPLAY display_symbol], "type" => %i[TYPE type_symbol],
  "param" => %i[PARAM param_name],
  "printer" => %i[PRINTER printer_symbol],
  "parser" => %i[PARSER parser_key],
  "rule" => %i[RULE rules]
}.freeze
ASSOCIATIONS =

Signature:

  • Hash[String, [external_token, Symbol]]

Returns:

  • (Hash[String, external_token])
{
  "left" => :LEFT, "right" => :RIGHT, "nonassoc" => :NONASSOC, "precedence" => :PRECEDENCE
}.freeze
SCALAR_TYPES =

Signature:

  • Hash[String, external_token]

Returns:

  • (Hash[Symbol, external_token])
{
  literal: :LITERAL, regexp: :REGEXP, integer: :INTEGER, action: :ACTION, user_code: :USER_CODE
}.freeze
EXPECTATIONS =

Signature:

  • Hash[Symbol, external_token]

Returns:

  • (Hash[Symbol, String])
{
  class_keyword: "class", class_name: "identifier", superclass_name: "identifier",
  expect_integer: "integer", expect_rr_integer: "integer",
  start_first_symbol: "a grammar symbol", start_symbols: "a grammar symbol",
  include_path: "a double-quoted relative path",
  display_symbol: "a grammar symbol", type_symbol: "a grammar symbol",
  display_value: "a quoted string", type_value: "a quoted string",
  param_name: "an identifier", param_type: "a quoted type or declaration",
  printer_symbol: "a grammar symbol", printer_action: "an action",
  recover_kind: "sync", recovery_colon: ":", recovery_first_symbol: "a grammar symbol",
  recovery_symbols: "a grammar symbol", on_error_reduce_first_symbol: "a grammar symbol",
  on_error_reduce_symbols: "a grammar symbol", test_expectation: "accept or reject",
  test_source: "a double-quoted string",
  lexer_entries: "a lexer rule, state, or end", lexer_state_name: "a state name",
  lexer_state_do: "do", lexer_pattern: "a regular expression or quoted literal",
  lexer_action_or_entry: "an action, lexer rule, state, or end",
  parser_key: "a parser setting or end", parser_value: "a parser setting value"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DeclarationLexerState

#begin_lexer_entry, #classify_lexer_identifier, #classify_lexer_scalar, #finish_lexer_scope, #lexer_declaration_state?

Methods included from DeclarationDocumentState

#class_keyword, #classify_include, #reject_fragment_pragma

Constructor Details

#initialize(extended: false) ⇒ DeclarationState

Returns a new instance of DeclarationState.

RBS:

  • (?extended: bool) -> void

Parameters:

  • extended: (Boolean) (defaults to: false)


68
69
70
71
72
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 68

def initialize(extended: false)
  @extended_mode = extended
  @pragmas = {} #: Hash[String, Location]
  @state = :class_keyword
end

Instance Attribute Details

#conversion_nameToken? (readonly)

Signature:

  • Hash[Symbol, String]

Returns:



57
58
59
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 57

def conversion_name
  @conversion_name
end

#declarationSymbol? (readonly)

Signature:

  • Symbol?

Returns:

  • (Symbol, nil)


58
59
60
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 58

def declaration
  @declaration
end

#precedence_closerString? (readonly)

Signature:

  • String?

Returns:

  • (String, nil)


59
60
61
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 59

def precedence_closer
  @precedence_closer
end

#stateSymbol (readonly)

Signature:

  • Symbol

Returns:

  • (Symbol)


60
61
62
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 60

def state
  @state
end

Instance Method Details

#begin_conversion(token, type, remaining) ⇒ external_token

RBS:

  • (Token token, external_token type, Array[Token] remaining) -> external_token

Parameters:

  • token (Token)
  • type (external_token)
  • remaining (Array[Token])

Returns:

  • (external_token)


268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 268

def begin_conversion(token, type, remaining)
  if token.type == :identifier && token.value == "end"
    @state = :declaration
    @declaration = nil
    return :END
  end

  validate_conversion_line(token, remaining)
  @conversion_name = token
  @state = :convert_expression
  type
end

#begin_declaration(token) ⇒ external_token

RBS:

  • (Token token) -> external_token

Parameters:

Returns:

  • (external_token)


189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 189

def begin_declaration(token)
  value = string_value(token)
  return begin_precedence(token) if %w[prechigh preclow].include?(value)

  reject_fragment_pragma(token, value)

  terminal, next_state = DECLARATIONS[value]
  return :IDENTIFIER unless terminal

  @pragma_location = token.location if terminal == :PRAGMA
  @token_alias_candidate = nil
  @state = next_state
  @declaration = value.to_sym unless terminal == :RULE
  @declaration = nil if terminal == :RULE
  terminal
end

#begin_metadata_value(type) ⇒ external_token

RBS:

  • (external_token type) -> external_token

Parameters:

  • type (external_token)

Returns:

  • (external_token)


384
385
386
387
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 384

def (type)
  @state = @state == :display_symbol ? :display_value : :type_value
  type
end

#begin_param_typeexternal_token

RBS:

  • () -> external_token

Returns:

  • (external_token)


390
391
392
393
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 390

def begin_param_type
  @state = :param_type
  :IDENTIFIER
end

#begin_parser_setting(token) ⇒ external_token

RBS:

  • (Token token) -> external_token

Parameters:

Returns:

  • (external_token)


156
157
158
159
160
161
162
163
164
165
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 156

def begin_parser_setting(token)
  if string_value(token) == "end"
    @state = :declaration
    @declaration = nil
    return :END
  end

  @state = :parser_value
  :IDENTIFIER
end

#begin_precedence(token) ⇒ external_token

RBS:

  • (Token token) -> external_token

Parameters:

Returns:

  • (external_token)


222
223
224
225
226
227
228
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 222

def begin_precedence(token)
  high_to_low = string_value(token) == "prechigh"
  @precedence_closer = high_to_low ? "preclow" : "prechigh"
  @declaration = :precedence
  @state = :precedence_association
  high_to_low ? :PRECHIGH : :PRECLOW
end

#begin_printer_action(type) ⇒ external_token

RBS:

  • (external_token type) -> external_token

Parameters:

  • type (external_token)

Returns:

  • (external_token)


396
397
398
399
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 396

def begin_printer_action(type)
  @state = :printer_action
  type
end

#begin_recovery_colon(_token) ⇒ external_token

RBS:

  • (Token token) -> external_token

Parameters:

Returns:

  • (external_token)


402
403
404
405
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 402

def begin_recovery_colon(_token)
  @state = :recovery_colon
  :IDENTIFIER
end

#begin_test_source(_token) ⇒ external_token

RBS:

  • (Token token) -> external_token

Parameters:

Returns:

  • (external_token)


408
409
410
411
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 408

def begin_test_source(_token)
  @state = :test_source
  :IDENTIFIER
end

#classify(token, remaining) ⇒ external_token

RBS:

  • (Token token, Array[Token] remaining) -> external_token

Parameters:

Returns:

  • (external_token)


75
76
77
78
79
80
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 75

def classify(token, remaining)
  return classify_identifier(token, remaining) if token.type == :identifier
  return classify_scalar(token, remaining) if SCALAR_TYPES.key?(token.type)

  classify_punctuation(token)
end

#classify_conversion(token, type, remaining) ⇒ external_token?

RBS:

  • (Token token, external_token type, Array[Token] remaining) -> external_token?

Parameters:

  • token (Token)
  • type (external_token)
  • remaining (Array[Token])

Returns:

  • (external_token, nil)


351
352
353
354
355
356
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 351

def classify_conversion(token, type, remaining)
  return unless type == :LITERAL
  return begin_conversion(token, type, remaining) if @state == :convert_name

  finish_conversion(type) if @state == :convert_expression
end

#classify_grammar_test(type) ⇒ external_token?

RBS:

  • (external_token type) -> external_token?

Parameters:

  • type (external_token)

Returns:

  • (external_token, nil)


342
343
344
345
346
347
348
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 342

def classify_grammar_test(type)
  return unless @state == :test_source && type == :LITERAL

  @state = :declaration
  @declaration = nil
  type
end

#classify_identifier(token, remaining) ⇒ external_token

RBS:

  • (Token token, Array[Token] remaining) -> external_token

Parameters:

Returns:

  • (external_token)


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 126

def classify_identifier(token, remaining)
  return classify_lexer_identifier(token) if lexer_declaration_state?

  case @state
  when :class_keyword then class_keyword(token)
  when :class_name, :superclass_name then constant_name(remaining)
  when :declaration, :param_type then begin_declaration(token)
  when :token_symbols
    @token_alias_candidate = token
    declaration_symbol(token)
  when :options_identifiers, :start_symbols, :recovery_symbols, :on_error_reduce_symbols
    declaration_symbol(token)
  when :precedence_association, :precedence_symbols then precedence_identifier(token)
  when :start_first_symbol then continue_start_symbols(:IDENTIFIER)
  when :display_symbol, :type_symbol then (:IDENTIFIER)
  when :param_name then begin_param_type
  when :printer_symbol then begin_printer_action(:IDENTIFIER)
  when :recover_kind then begin_recovery_colon(token)
  when :recovery_first_symbol then continue_recovery_symbols(:IDENTIFIER)
  when :on_error_reduce_first_symbol then continue_on_error_reduce_symbols(:IDENTIFIER)
  when :test_expectation then begin_test_source(token)
  when :pragma_value then finish_pragma(token)
  when :convert_name then begin_conversion(token, :IDENTIFIER, remaining)
  when :parser_key then begin_parser_setting(token)
  when :parser_value then finish_parser_setting
  else :IDENTIFIER
  end
end

#classify_metadata(type) ⇒ external_token?

RBS:

  • (external_token type) -> external_token?

Parameters:

  • type (external_token)

Returns:

  • (external_token, nil)


323
324
325
326
327
328
329
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 323

def (type)
  return unless type == :LITERAL
  return (type) if %i[display_symbol type_symbol].include?(@state)
  return finish_param_type(type) if @state == :param_type

  (type) if %i[display_value type_value].include?(@state)
end

#classify_printer(type) ⇒ external_token?

RBS:

  • (external_token type) -> external_token?

Parameters:

  • type (external_token)

Returns:

  • (external_token, nil)


332
333
334
335
336
337
338
339
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 332

def classify_printer(type)
  return begin_printer_action(type) if @state == :printer_symbol && type == :LITERAL
  return unless @state == :printer_action && type == :ACTION

  @state = :declaration
  @declaration = nil
  type
end

#classify_punctuation(token) ⇒ external_token

RBS:

  • (Token token) -> external_token

Parameters:

Returns:

  • (external_token)


435
436
437
438
439
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 435

def classify_punctuation(token)
  @state = :superclass_name if @state == :superclass_marker && token.type == :<
  @state = :recovery_first_symbol if @state == :recovery_colon && token.type == :":"
  string_value(token)
end

#classify_scalar(token, remaining) ⇒ external_token

RBS:

  • (Token token, Array[Token] remaining) -> external_token

Parameters:

Returns:

  • (external_token)


282
283
284
285
286
287
288
289
290
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 282

def classify_scalar(token, remaining)
  type = SCALAR_TYPES.fetch(token.type)
  classified = classify_lexer_scalar(type) ||
               classify_token_alias(token, type) || classify_include(type) || classify_single_symbol(type) ||
               (type) || classify_printer(type) || classify_grammar_test(type) ||
               classify_conversion(token, type, remaining)

  classified || type
end

#classify_single_symbol(type) ⇒ external_token?

RBS:

  • (external_token type) -> external_token?

Parameters:

  • type (external_token)

Returns:

  • (external_token, nil)


293
294
295
296
297
298
299
300
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 293

def classify_single_symbol(type)
  return finish_single_symbol(type) if %i[expect_integer expect_rr_integer].include?(@state) && type == :INTEGER

  first = continue_first_symbol(type)
  return first if first

  type if @state == :start_symbols && type == :LITERAL
end

#classify_token_alias(token, type) ⇒ external_token?

RBS:

  • (Token token, external_token type) -> external_token?

Parameters:

  • token (Token)
  • type (external_token)

Returns:

  • (external_token, nil)


312
313
314
315
316
317
318
319
320
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 312

def classify_token_alias(token, type)
  candidate = @token_alias_candidate
  return unless extended_features? && @state == :token_symbols &&
                type == :LITERAL && candidate
  return unless candidate.location.line == token.location.line

  @token_alias_candidate = nil
  :TOKEN_ALIAS
end

#constant_name(remaining) ⇒ external_token

RBS:

  • (Array[Token] remaining) -> external_token

Parameters:

  • remaining (Array[Token])

Returns:

  • (external_token)


174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 174

def constant_name(remaining)
  following = remaining.first
  raise Ibex::Error, "unexpected end of token stream" unless following

  @state = if following.type == :scope
             @state
           elsif following.type == :<
             :superclass_marker
           else
             :declaration
           end
  :IDENTIFIER
end

#continue_first_symbol(type) ⇒ external_token?

RBS:

  • (external_token type) -> external_token?

Parameters:

  • type (external_token)

Returns:

  • (external_token, nil)


303
304
305
306
307
308
309
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 303

def continue_first_symbol(type)
  return unless type == :LITERAL
  return continue_start_symbols(type) if @state == :start_first_symbol
  return continue_recovery_symbols(type) if @state == :recovery_first_symbol

  continue_on_error_reduce_symbols(type) if @state == :on_error_reduce_first_symbol
end

#continue_on_error_reduce_symbols(type) ⇒ external_token

RBS:

  • (external_token type) -> external_token

Parameters:

  • type (external_token)

Returns:

  • (external_token)


378
379
380
381
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 378

def continue_on_error_reduce_symbols(type)
  @state = :on_error_reduce_symbols
  type
end

#continue_recovery_symbols(type) ⇒ external_token

RBS:

  • (external_token type) -> external_token

Parameters:

  • type (external_token)

Returns:

  • (external_token)


372
373
374
375
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 372

def continue_recovery_symbols(type)
  @state = :recovery_symbols
  type
end

#continue_start_symbols(type) ⇒ external_token

RBS:

  • (external_token type) -> external_token

Parameters:

  • type (external_token)

Returns:

  • (external_token)


366
367
368
369
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 366

def continue_start_symbols(type)
  @state = :start_symbols
  type
end

#cst_pragma?Boolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


93
94
95
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 93

def cst_pragma?
  @pragmas.key?("cst")
end

#cst_pragma_locationLocation?

RBS:

  • () -> Location?

Returns:



103
104
105
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 103

def cst_pragma_location
  @pragmas["cst"]
end

#declaration_boundary?(value) ⇒ Boolean

RBS:

  • (String value) -> bool

Parameters:

  • value (String)

Returns:

  • (Boolean)


238
239
240
241
242
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 238

def declaration_boundary?(value)
  return false if %w[display type param printer].include?(value) && !extended_features?

  DECLARATIONS.key?(value) || %w[prechigh preclow].include?(value)
end

#declaration_symbol(token) ⇒ external_token

RBS:

  • (Token token) -> external_token

Parameters:

Returns:

  • (external_token)


231
232
233
234
235
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 231

def declaration_symbol(token)
  return begin_declaration(token) if declaration_boundary?(string_value(token))

  :IDENTIFIER
end

#expectation(token) ⇒ String?

RBS:

  • (Token? token) -> String?

Parameters:

Returns:

  • (String, nil)


108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 108

def expectation(token)
  return "identifier" if @state == :pragma_value && token&.type != :identifier

  expected = EXPECTATIONS[@state]
  return expected if expected

  if @declaration == :precedence
    precedence_expectation(token)
  elsif @declaration == :convert
    "end"
  elsif @state == :declaration
    token&.type == :eof ? "rule" : "a declaration or rule"
  end
end

#extended_features?Boolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


245
246
247
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 245

def extended_features?
  @extended_mode || extended_pragma? || cst_pragma?
end

#extended_pragma?Boolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


88
89
90
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 88

def extended_pragma?
  @pragmas.key?("extended")
end

#extended_pragma_locationLocation?

RBS:

  • () -> Location?

Returns:



98
99
100
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 98

def extended_pragma_location
  @pragmas["extended"]
end

#finish_conversion(type) ⇒ external_token

RBS:

  • (external_token type) -> external_token

Parameters:

  • type (external_token)

Returns:

  • (external_token)


428
429
430
431
432
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 428

def finish_conversion(type)
  @state = :convert_name
  @conversion_name = nil
  type
end

#finish_metadata_value(type) ⇒ external_token

RBS:

  • (external_token type) -> external_token

Parameters:

  • type (external_token)

Returns:

  • (external_token)


421
422
423
424
425
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 421

def (type)
  @state = :declaration
  @declaration = nil
  type
end

#finish_param_type(type) ⇒ external_token

RBS:

  • (external_token type) -> external_token

Parameters:

  • type (external_token)

Returns:

  • (external_token)


414
415
416
417
418
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 414

def finish_param_type(type)
  @state = :declaration
  @declaration = nil
  type
end

#finish_parser_settingexternal_token

RBS:

  • () -> external_token

Returns:

  • (external_token)


168
169
170
171
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 168

def finish_parser_setting
  @state = :parser_key
  :IDENTIFIER
end

#finish_pragma(token) ⇒ external_token

RBS:

  • (Token token) -> external_token

Parameters:

Returns:

  • (external_token)


207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 207

def finish_pragma(token)
  value = string_value(token)
  raise Ibex::Error, "#{token.location}: unknown pragma #{value}" unless %w[extended cst].include?(value)

  location = @pragma_location || token.location
  raise Ibex::Error, "#{location}: duplicate pragma #{value}" if @pragmas[value]

  @pragmas[value] = location
  @pragma_location = nil
  @state = :declaration
  @declaration = nil
  :IDENTIFIER
end

#finish_precedence(token) ⇒ external_token

RBS:

  • (Token token) -> external_token

Parameters:

Returns:

  • (external_token)


260
261
262
263
264
265
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 260

def finish_precedence(token)
  @state = :declaration
  @declaration = nil
  @precedence_closer = nil
  string_value(token) == "prechigh" ? :PRECHIGH : :PRECLOW
end

#finish_single_symbol(type) ⇒ external_token

RBS:

  • (external_token type) -> external_token

Parameters:

  • type (external_token)

Returns:

  • (external_token)


359
360
361
362
363
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 359

def finish_single_symbol(type)
  @state = :declaration
  @declaration = nil
  type
end

#precedence_expectation(token) ⇒ String?

RBS:

  • (Token? token) -> String?

Parameters:

Returns:

  • (String, nil)


453
454
455
456
457
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 453

def precedence_expectation(token)
  return @precedence_closer if token&.type == :eof

  "left or right or nonassoc or precedence" if @state == :precedence_association
end

#precedence_identifier(token) ⇒ external_token

RBS:

  • (Token token) -> external_token

Parameters:

Returns:

  • (external_token)


250
251
252
253
254
255
256
257
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 250

def precedence_identifier(token)
  value = string_value(token)
  return finish_precedence(token) if value == @precedence_closer

  association = ASSOCIATIONS[value]
  @state = :precedence_symbols if association
  association || :IDENTIFIER
end

#rules?Boolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


83
84
85
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 83

def rules?
  @state == :rules
end

#string_value(token) ⇒ String

RBS:

  • (Token token) -> String

Parameters:

Returns:

  • (String)


460
461
462
463
464
465
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 460

def string_value(token)
  value = token.value
  return value if value.is_a?(String)

  raise Ibex::Error, "#{token.location}: expected text token"
end

#validate_conversion_line(name, remaining) ⇒ void

This method returns an undefined value.

RBS:

  • (Token name, Array[Token] remaining) -> void

Parameters:



442
443
444
445
446
447
448
449
450
# File 'lib/ibex/frontend/token_adapter/declaration_state.rb', line 442

def validate_conversion_line(name, remaining)
  line = name.location.line
  rest = remaining.take_while do |token|
    token.type != :eof && token.location.line == line && !(token.type == :identifier && token.value == "end")
  end
  return if rest.length == 1 && rest.first.type == :literal

  raise Ibex::Error, "#{name.location}: expected a quoted Ruby conversion expression"
end