Parse text.

@param string $text
@param mixed $context
@return string
420459
public function parse($text, $context = null)
    {
        $parser = $this->getParser($context);

        $this->events->dispatch(new Parsing($parser, $context, $text));

        return $parser->parse($text);
    }
877601
public function parse(string $text) : array
    {
        $index = 0;
        $items = Text::split($text, $this->separator);
        $array = [];
        try {
            foreach ($items as $item) {
                $array[] = $this->syntax->parse($item);
                $index += strlen($item) + 1;
            }
        } catch (ParseException $e) {
            $extra = [
                'type' => 'invalid-item',
                'item' => $item,
                'position' => $e->position()
            ];
            throw new ParseException($this, $text, $index + $e->position(),
                "Unable to parse the item '{$item}'", $extra, $e
            );
        }

        return $array;
    }
501495
public function read($text)
    {
        $payload = $this->getPayload($text);

        $handle = $this->getHandle();
        $handle->setUrl($payload->getServiceUrl());
        $handle->setOption(CURLOPT_RETURNTRANSFER, 1);
        $handle->setOption(CURLOPT_POST, true);

        $handle->setOption(CURLOPT_POSTFIELDS, $payload->getPayload());
        $handle->setOption(CURLOPT_HTTPHEADER, $payload->getHeaders());
        $handle->setOption(CURLOPT_SSL_VERIFYPEER, false);

        $response = $handle->execute();
        $this->setHeaders($handle->getInfo());
        return $response;
    }
97168
public static function parseAttributes($text)
    {
        $text = preg_replace("/[\x{00a0}\x{200b}]+/u", " ", $text);
        if (!preg_match_all(self::$attrPattern, $text, $matches, PREG_SET_ORDER)) {
            return array(ltrim($text));
        }
        $attr = array();
        foreach ($matches as $match) {
            if (!empty($match[1])) {
                $attr[strtolower($match[1])] = stripcslashes($match[2]);
            } elseif (!empty($match[3])) {
                $attr[strtolower($match[3])] = stripcslashes($match[4]);
            } elseif (!empty($match[5])) {
                $attr[strtolower($match[5])] = stripcslashes($match[6]);
            } elseif (isset($match[7]) && strlen($match[7])) {
                $attr[] = stripcslashes($match[7]);
            } elseif (isset($match[8])) {
                $attr[] = stripcslashes($match[8]);
            }
        }
        return (array)$attr;
    }
431750
public function w($text, $context = array())
    {
        $this->log->warn($text, $context);
        $this->emit(self::SIGNAL_WARNING_ENTERED);
    }
580921
public function parse(string $text) : bool
    {
        $lower = strtolower($text);
        if (! in_array($lower, array_merge(self::TRUE_VALUES, self::FALSE_VALUES)))
            throw new ParseException($this, $text, 0, self::PARSE_ERROR);
        return in_array($lower, self::TRUE_VALUES);
    }
548625
public function loadGrammar(string $text): Grammar
    {
        $this->symbols = [];
        $this->inline = [];
        $this->regexpMap = [];
        $this->defines = [];
        $this->whitespaces = [];
        $this->modifiers = null;

        try {
            /** @var Rule[] $rules */
            $rules = $this->parser->parse($text, $this->actions)->made();

            /** @var int[] $subject_rules_count */
            $subject_rules_count = [];
            /** @var int[] $inline_ref_count */
            $inline_ref_count = [];
            /** @var Rule[] $inline_ref_rule */
            $inline_ref_rule = [];

            $non_terminal_is_hidden = [];
            $hidden_non_terminals = [];

            foreach ($rules as $rule) {
                $subject = $rule->getSubject();
                $subject_name = $subject->getName();
                $subject_hidden = $subject->isHidden();

                // RegExp tokens cannot be non-terminals in the same time
                // since there is no anonymous RegExp terminals
                if (isset($this->regexpMap[$subject_name])) {
                    throw new GrammarException(
                        "Symbol `$subject_name` defined as non-terminal and as regexp terminal in the same time"
                    );
                }

                if (isset($non_terminal_is_hidden[$subject_name])) {
                    if ($subject_hidden !== $non_terminal_is_hidden[$subject_name]) {
                        throw new GrammarException(
                            "Symbol `$subject_name` defined both as hidden and as visible"
                        );
                    }
                } else {
                    $non_terminal_is_hidden[$subject_name] = $subject_hidden;
                }

                $subject_rules_count[$subject_name] = ($subject_rules_count[$subject_name] ?? 0) + 1;

                if ($subject_hidden) {
                    $hidden_non_terminals[$subject_name] = true;
                }

                foreach ($rule->getDefinition() as $symbol) {
                    $name = $symbol->getName();
                    if (isset($this->inline[$name])) {
                        $inline_ref_count[$name] = ($inline_ref_count[$name] ?? 0) + 1;

                        // it is needed in case of the only reference,
                        // so array of an subject is not needed
                        $inline_ref_rule[$name] = $rule;
                    }
                }
            }

            foreach ($hidden_non_terminals as $name => $_) {
                if (isset($this->symbols[$name][false])) {
                    $this->symbols[$name][false]->setIsHidden(true);
                }
            }

            // Convert non-terminals defined only once with inline tokens
            // `Subject: "inline"`
            // into fixed terminals
            $fixed = [];
            foreach ($inline_ref_count as $inline_token => $ref_count) {
                if (1 !== $ref_count) {
                    continue;
                }

                $rule = $inline_ref_rule[$inline_token];
                if (null === $rule->getTag() && 1 === count($rule->getDefinition())) {
                    $subject = $rule->getSubject();
                    $name = $subject->getName();

                    if (1 !== $subject_rules_count[$name]) {
                        continue;
                    }

                    // remove rule
                    $key = array_search($rule, $rules, true);
                    if (false !== $key) {
                        unset($rules[$key]);
                    }

                    // remove inline
                    unset($this->inline[$inline_token]);

                    // make terminal
                    $subject->setIsTerminal(true);
                    if (isset($this->symbols[$name][!$subject->isHidden()])) {
                        $this->symbols[$name][!$subject->isHidden()]->setIsTerminal(true);
                    }

                    $fixed[$name] = $inline_token;
                }
            }

            return new Grammar(
                $rules,
                $this->inline,
                $fixed,
                $this->regexpMap,
                $this->whitespaces,
                $this->defines,
                $this->modifiers ?? ''
            );
        } catch (UnknownCharacterException | UnexpectedInputAfterEndException | UnexpectedTokenException $e) {
            throw new GrammarException(
                'Cannot parse grammar: ' . $e->getMessage() . ' at offset ' . $e->getOffset(),
                0,
                $e
            );
        } catch (AbortedException $e) {
            for ($inner = $e; $inner; $inner = $inner->getPrevious()) {
                if ($inner instanceof GrammarException || $inner instanceof InternalException) {
                    throw $inner;
                }
            }
            throw new InternalException('Failure while parsing your grammar text', 0, $e);
        } finally {
            $this->symbols = null;
            $this->inline = null;
            $this->regexpMap = null;
            $this->defines = null;
            $this->whitespaces = null;
            $this->modifiers = null;
        }
    }
192316
public static function Parse( $text )
	{
		$text = CoreFuncs::NormalizeSpace( $text );

		// $x = "-2016-01-02T09:08:02.1234Z";
		// $x = "-2016-01-02";
		// $x = "-2016-01-02T09:08:02";
		// $x = "-2016-01-02T09:08";
		// $x = "-2016-01-02T09";
		$pattern = "^((?<time>(?<hour>[0-9]{1,2})(:(?<minute>[0-9]{1,2}))?(:(?<second>[0-9]{2,2}))?)(\.(?<micro>[0-9]+))?)?(?<offset>(?=[+\-a-zA-Z]).*)?$";

		$result = preg_match( "/$pattern/", $text, $matches );
		$error = empty( $text ) || ! $result ||
				( ! empty( $matches['offset'] ) && $matches['offset'] == $text ) ||
				( empty( $matches['minute'] ) && empty( $matches['second'] ) ) ||
				( ! empty( $matches['hour'] )   && ( $matches['hour'] > 24 ) ) ||
				( ! empty( $matches['minute'] ) && ( $matches['minute'] > 59 ) ) ||
				( ! empty( $matches['second'] ) && ( $matches['second'] > 59 ) ) ||
				( ! empty( $matches['offset'] ) && ! preg_match( "/^[+-]?\d+$|^[+-]?\d{2}:\d{2}$|^[a-z]+$/i", $matches['offset'] ) );

		if ( ! $error )
		{
			$timeSeconds = ( empty( $matches['hour'] ) ? 0 : $matches['hour'] * 3600 ) +
			( empty( $matches['minute'] ) ? 0 : $matches['minute'] * 60 ) +
			( empty( $matches['second'] ) ? 0 : $matches['second'] * 1 ) +
			( empty( $matches['micro'] ) ? 0 : $matches['micro'] / 1000 );
			$error = $timeSeconds > 86400;

			if ( ! $error && ! empty( $matches['offset'] ) && preg_match( "/^[+-](?<hours>\d{2})(:(?<minutes>\d{2}))?$/", $matches['offset'], $offsetMatches ) )
			{
				$error = ( ! empty( $offsetMatches['hours'] ) && $offsetMatches['hours'] > 14 ) ||
				empty( $offsetMatches['minutes'] ) ||
				$offsetMatches['minutes'] > 59;
			}
		}

		if ( $error )
		{
			throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::FORG0001, array( $text, "Date" ) );
		}

		$sign = empty( $matches['sign'] ) ? false : $matches['sign'] == "-" ;
		$date = empty( $matches['date'] ) ? "1970-01-01" : $matches['date'];
		$time = empty( $matches['time'] ) ? "" : $matches['time'];
		$offset = empty( $matches['offset'] ) ? "" : $matches['offset'];

		$microseconds = empty( $matches['micro'] ) ? 0 : $matches['micro'];
		$notlocal = ! empty( $matches['offset'] );

		$T = $date && $time ? "T" : "";

		/**
		 * @var DateTime $dateTime
		 */
		$dateTime = new \DateTime( "{$date}$T{$time}$offset" );
		$dateTime->microseconds = $microseconds;

		return new TimeValue( $dateTime, $notlocal );
	}
86167
private function tokenize($text)
    {
        $count = preg_match_all($this->lexerRegex, $text, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
        if(false === $count || preg_last_error() !== PREG_NO_ERROR) {
            throw new \RuntimeException(sprintf('PCRE failure `%s`.', preg_last_error()));
        }

        $tokens = array();
        $position = 0;

        foreach($matches as $match) {
            switch(true) {
                case -1 !== $match['string'][1]: { $token = $match['string'][0]; $type = self::TOKEN_STRING; break; }
                case -1 !== $match['ws'][1]: { $token = $match['ws'][0]; $type = self::TOKEN_WS; break; }
                case -1 !== $match['marker'][1]: { $token = $match['marker'][0]; $type = self::TOKEN_MARKER; break; }
                case -1 !== $match['delimiter'][1]: { $token = $match['delimiter'][0]; $type = self::TOKEN_DELIMITER; break; }
                case -1 !== $match['separator'][1]: { $token = $match['separator'][0]; $type = self::TOKEN_SEPARATOR; break; }
                case -1 !== $match['open'][1]: { $token = $match['open'][0]; $type = self::TOKEN_OPEN; break; }
                case -1 !== $match['close'][1]: { $token = $match['close'][0]; $type = self::TOKEN_CLOSE; break; }
                default: { throw new \RuntimeException(sprintf('Invalid token.')); }
            }
            $tokens[] = array($type, $token, $position);
            $position += mb_strlen($token, 'utf-8');
        }

        return $tokens;
    }
436504
public static function parse($text) {
    static $int_regex = <<<'EOF'
/^[+-]?(?:
  0
  | [1-9][0-9]*
  | 0[xX][0-9a-fA-F]+
  | 0[0-7]+
  | 0b[01]+
)$/x
EOF;
    static $decimal_regex = <<<EOF
/^[+-]?(?:
  [0-9]*\.[0-9]+ (?:[eE][+-]?[0-9]+)?
  | [0-9]+\.[0-9]* (?:[eE][+-]?[0-9]+)?
  | [0-9]+[eE][+-]?[0-9]+
)$/x
EOF;
    static $var_regex = '/^\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/';
    switch ($text) {
      case 'abstract':
        return static::_abstract();
      case 'array':
        return static::_array();
      case 'as':
        return static::_as();
      case 'break':
        return static::_break();
      case 'callable':
        return static::_callable();
      case 'case':
        return static::_case();
      case 'catch':
        return static::_catch();
      case 'class':
        return static::_class();
      case 'clone':
        return static::_clone();
      case 'const':
        return static::_const();
      case 'continue':
        return static::_continue();
      case 'declare':
        return static::_declare();
      case 'default':
        return static::_default();
      case 'die':
        return static::_die();
      case 'do':
        return static::_do();
      case 'echo':
        return static::_echo();
      case 'else':
        return static::_else();
      case 'elseif':
        return static::_elseIf();
      case 'empty':
        return static::_empty();
      case 'enddeclare':
        return static::_endDeclare();
      case 'endfor':
        return static::_endFor();
      case 'endforeach':
        return static::_endForeach();
      case 'endif':
        return static::_endIf();
      case 'endswitch':
        return static::_endSwitch();
      case 'endwhile':
        return static::_endWhile();
      case 'eval':
        return static::_eval();
      case 'exit':
        return static::_exit();
      case 'extends':
        return static::_extends();
      case 'final':
        return static::_final();
      case 'finally':
        return static::_finally();
      case 'for':
        return static::_for();
      case 'foreach':
        return static::_foreach();
      case 'function':
        return static::_function();
      case 'global':
        return static::_global();
      case 'goto':
        return static::_goto();
      case 'if':
        return static::_if();
      case 'implements':
        return static::_implements();
      case 'include':
        return static::_include();
      case 'include_once':
        return static::_includeOnce();
      case 'instanceof':
        return static::_instanceOf();
      case 'insteadof':
        return static::_insteadOf();
      case 'interface':
        return static::_interface();
      case 'isset':
        return static::_isset();
      case 'list':
        return static::_list();
      case 'namespace':
        return static::_namespace();
      case 'new':
        return static::_new();
      case 'print':
        return static::_print();
      case 'private':
        return static::_private();
      case 'protected':
        return static::_protected();
      case 'public':
        return static::_public();
      case 'require':
        return static::_require();
      case 'require_once':
        return static::_requireOnce();
      case 'return':
        return static::_return();
      case 'static':
        return static::_static();
      case 'switch':
        return static::_switch();
      case 'throw':
        return static::_throw();
      case 'trait':
        return static::_trait();
      case 'try':
        return static::_try();
      case 'unset':
        return static::_unset();
      case 'use':
        return static::_use();
      case 'var':
        return static::_var();
      case 'while':
        return static::_while();
      case 'yield':
        return static::_yield();
      case 'and':
        return static::logicalAnd();
      case 'or':
        return static::logicalOr();
      case 'xor':
        return static::logicalXor();
      case '(array)':
        return static::arrayCast();
      case '(bool)':
      case '(boolean)':
        return static::booleanCast();
      case '(real)':
      case '(double)':
      case '(float)':
        return static::doubleCast();
      case '(int)':
      case '(integer)':
        return static::integerCast();
      case '(object)':
        return static::objectCast();
      case '(string)':
        return static::stringCast();
      case '(unset)':
        return static::unsetCast();
      case '__halt_compiler':
        return static::haltCompiler();
      case '__CLASS__':
        return static::classConstant();
      case '__DIR__':
        return static::dirConstant();
      case '__FILE__':
        return static::fileConstant();
      case '__FUNCTION__':
        return static::functionConstant();
      case '__LINE__':
        return static::lineConstant();
      case '__METHOD__':
        return static::methodConstant();
      case '__NAMESPACE__':
        return static::namespaceConstant();
      case '__TRAIT__':
        return static::traitConstant();
      case '...':
        return static::splat();
      case '=>':
        return static::doubleArrow();
      case '->':
        return static::objectOperator();
      case '::':
        return static::doubleColon();
      case '&=':
        return static::bitwiseAndAssign();
      case '|=':
        return static::bitwiseOrAssign();
      case '^=':
        return static::bitwiseXorAssign();
      case '*=':
        return static::multiplyAssign();
      case '/=':
        return static::divideAssign();
      case '%=':
        return static::modulusAssign();
      case '+=':
        return static::addAssign();
      case '-=':
        return static::subtractAssign();
      case '.=':
        return static::concatAssign();
      case '===':
        return static::isIdentical();
      case '==':
        return static::isEqual();
      case '!==':
        return static::isNotIdentical();
      case '!=':
        return static::isNotEqual();
      case '<=':
        return static::isLessThanOrEqual();
      case '>=':
        return static::isGreaterThanOrEqual();
      case '&&':
        return static::booleanAnd();
      case '||':
        return static::booleanOr();
      case '<<':
        return static::bitwiseShiftLeft();
      case '<<=':
        return static::bitwiseShiftLeftAssign();
      case '>>':
        return static::bitwiseShiftRight();
      case '>>=':
        return static::bitwiseShiftRightAssign();
      case '\\':
        return static::namespaceSeparator();
      case '--':
        return static::decrement();
      case '++':
        return static::increment();
      case '`':
      case '~':
      case '!':
      case '@':
      case '%':
      case '^':
      case '&':
      case '*':
      case '(':
      case ')':
      case '-':
      case '+':
      case '=':
      case '{':
      case '}':
      case '[':
      case ']':
      case '|':
      case ':':
      case ';':
      case "'":
      case '"':
      case '<':
      case ',':
      case '>':
      case '.':
      case '?':
      case '/':
        return new TokenNode($text, $text);
      case ' ':
        return static::space();
      case '?>':
        return static::closeTag();
      default:
        if (rtrim($text) === '<?php') {
          return static::openTag();
        }
        elseif (preg_match($int_regex, $text)) {
          return static::integer($text);
        }
        elseif (preg_match($decimal_regex, $text)) {
          return static::decimalNumber($text);
        }
        elseif (preg_match($var_regex, $text)) {
          return static::variable($text);
        }
        // @todo handle all tokens as per http://php.net/manual/en/tokens.php
        throw new \InvalidArgumentException("Unable to parse '{$text}'");
    }
  }
1092582
public function e($text, $context = array())
    {
        $this->log->error($text, $context);
        $this->emit(self::SIGNAL_ERROR_ENTERED);
    }
254056
static public function parseText($text)
    {
        $text = (string)$text;
        // links
        $text = preg_replace('@(https?://([-\w\.]+)+(/([\w/_\.]*(\?\S+)?(#\S+)?)?)?)@', '<a href="$1">$1</a>', $text);
        // users         
        $text = preg_replace('(@([a-zA-Z0-9_]+))', '<a href="http://www.twitter.com/\1">\0</a>', $text);
        // hastag
        $text = preg_replace(
            '/(^|\s)#(\w*[a-zA-Z_]+\w*)/',
            '\1<a href="http://search.twitter.com/search?q=%23\2">#\2</a>',
            $text
        );

        return $text;
    }
755989
public function parse($text) {
        parent::parse($text);

        $number = self::executeStep1($this->text, $this->barcodeIdentifier, $this->serviceTypeIdentifier, $this->mailerIdentifier, $this->serialNumber);
        $crc = self::executeStep2($number);
        $codewords = self::executeStep3($number);
        $codewords = self::executeStep4($codewords, $crc);
        $characters = self::executeStep5($codewords, $crc);
        $this->data = self::executeStep6($characters);
    }
463799
private function parseText ($text)
		{
			$type = gettype($text);
			switch ($type)
			{
				case 'array':
					return $text;
				case 'string':
					return [ '@message' => $text ];
				case 'object':
					return get_object_vars($text);
				default:
					return [ '@message' => \Yii::t('log', "Warning, wrong log message type '{$type}'") ];
			}
		}
394467
private function parseContext($context)
    {
        $debugBackTrace = debug_backtrace();
        if(!isset($context['trace']))
        {
            $context['trace'] = $this->getTrace($debugBackTrace);
        }
        if(!isset($context['errorFile']))
        {
            list($file, $line) = $this->getErrorFile($debugBackTrace);
            $context['errorFile'] = $file;
            $context['errorLine'] = $line;
        }
        return $context;
    }
1025045
public function parseTajweed($text)
    {
        foreach ($this->meta as $meta)
        $text = str_replace(
            $meta['identifier'],
            '<tajweed class="' . $meta['default_css_class']. '" data-type="' . $meta['type'] . '" data-description="' .$meta['description'] . '" data-tajweed="',
            $text);

        return $text;
    }
687268
public function filter($text, $config = array())
    {
        $context = $this->_chain->getContext();
        $context->data = $text;
        $context->config = $config;
        if ($context->config->filter) {
            $filter = (array) AnConfig::unbox($context->config->filter);
            $filter[] = 'ptag';
            $context->config->filter = $filter;
        }
        $this->_chain->run('filter', $context);

        return $context->data;
    }