function tokenize($edn) { $factory = new UsingPregReplace(new LexerDataGenerator()); $delim = function ($pattern) { return "(?:{$pattern})(?=[\\s,\\)\\]\\};]|\$)"; }; $lexer = $factory->createLexer([';(?:.*)(?:\\n)?' => 'comment', '#_[\\s,]?' => 'discard', $delim('nil|true|false') => 'literal', $delim('"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"') => 'string', '[\\s,]' => 'whitespace', $delim('\\\\(?:newline|return|space|tab|formfeed|.)') => 'character', $delim('(?:[+-])?\\d+N?') => 'int', $delim('(?:[+-])?\\d+(\\.\\d+)?(?:[eE][-+]?\\d+)?M?') => 'float', $delim(get_symbol_regex()) => 'symbol', $delim(':(?:' . get_symbol_regex() . ')') => 'keyword', $delim('#(?:' . get_symbol_regex() . ')') => 'tag', '\\(' => 'list_start', '\\)' => 'list_end', '\\[' => 'vector_start', '\\]' => 'vector_end', '#\\{' => 'set_start', '\\{' => 'map_start', '\\}' => 'map_set_end']); $tokens = $lexer->lex($edn); return $tokens; }
/** * Initialize the initial context with the values of the passed properties. * * @param \AppserverIo\Properties\PropertiesInterface $properties The configuration properties */ public function __construct(PropertiesInterface $properties = null) { // initialize the default properties if no ones has been passed if ($properties == null) { // initialize the default properties $properties = new Properties(); foreach ($this->defaultProperties as $key => $value) { $properties->setProperty($key, $value); } } // inject the properties $this->injectProperties($properties); // create a factory for the lexer we use to parse the JNDI style bean names $factory = new UsingPregReplace(new LexerDataGenerator()); // create the lexer instance and inject it $this->injectLexer($factory->createLexer(array('php' => InitialContext::T_SCHEME, 'global\\/([a-zA-Z0-9_-]+)' => InitialContext::T_GLOBAL_SCOPE, 'app' => InitialContext::T_APPLICATION_SCOPE, '\\:' => InitialContext::T_COLON, '\\/' => InitialContext::T_SEPARATOR, 'local|remote' => InitialContext::T_INTERFACE, '\\w+' => InitialContext::T_CLASS))); }
public function __construct() { $factory = new UsingPregReplace(new LexerDataGenerator()); $this->lexer = $factory->createLexer($this->getConfig()); }
public function __construct() { $this->regexs = ['#[^\\r\\n]*' => self::T_COMMENT, '\\h+' => self::T_HORI_WHITESPACE, '<([^\\r\\n\\>]+) ([^\\r\\n\\>\\ ]*)?>' => self::T_NODE_OPEN, '<\\/([^\\r\\n\\>]+)>' => self::T_NODE_CLOSE, '\\\\\\h*\\r?\\n\\h*([^\\r\\n]+)' => self::T_CONTINUE_VARIABLE, '([a-zA-Z]+)\\h+([^\\r\\n]+)(?<!\\\\)' => self::T_VARIABLE, '\\r?\\n' => self::T_LINEBREAK]; $this->factory = new UsingPregReplace(new LexerDataGenerator()); $this->lexer = $this->factory->createLexer($this->regexs); }