Module: CSVPlusPlus::Lexer

Defined in:
lib/csv_plus_plus/lexer/lexer.rb,
lib/csv_plus_plus/lexer.rb,
lib/csv_plus_plus/lexer/tokenizer.rb

Overview

Common methods to be mixed into our Racc parsers

Defined Under Namespace

Classes: Tokenizer

Constant Summary collapse

END_OF_CODE_SECTION =
'---'
VARIABLE_REF =
'$$'

Instance Method Summary collapse

Instance Method Details

#initializeObject

initialize



7
8
9
# File 'lib/csv_plus_plus/lexer/lexer.rb', line 7

def initialize
  @tokens = []
end

#next_tokenObject

Used by racc to iterate each token



12
13
14
# File 'lib/csv_plus_plus/lexer/lexer.rb', line 12

def next_token
  @tokens.shift
end

#parse(input, runtime) ⇒ Object

parse



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/csv_plus_plus/lexer/lexer.rb', line 17

def parse(input, runtime)
  return if input.nil?

  return return_value unless anything_to_parse?(input)

  tokenize(input, runtime)
  do_parse
  return_value
rescue ::Racc::ParseError => e
  runtime.raise_syntax_error("Error parsing #{parse_subject}", e.message, wrapped_error: e)
end