Beispiel #1
0
    public function __construct()
    {
        parent::__construct(new \JMS\Parser\SimpleLexer('/
                # PHP Class Names
                ((?:[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*\\\\)*[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)

                # Strings
                |("(?:[^"]|"")*"|\'(?:[^\']|\'\')*\')

                # Ignore whitespace
                |\\s*

                # Terminals
                |(.)
            /x', array(self::T_NAME => 'T_NAME', self::T_STRING => 'T_STRING', self::T_OPEN_BRACKET => 'T_OPEN_BRACKET', self::T_CLOSE_BRACKET => 'T_CLOSE_BRACKET', self::T_COMMA => 'T_COMMA', self::T_NONE => 'T_NONE'), function ($value) {
            switch ($value[0]) {
                case '"':
                case "'":
                    return array(TypeParser::T_STRING, substr($value, 1, -1));
                case '<':
                    return array(TypeParser::T_OPEN_BRACKET, '<');
                case '>':
                    return array(TypeParser::T_CLOSE_BRACKET, '>');
                case ',':
                    return array(TypeParser::T_COMMA, ',');
                default:
                    if (preg_match('/^(?:[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*\\\\)*[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$/', $value)) {
                        return array(TypeParser::T_NAME, $value);
                    }
                    return array(TypeParser::T_NONE, $value);
            }
        }));
    }
Beispiel #2
0
 public function parse($str, $context = null)
 {
     try {
         return parent::parse($str, $context);
     } catch (\Exception $e) {
         throw new ParserException('Parsing failed: ' . $e->getMessage(), 0, $e);
     }
 }
 /**
  * Parses the message and returns the tokens.
  *
  * The result is an array of tokens.
  * Each token is an array that consists of the token type as
  * first value and the message part as second value.
  * The token type is always one of the MessageLexer::TOKEN_* or
  * MessageParser::TOKEN_* constants.
  *
  * @param string $message
  * @param string|null $context
  * @return array<array<string>> The message tokens.
  */
 public function parse($message, $context = null)
 {
     if (strpos($message, '{') === false) {
         // Message does not contain any declarations, therefore, we can avoid
         // the parsing process.
         return array(array(MessageLexer::TOKEN_TEXT, $message));
     }
     return parent::parse($message, $context);
 }
 public function __construct()
 {
     parent::__construct(new ExpressionLexer());
 }
 public function __construct(TypeRegistry $registry)
 {
     parent::__construct(new TypeLexer());
     $this->registry = $registry;
 }