-
-
Save igorw/1f827076a066276fb820 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function tokenize($edn) { | |
$factory = new UsingPregReplace(new LexerDataGenerator()); | |
$lexer = $factory->createLexer(array( | |
'nil|true|false' => 'literal', | |
'"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"' => 'string', | |
'[\s,]' => 'whitespace', | |
'\\\\[a-z]+' => 'character', | |
get_symbol_regex() => 'symbol', | |
':(?:'.get_symbol_regex().')' => 'keyword', | |
'(?:[+-]?)(?:[0-9]+)N?' => 'int', | |
'(?:[+-]?)(?:[0-9]+\.[0-9]+)M?' => 'float', | |
'\\(' => 'list_start', | |
'\\)' => 'list_end', | |
)); | |
$tokens = $lexer->lex($edn); | |
return $tokens; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment