Skip to content

Instantly share code, notes, and snippets.

@igorw
Created March 13, 2013 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorw/1f827076a066276fb820 to your computer and use it in GitHub Desktop.
Save igorw/1f827076a066276fb820 to your computer and use it in GitHub Desktop.
<?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