Module: CSVPlusPlus::Lexer::RaccLexer
- Extended by:
- T::Generic, T::Helpers, T::Sig
- Includes:
- Kernel
- Defined in:
- lib/csv_plus_plus/lexer/racc_lexer.rb
Overview
Common methods to be mixed into the Racc parsers
Constant Summary collapse
- ReturnType =
type_member
Instance Attribute Summary collapse
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#initialize(tokens: []) ⇒ Object
Initialize a lexer instance with an empty @tokens.
-
#next_token ⇒ Array<(Regexp, Symbol) | (false, false)>
Used by racc to iterate each token.
-
#parse(input) ⇒ RaccLexer#Eachch instance will define it's own +return_value+ with the result of parsing
Orchestate the tokenizing, parsing and error handling of parsing input.
Instance Attribute Details
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
34 35 36 |
# File 'lib/csv_plus_plus/lexer/racc_lexer.rb', line 34 def tokens @tokens end |
Instance Method Details
#initialize(tokens: []) ⇒ Object
Initialize a lexer instance with an empty @tokens
38 39 40 |
# File 'lib/csv_plus_plus/lexer/racc_lexer.rb', line 38 def initialize(tokens: []) @tokens = ::T.let(tokens, ::T::Array[::CSVPlusPlus::Lexer::RaccToken]) end |
#next_token ⇒ Array<(Regexp, Symbol) | (false, false)>
Used by racc to iterate each token
46 47 48 |
# File 'lib/csv_plus_plus/lexer/racc_lexer.rb', line 46 def next_token @tokens.shift end |
#parse(input) ⇒ RaccLexer#Eachch instance will define it's own +return_value+ with the result of parsing
Orchestate the tokenizing, parsing and error handling of parsing input. Each instance will implement their own #tokenizer
method
rubocop:disable Metrics/MethodLength
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/csv_plus_plus/lexer/racc_lexer.rb', line 56 def parse(input) return return_value unless anything_to_parse?(input) tokenize(input) do_parse return_value rescue ::Racc::ParseError => e raise( ::CSVPlusPlus::Error::FormulaSyntaxError.new( "Error parsing #{parse_subject}", bad_input: e., wrapped_error: e ) ) end |