Class: RubyLex

Inherits:
Object show all
Defined in:
lib/openc3/utilities/ruby_lex_utils.rb,
lib/openc3/utilities/ruby_lex_utils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#code_block_openObject

Returns the value of attribute code_block_open.



35
36
37
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 35

def code_block_open
  @code_block_open
end

#continueObject

Returns the value of attribute continue.



38
39
40
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 38

def continue
  @continue
end

#exp_line_noInteger

Returns The expression line number. This can differ from the actual line number due to white space and Ruby control keywords.

Returns:

  • (Integer)

    The expression line number. This can differ from the actual line number due to white space and Ruby control keywords.



281
282
283
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 281

def exp_line_no
  @exp_line_no
end

#indentObject

Returns the value of attribute indent.



31
32
33
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 31

def indent
  @indent
end

#lineObject

Returns the value of attribute line.



37
38
39
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 37

def line
  @line
end

#line_noObject

Returns the value of attribute line_no.



32
33
34
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 32

def line_no
  @line_no
end

#ltypeObject

Returns the value of attribute ltype.



36
37
38
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 36

def ltype
  @ltype
end

#tokensObject

Returns the value of attribute tokens.



34
35
36
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 34

def tokens
  @tokens
end

Instance Method Details

#identify_string_dvarObject

Monkey patch to keep this from looping forever if the string never is closed with a right brace



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 307

def identify_string_dvar
  getc

  reserve_continue = @continue
  reserve_ltype = @ltype
  reserve_indent = @indent
  reserve_indent_stack = @indent_stack
  reserve_state = @lex_state
  reserve_quoted = @quoted

  @ltype = nil
  @quoted = nil
  @indent = 0
  @indent_stack = []
  @lex_state = EXPR_BEG

  loop do
    @continue = false
    prompt
    tk = token
    break if tk.nil? # This is the patch
    if @ltype or @continue or @indent >= 0
      next
    end
    break if tk.kind_of?(TkRBRACE)
  end
ensure
  @continue = reserve_continue
  @ltype = reserve_ltype
  @indent = reserve_indent
  @indent_stack = reserve_indent_stack
  @lex_state = reserve_state
  @quoted = reserve_quoted
end

#reinitializeObject

Resets the RubyLex in preparation of parsing a line



284
285
286
287
288
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 284

def reinitialize
  @line_no = 1
  @prompt = nil
  initialize_input()
end