Class: Clef::Parser::LilypondLexer
- Inherits:
-
Object
- Object
- Clef::Parser::LilypondLexer
- Defined in:
- lib/clef/parser/lilypond_lexer.rb
Defined Under Namespace
Classes: Token
Constant Summary collapse
- TOKEN_REGEX =
/ \\[a-zA-Z]+ | << | >> | \{\} | \{ | \} | <[^>]+>\d*\.*~? | [a-g](?:isis|eses|is|es)?[',]*\d*\.*~? | r\d*\.* | -- | -> | -\. | [~()\[\]|] /mx
Instance Method Summary collapse
Instance Method Details
#tokenize(input) ⇒ Array<String>
33 34 35 |
# File 'lib/clef/parser/lilypond_lexer.rb', line 33 def tokenize(input) tokenize_with_locations(input).map(&:value) end |
#tokenize_with_locations(input) ⇒ Array<Token>
39 40 41 42 43 44 45 46 |
# File 'lib/clef/parser/lilypond_lexer.rb', line 39 def tokenize_with_locations(input) sanitized = strip_comments(input) sanitized.enum_for(:scan, TOKEN_REGEX).map do value = Regexp.last_match[0] line, column = location_for(sanitized, Regexp.last_match.begin(0)) Token.new(value: value, line: line, column: column) end end |