Class: Babelyoda::StringsLexer
- Inherits:
-
Object
- Object
- Babelyoda::StringsLexer
- Defined in:
- lib/babelyoda/strings_lexer.rb
Constant Summary collapse
- TOKENS =
[ :multiline_comment, :singleline_comment, :string, :equal_sign, :semicolon, :space ].freeze
- REGEXP =
Regexp.new("/\\*\\s*(.*?)\\s*\\*/|\\s*(//.*?\n)|\"((?:\\\\?+.)*?)\"|(\\s*=\\s*)|(\\s*;\\s*)|(\\s*)", Regexp::MULTILINE)
Instance Method Summary collapse
Instance Method Details
#lex(str) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/babelyoda/strings_lexer.rb', line 6 def lex(str) str.scan(REGEXP).each do |m| idx = m.index { |x| x } if TOKENS[idx] == :space next end yield TOKENS[idx], m[idx] end end |