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.



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

def code_block_open
  @code_block_open
end

#continueObject

Returns the value of attribute continue.



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

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.



278
279
280
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 278

def exp_line_no
  @exp_line_no
end

#indentObject

Returns the value of attribute indent.



28
29
30
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 28

def indent
  @indent
end

#lineObject

Returns the value of attribute line.



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

def line
  @line
end

#line_noObject

Returns the value of attribute line_no.



29
30
31
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 29

def line_no
  @line_no
end

#ltypeObject

Returns the value of attribute ltype.



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

def ltype
  @ltype
end

#tokensObject

Returns the value of attribute tokens.



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

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



304
305
306
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
# File 'lib/openc3/utilities/ruby_lex_utils.rb', line 304

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



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

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