Class: RubyLex
Instance Attribute Summary collapse
-
#exp_line_no ⇒ Integer
The expression line number.
-
#indent ⇒ Object
Returns the value of attribute indent.
Instance Method Summary collapse
-
#get_readed ⇒ Object
Monkey patch to fix performance issue caused by call to reverse.
-
#reinitialize ⇒ Object
Resets the RubyLex in preparation of parsing a line.
-
#ungetc(c = nil) ⇒ Object
Monkey patch to fix performance issue caused by call to reverse.
Instance Attribute Details
#exp_line_no ⇒ Integer
Returns The expression line number. This can differ from the actual line number due to white space and Ruby control keywords.
24 25 26 |
# File 'lib/cosmos/utilities/ruby_lex_utils.rb', line 24 def exp_line_no @exp_line_no end |
#indent ⇒ Object
Returns the value of attribute indent.
20 21 22 |
# File 'lib/cosmos/utilities/ruby_lex_utils.rb', line 20 def indent @indent end |
Instance Method Details
#get_readed ⇒ Object
Monkey patch to fix performance issue caused by call to reverse
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/cosmos/utilities/ruby_lex_utils.rb', line 50 def get_readed if idx = @readed.rindex("\n") @base_char_no = @readed.size - (idx + 1) else @base_char_no += @readed.size end readed = @readed.join("") @readed = [] readed end |
#reinitialize ⇒ Object
Resets the RubyLex in preparation of parsing a line
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cosmos/utilities/ruby_lex_utils.rb', line 27 def reinitialize @seek = 0 @exp_line_no = 1 @line_no = 1 @base_char_no = 0 @char_no = 0 @rests.clear @readed.clear @here_readed.clear @indent = 0 @indent_stack.clear @lex_state = EXPR_BEG @space_seen = false @here_header = false @continue = false @line = '' @skip_space = false @readed_auto_clean_up = false @exception_on_syntax_error = true @prompt = nil end |
#ungetc(c = nil) ⇒ Object
Monkey patch to fix performance issue caused by call to reverse
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cosmos/utilities/ruby_lex_utils.rb', line 63 def ungetc(c = nil) if @here_readed.empty? c2 = @readed.pop else c2 = @here_readed.pop end c = c2 unless c @rests.unshift c #c = @seek -= 1 if c == "\n" @line_no -= 1 if idx = @readed.rindex("\n") @char_no = idx + 1 else @char_no = @base_char_no + @readed.size end else @char_no -= 1 end end |