Create a Grammar object from text grammar source
@param string $text Grammar text
@return Grammar
@since 2.0.0
@throws GrammarException
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;
        }
    }
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}'");
    }
  }
1030527
public static function parse($text, $context = null)
    {
        if (!static::$_enabled || strpos($text, '{') === false) {
            return $text;
        }

        if ($context === null) {
            $context = static::_getDefaultContext();
        }

        static::cache('context', $context);
        $pattern = static::_regex();

        return preg_replace_callback("/{$pattern}/s", 'static::_doShortcode', $text);
    }
1327102
public function create(TextInterface $text)
    {

        return $this->formFactory->create(
            'silvestra_text',
            $text,
            array(
                'method' => 'POST',
                'action' => $this->router->getContext()->getPathInfo(),
            )
        );
    }
54371
public function inject($text)
    {
        if (!is_string($text)) {
            return $text; // nothing to do here
        }

        foreach ($this->parameters as $key => $parameter) {
            if (strpos($text, $key) === false) {
                continue;
            }

            if (is_callable($parameter)) {
                $parameter = call_user_func($parameter);
            }

            $text = str_replace($key, $parameter, $text);
        }

        return $text;
    }
683955
public function makeHtml($text)
    {
        $this->_footnotes = array();
        $this->_definitions = array();
        $this->_holders = array();
        $this->_uniqid = md5(uniqid());
        $this->_id = 0;
        usort($this->blockParsers, function ($a, $b) {
            return $a[1] < $b[1] ? -1 : 1;
        });
        foreach ($this->blockParsers as $parser) {
            list ($name) = $parser;
            if (isset($parser[2])) {
                $this->_parsers[$name] = $parser[2];
            } else {
                $this->_parsers[$name] = array($this, 'parseBlock' . ucfirst($name));
            }
        }
        $text = $this->initText($text);
        $html = $this->parse($text); 
        $html = $this->makeFootnotes($html);
        $html = $this->optimizeLines($html);
        return $this->call('makeHtml', $html);
    }
598731
public function writeRaw($text)
	{
		if (isset($this->_xmlWriter) && is_object($this->_xmlWriter) && (method_exists($this->_xmlWriter, 'writeRaw'))) {
			return $this->_xmlWriter->writeRaw($text);
		}

		return $this->text($text);
	}
174724
public function setText(string $text)
    {
        $this->resource = mailparse_msg_create();
        $eaten = 0;
        $text_length = strlen($text);
        while ($eaten < $text_length) {
            mailparse_msg_parse($this->resource, substr($text, $eaten, 2082));
            $eaten += 2082;
        }

        $this->text = $text;

        return $this;
    }
616550
public function parse($text)
    {
        $this->tokens = $this->lexer->tokenize($text);
        $this->tree = $this->parser->parse($this->tokens);

        return $this->tree;
    }
789583
public function parse($text) {
      $this->queue = array();
      $this->parser = xml_parser_create();        
      $this->parsed = 0;     
      $this->opened = 0;
      xml_set_object($this->parser, $this);
      xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
      xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1);
      $code = xml_parse_into_struct($this->parser, $text, $vals, $index); 
      /**
       * Parse into bAML
       * type structure
       * 
       */ 
      if ($code != 0) {
        return XMLUtility::Make($this, $vals); 
      }
        
      throw new \CatapultApiException("Provided text was not valid XMLUtility..");
    }
391546
public function setText(string $text): self
    {
        return $this->addPart(Part::create($text, 'text/plain'), true);
    }
153037
public static function find(string $text) : Header
    {
        $matches = [];
        $parent = new Header();
        if (\preg_match_all(self::HEADERS_REGEX, $text, $matches, PREG_OFFSET_CAPTURE)) {
            foreach ($matches[0] as $index => $match) {
                $parent->append(new Header((int)$match[1], \strlen($match[0]), (int)$matches[1][$index][0], $matches[2][$index][0]));
            }
        }
        return $parent;
    }
51159
public function sentence(string $text = null): Sentence
    {
        $sentence = Sentence::factory();
        if ($text !== null) {
            $sentence->text($text);
        }

        /** @var ContainerElement $this */
        return $this->addElement($sentence);
    }
593237
public function write(&$text)
    {
        $text = str_replace(
            array_keys($this->_alias_write),
            array_values($this->_alias_write),
            $text);

        return $this;
    }
1085048
public function process($text)
    {
        $iterations = $this->maxIterations === null ? 1 : $this->maxIterations;
        $context = new ProcessorContext();
        $context->processor = $this;

        while ($iterations--) {
            $context->iterationNumber++;
            $newText = $this->processIteration($text, $context, null);
            if ($newText === $text) {
                break;
            }
            $text = $newText;
            $iterations += $this->maxIterations === null ? 1 : 0;
        }

        return $text;
    }
77324
public function write(&$text)
    {
        //Parse the script information
        $styles = $this->_parseStyles($text);

        //Prepend the script information
        $text = $styles.$text;

        return $this;
    }
840773
public static function translate($text)
    {
        $args = func_get_args();
        unset($args[0]);
        
        if (isset(self::$messages[$text])) {
            $text = self::$messages[$text];
        }
        
        return vsprintf($text, $args);
    }