/** * @throws SyntaxError When got None for xpath expression */ public static function cssToXpath($cssExpr, $prefix = 'descendant-or-self::') { if (is_string($cssExpr)) { if (preg_match('#^\\w+\\s*$#u', $cssExpr, $match)) { return $prefix . trim($match[0]); } if (preg_match('~^(\\w*)#(\\w+)\\s*$~u', $cssExpr, $match)) { return sprintf("%s%s[@id = '%s']", $prefix, $match[1] ? $match[1] : '*', $match[2]); } if (preg_match('#^(\\w*)\\.(\\w+)\\s*$#u', $cssExpr, $match)) { return sprintf("%s%s[contains(concat(' ', normalize-space(@class), ' '), ' %s ')]", $prefix, $match[1] ? $match[1] : '*', $match[2]); } $parser = new self(); $cssExpr = $parser->parse($cssExpr); } $expr = $cssExpr->toXpath(); // @codeCoverageIgnoreStart if (!$expr) { throw new SyntaxError(sprintf('Got None for xpath expression from %s.', $cssExpr)); } // @codeCoverageIgnoreEnd if ($prefix) { $expr->addPrefix($prefix); } return (string) $expr; }
/** * Returns a preview of given Text * * @param type $foo * @return type */ public static function Render($markdown) { $markdown = CHtml::encode($markdown); $parser = new self(); $text = $parser->parse($markdown); return $text; }
public static function getAtts(&$source) { $p = new self(); $res = $p->parse($source); $source = !empty($p->modifiers) ? ' |' . $p->modifiers : ''; return $res; }
/** * Creates a stylesheet link with LESS support * * @param string $style file name * @param array $attributes default attributes * @param bool $index include the index page * @param array $imports compare file date for these too, CSS and LESS in style @import * @return string */ public static function style($file, array $attributes = null, $index = false, $imports = null) { $imports = (array) $imports; // Compile only .less files if (substr_compare($file, '.less', -5, 5, false) === 0) { $css = substr_replace($file, 'css', -4); $compiled = is_file($css) ? filemtime($css) : 0; try { // Check if imported files have changed $compile = filemtime($file) > $compiled; if (!$compile && !empty($imports)) { foreach ($imports as $import) { if (filemtime($import) > $compiled) { $compile = true; break; } } } // Compile LESS if ($compile) { $compiler = new self($file); file_put_contents($css, $compiler->parse()); } $file = $css; } catch (Exception $e) { Kohana::$log->add(Kohana::ERROR, __METHOD__ . ': Error compiling LESS file ' . $file . ', ' . $e->getMessage()); } } return HTML::style($file . '?' . filemtime($file), $attributes, $index); }
public static function match($method) { if (Strings::startsWith($method, 'findBy')) { $dynamicFinder = new self($method); $dynamicFinder->parse(); return $dynamicFinder; } return null; }
/** * Simple entry point for command-line testing */ static function test($text) { try { $ce = new self($text); $ce->parse(); } catch (ConfEditorParseError $e) { return $e->getMessage() . "\n" . $e->highlight($text); } return "OK"; }
public static function fromFile($file) { if (!empty($file) && is_file($file)) { $basePath = pathinfo($file, PATHINFO_DIRNAME); $parser = new self($basePath); return $parser->parse(file_get_contents($file)); } else { throw new RuntimeException('Could not load json schema ' . $file); } }
/** * Quick parse modules feed. * * @param string $url XML feed URL * @param string $cache_dir Cache directoy or null for no cache * @param boolean $force Force query repository * @return object Self instance */ public static function quickParse($url, $cache_dir = null, $force = false) { $parser = new self(); if ($cache_dir) { $parser->setCacheDir($cache_dir); } if ($force) { $parser->setForce($force); } return $parser->parse($url); }
public static function find_or_create_by_uastring($ua_string) { $ua_string = trim($ua_string); if (!strlen($ua_string)) { return NULL; } $agent = self::find_one_by_user_agent($ua_string); if (!$agent) { $agent = new self(); $agent->user_agent = $ua_string; $agent->parse()->save(); } return $agent; }
protected function getBlock() { if (!$this->testCurrentString('[[')) { throw new \Exception('Block start expected!'); } $this->nextChar(); $this->nextChar(); $blockSignature = $this->getBlockSignature(); $block = $this->blockSignatureParser->parse($blockSignature); $position = $this->getNextNotWhiteSpacePosition($this->position); if ($this->testString($position, '{{')) { $this->skipWhiteSpace(); $content = $this->getBlockContent(); // todo: block can be parsed in one pass $clone = new self($this->blockSignatureParser); $result = $clone->parse($content); $block['markup'] = $result; } return $block; }
private function parsePreToken($preToken) { $token = null; $matches = []; foreach ($this->regEx as $tokenName => $rgx) { if (preg_match($rgx, $preToken, $matches)) { $token = $this->createToken($tokenName, $matches['value']); break; } } if (is_null($token)) { $token = $this->createToken(self::ILEGAL, $preToken); } else { if (array_key_exists('inner', $matches)) { $this->addToken($token); $tokenizer = new self(); $stream = $tokenizer->parse($matches['inner']); $this->addTokens($stream); } else { $this->addToken($token); } } return $this->currentToken; }
/** * Shortcut to instantiate, tokenize, parse and evaluate * * @param string $expression * @param array $values * @return boolean */ public static function run($expression, $values) { $evaluator = new self(); $evaluator->parse($evaluator->tokenize($expression)); return $evaluator->evaluate($values); }
public static function fromString($s) { $parser = new self($s); return $parser->parse(); }
/** * @param $in * @param $root_url * * @return string */ public static function combine($in, $root_url) { $css = new self($in, $root_url); return $css->parse(); }
private function parseBlock($offset, $yaml, $exceptionOnInvalidType, $objectSupport, $objectForMap) { $skippedLineNumbers = $this->skippedLineNumbers; foreach ($this->locallySkippedLineNumbers as $lineNumber) { if ($lineNumber < $offset) { continue; } $skippedLineNumbers[] = $lineNumber; } $parser = new self($offset, $this->totalNumberOfLines, $skippedLineNumbers); $parser->refs =& $this->refs; return $parser->parse($yaml, $exceptionOnInvalidType, $objectSupport, $objectForMap); }
/** * Decodes a NEON string. * @param string * @return mixed */ public static function decode($input) { if (!is_string($input)) { throw new \InvalidArgumentException("Argument must be a string, " . gettype($input) . " given."); } if (!self::$tokenizer) { self::$tokenizer = new Tokenizer(self::$patterns, 'mi'); } $input = str_replace("\r", '', $input); self::$tokenizer->tokenize($input); $parser = new self; $res = $parser->parse(0); while (isset(self::$tokenizer->tokens[$parser->n])) { if (self::$tokenizer->tokens[$parser->n][0] === "\n") { $parser->n++; } else { $parser->error(); } } return $res; }
/** * Quick Parse * * This static method returns a new {@link feedParser} instance for given URL. If a * <var>$cache_dir</var> is specified, cache will be activated. * * @param string $url Feed URL * @param string $cache_dir Cache directory * @return feedParser|false */ public static function quickParse($url, $cache_dir = null) { $parser = new self(); if ($cache_dir) { $parser->setCacheDir($cache_dir); } return $parser->parse($url); }
public function parse($value, $exceptionOnInvalidType = false, $objectSupport = false, $objectForMap = false) { if (!preg_match('//u', $value)) { throw new ParseException('The YAML value does not appear to be valid UTF-8.'); } $this->currentLineNb = -1; $this->currentLine = ''; $value = $this->cleanup($value); $this->lines = explode("\n", $value); if (2 & (int) ini_get('mbstring.func_overload')) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('UTF-8'); } $data = array(); $context = null; $allowOverwrite = false; while ($this->moveToNextLine()) { if ($this->isCurrentLineEmpty()) { continue; } if ("\t" === $this->currentLine[0]) { throw new ParseException('A YAML file cannot contain tabs as indentation.', $this->getRealCurrentLineNb() + 1, $this->currentLine); } $isRef = $mergeNode = false; if (preg_match('#^\-((?P<leadspaces>\s+)(?P<value>.+?))?\s*$#u', $this->currentLine, $values)) { if ($context && 'mapping' == $context) { throw new ParseException('You cannot define a sequence item when in a mapping'); } $context = 'sequence'; if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches)) { $isRef = $matches['ref']; $values['value'] = $matches['value']; } if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) { $c = $this->getRealCurrentLineNb() + 1; $parser = new self($c); $parser->refs = &$this->refs; $data[] = $parser->parse($this->getNextEmbedBlock(null, true), $exceptionOnInvalidType, $objectSupport, $objectForMap); } else { if (isset($values['leadspaces']) && preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $values['value'], $matches) ) { $c = $this->getRealCurrentLineNb(); $parser = new self($c); $parser->refs = &$this->refs; $block = $values['value']; if ($this->isNextLineIndented()) { $block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + strlen($values['leadspaces']) + 1); } $data[] = $parser->parse($block, $exceptionOnInvalidType, $objectSupport, $objectForMap); } else { $data[] = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport, $objectForMap, $context); } } if ($isRef) { $this->refs[$isRef] = end($data); } } elseif (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->currentLine, $values) && (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'")))) { if ($context && 'sequence' == $context) { throw new ParseException('You cannot define a mapping item when in a sequence'); } $context = 'mapping'; Inline::parse(null, $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs); try { $key = Inline::parseScalar($values['key']); } catch (ParseException $e) { $e->setParsedLine($this->getRealCurrentLineNb() + 1); $e->setSnippet($this->currentLine); throw $e; } if (is_float($key)) { $key = (string) $key; } if ('<<' === $key) { $mergeNode = true; $allowOverwrite = true; if (isset($values['value']) && 0 === strpos($values['value'], '*')) { $refName = substr($values['value'], 1); if (!array_key_exists($refName, $this->refs)) { throw new ParseException(sprintf('Reference "%s" does not exist.', $refName), $this->getRealCurrentLineNb() + 1, $this->currentLine); } $refValue = $this->refs[$refName]; if (!is_array($refValue)) { throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine); } foreach ($refValue as $key => $value) { if (!isset($data[$key])) { $data[$key] = $value; } } } else { if (isset($values['value']) && $values['value'] !== '') { $value = $values['value']; } else { $value = $this->getNextEmbedBlock(); } $c = $this->getRealCurrentLineNb() + 1; $parser = new self($c); $parser->refs = &$this->refs; $parsed = $parser->parse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap); if (!is_array($parsed)) { throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine); } if (isset($parsed[0])) { foreach ($parsed as $parsedItem) { if (!is_array($parsedItem)) { throw new ParseException('Merge items must be arrays.', $this->getRealCurrentLineNb() + 1, $parsedItem); } foreach ($parsedItem as $key => $value) { if (!isset($data[$key])) { $data[$key] = $value; } } } } else { foreach ($parsed as $key => $value) { if (!isset($data[$key])) { $data[$key] = $value; } } } } } elseif (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches)) { $isRef = $matches['ref']; $values['value'] = $matches['value']; } if ($mergeNode) { } elseif (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) { if (!$this->isNextLineIndented() && !$this->isNextLineUnIndentedCollection()) { if ($allowOverwrite || !isset($data[$key])) { $data[$key] = null; } } else { $c = $this->getRealCurrentLineNb() + 1; $parser = new self($c); $parser->refs = &$this->refs; $value = $parser->parse($this->getNextEmbedBlock(), $exceptionOnInvalidType, $objectSupport, $objectForMap); if ($allowOverwrite || !isset($data[$key])) { $data[$key] = $value; } } } else { $value = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport, $objectForMap, $context); if ($allowOverwrite || !isset($data[$key])) { $data[$key] = $value; } } if ($isRef) { $this->refs[$isRef] = $data[$key]; } } else { if ('---' === $this->currentLine) { throw new ParseException('Multiple documents are not supported.'); } if (is_string($value) && $this->lines[0] === trim($value)) { try { $value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs); } catch (ParseException $e) { $e->setParsedLine($this->getRealCurrentLineNb() + 1); $e->setSnippet($this->currentLine); throw $e; } if (is_array($value)) { $first = reset($value); if (is_string($first) && 0 === strpos($first, '*')) { $data = array(); foreach ($value as $alias) { $data[] = $this->refs[substr($alias, 1)]; } $value = $data; } } if (isset($mbEncoding)) { mb_internal_encoding($mbEncoding); } return $value; } switch (preg_last_error()) { case PREG_INTERNAL_ERROR: $error = 'Internal PCRE error.'; break; case PREG_BACKTRACK_LIMIT_ERROR: $error = 'pcre.backtrack_limit reached.'; break; case PREG_RECURSION_LIMIT_ERROR: $error = 'pcre.recursion_limit reached.'; break; case PREG_BAD_UTF8_ERROR: $error = 'Malformed UTF-8 data.'; break; case PREG_BAD_UTF8_OFFSET_ERROR: $error = 'Offset doesn\'t correspond to the begin of a valid UTF-8 code point.'; break; default: $error = 'Unable to parse.'; } throw new ParseException($error, $this->getRealCurrentLineNb() + 1, $this->currentLine); } } if (isset($mbEncoding)) { mb_internal_encoding($mbEncoding); } if ($objectForMap && !is_object($data)) { $data = (object) $data; } return empty($data) ? null : $data; }
/** * Include a Subfragment from within a fragment. * * The Subfragment gets all variables of the current fragment, plus optional overrides from $params * * @param string $filename The filename of the fragment to use * @param array $params A array of key-value pairs to pass as local parameters */ protected function subfragment($filename, array $params = []) { $fragment = new self(array_merge($this->vars, $params)); echo $fragment->parse($filename); }
/** * Parses a YAML string to a PHP value. * * @param string $value * A YAML string * @param bool $exceptionOnInvalidType * true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise * @param bool $objectSupport * true if object support is enabled, false otherwise * @param bool $objectForMap * true if maps should return a stdClass instead of array() * * @return mixed A PHP value * * @throws ParseException If the YAML is not valid */ public function parse($value, $exceptionOnInvalidType = false, $objectSupport = false, $objectForMap = false) { if (!preg_match('//u', $value)) { throw new ParseException('The YAML value does not appear to be valid UTF-8.'); } $this->currentLineNb = -1; $this->currentLine = ''; $value = $this->cleanup($value); $this->lines = explode("\n", $value); if (function_exists('mb_internal_encoding') && (int) ini_get('mbstring.func_overload') & 2) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('UTF-8'); } $data = array(); $context = null; $allowOverwrite = false; while ($this->moveToNextLine()) { if ($this->isCurrentLineEmpty()) { continue; } // tab? if ("\t" === $this->currentLine[0]) { throw new ParseException('A YAML file cannot contain tabs as indentation.', $this->getRealCurrentLineNb() + 1, $this->currentLine); } $isRef = $mergeNode = false; if (preg_match('#^\\-((?P<leadspaces>\\s+)(?P<value>.+?))?\\s*$#u', $this->currentLine, $values)) { if ($context && 'mapping' == $context) { throw new ParseException('You cannot define a sequence item when in a mapping'); } $context = 'sequence'; if (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches)) { $isRef = $matches['ref']; $values['value'] = $matches['value']; } // array if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) { $c = $this->getRealCurrentLineNb() + 1; $parser = new self($c); $parser->refs =& $this->refs; $data[] = $parser->parse($this->getNextEmbedBlock(null, true), $exceptionOnInvalidType, $objectSupport, $objectForMap); } else { if (isset($values['leadspaces']) && preg_match('#^(?P<key>' . Inline::REGEX_QUOTED_STRING . '|[^ \'"\\{\\[].*?) *\\:(\\s+(?P<value>.+?))?\\s*$#u', $values['value'], $matches)) { // this is a compact notation element, add to next block and parse $c = $this->getRealCurrentLineNb(); $parser = new self($c); $parser->refs =& $this->refs; $block = $values['value']; if ($this->isNextLineIndented()) { $block .= "\n" . $this->getNextEmbedBlock($this->getCurrentLineIndentation() + strlen($values['leadspaces']) + 1); } $data[] = $parser->parse($block, $exceptionOnInvalidType, $objectSupport, $objectForMap); } else { $data[] = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport, $objectForMap); } } if ($isRef) { $this->refs[$isRef] = end($data); } } elseif (preg_match('#^(?P<key>' . Inline::REGEX_QUOTED_STRING . '|[^ \'"\\[\\{].*?) *\\:(\\s+(?P<value>.+?))?\\s*$#u', $this->currentLine, $values) && (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'")))) { if ($context && 'sequence' == $context) { throw new ParseException('You cannot define a mapping item when in a sequence'); } $context = 'mapping'; // force correct settings Inline::parse(null, $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs); try { $key = Inline::parseScalar($values['key']); } catch (ParseException $e) { $e->setParsedLine($this->getRealCurrentLineNb() + 1); $e->setSnippet($this->currentLine); throw $e; } // Convert float keys to strings, to avoid being converted to integers by PHP if (is_float($key)) { $key = (string) $key; } if ('<<' === $key) { $mergeNode = true; $allowOverwrite = true; if (isset($values['value']) && 0 === strpos($values['value'], '*')) { $refName = substr($values['value'], 1); if (!array_key_exists($refName, $this->refs)) { throw new ParseException(sprintf('Reference "%s" does not exist.', $refName), $this->getRealCurrentLineNb() + 1, $this->currentLine); } $refValue = $this->refs[$refName]; if (!is_array($refValue)) { throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine); } foreach ($refValue as $key => $value) { if (!isset($data[$key])) { $data[$key] = $value; } } } else { if (isset($values['value']) && $values['value'] !== '') { $value = $values['value']; } else { $value = $this->getNextEmbedBlock(); } $c = $this->getRealCurrentLineNb() + 1; $parser = new self($c); $parser->refs =& $this->refs; $parsed = $parser->parse($value, $exceptionOnInvalidType, $objectSupport, $objectForMap); if (!is_array($parsed)) { throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine); } if (isset($parsed[0])) { // If the value associated with the merge key is a sequence, then this sequence is expected to contain mapping nodes // and each of these nodes is merged in turn according to its order in the sequence. Keys in mapping nodes earlier // in the sequence override keys specified in later mapping nodes. foreach ($parsed as $parsedItem) { if (!is_array($parsedItem)) { throw new ParseException('Merge items must be arrays.', $this->getRealCurrentLineNb() + 1, $parsedItem); } foreach ($parsedItem as $key => $value) { if (!isset($data[$key])) { $data[$key] = $value; } } } } else { // If the value associated with the key is a single mapping node, each of its key/value pairs is inserted into the // current mapping, unless the key already exists in it. foreach ($parsed as $key => $value) { if (!isset($data[$key])) { $data[$key] = $value; } } } } } elseif (isset($values['value']) && preg_match('#^&(?P<ref>[^ ]+) *(?P<value>.*)#u', $values['value'], $matches)) { $isRef = $matches['ref']; $values['value'] = $matches['value']; } if ($mergeNode) { // Merge keys } elseif (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) { // hash // if next line is less indented or equal, then it means that the current value is null if (!$this->isNextLineIndented() && !$this->isNextLineUnIndentedCollection()) { // Spec: Keys MUST be unique; first one wins. // But overwriting is allowed when a merge node is used in current block. if ($allowOverwrite || !isset($data[$key])) { $data[$key] = null; } } else { $c = $this->getRealCurrentLineNb() + 1; $parser = new self($c); $parser->refs =& $this->refs; $value = $parser->parse($this->getNextEmbedBlock(), $exceptionOnInvalidType, $objectSupport, $objectForMap); // Spec: Keys MUST be unique; first one wins. // But overwriting is allowed when a merge node is used in current block. if ($allowOverwrite || !isset($data[$key])) { $data[$key] = $value; } } } else { $value = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport, $objectForMap); // Spec: Keys MUST be unique; first one wins. // But overwriting is allowed when a merge node is used in current block. if ($allowOverwrite || !isset($data[$key])) { $data[$key] = $value; } } if ($isRef) { $this->refs[$isRef] = $data[$key]; } } else { // multiple documents are not supported if ('---' === $this->currentLine) { throw new ParseException('Multiple documents are not supported.'); } // 1-liner optionally followed by newline(s) if (is_string($value) && $this->lines[0] === trim($value)) { try { $value = Inline::parse($this->lines[0], $exceptionOnInvalidType, $objectSupport, $objectForMap, $this->refs); } catch (ParseException $e) { $e->setParsedLine($this->getRealCurrentLineNb() + 1); $e->setSnippet($this->currentLine); throw $e; } if (is_array($value)) { $first = reset($value); if (is_string($first) && 0 === strpos($first, '*')) { $data = array(); foreach ($value as $alias) { $data[] = $this->refs[substr($alias, 1)]; } $value = $data; } } if (isset($mbEncoding)) { mb_internal_encoding($mbEncoding); } return $value; } switch (preg_last_error()) { case PREG_INTERNAL_ERROR: $error = 'Internal PCRE error.'; break; case PREG_BACKTRACK_LIMIT_ERROR: $error = 'pcre.backtrack_limit reached.'; break; case PREG_RECURSION_LIMIT_ERROR: $error = 'pcre.recursion_limit reached.'; break; case PREG_BAD_UTF8_ERROR: $error = 'Malformed UTF-8 data.'; break; case PREG_BAD_UTF8_OFFSET_ERROR: $error = 'Offset doesn\'t correspond to the begin of a valid UTF-8 code point.'; break; default: $error = 'Unable to parse.'; } throw new ParseException($error, $this->getRealCurrentLineNb() + 1, $this->currentLine); } } if (isset($mbEncoding)) { mb_internal_encoding($mbEncoding); } return empty($data) ? null : $data; }
/** * Entry point for the class * * @param $text string * @return string */ public static function mangle($text) { $postParse = new self($text); $postParse->parse(); return $postParse->html; }
private function processRenderQueue($contents = array()) { if (isset($this->layoutRender)) { $template = new self(); // Set the variables that have been set here. foreach ($this->values as $k => $v) { $template->set($k, $v); } // And now set the content blocks. // This might overwrite other sets. foreach ($contents as $k => $v) { $template->set($k, $v, true); } return $template->parse($this->layoutRender); } else { return $contents['content']; } }
/** * Parse raw link label, including surrounding [], and return * inline contents. * * @param string $s * * @return ArrayCollection|InlineElementInterface[] Inline contents */ private function parseRawLabel($s) { // note: parse without a refmap; we don't want links to resolve // in nested brackets! $parser = new self(); $substring = substr($s, 1, strlen($s) - 2); return $parser->parse($substring, new CommonMark_Reference_ReferenceMap()); }
private function parseBlock($offset, $yaml, $flags) { $skippedLineNumbers = $this->skippedLineNumbers; foreach ($this->locallySkippedLineNumbers as $lineNumber) { if ($lineNumber < $offset) { continue; } $skippedLineNumbers[] = $lineNumber; } $parser = new self($offset, $this->totalNumberOfLines, $skippedLineNumbers); $parser->refs =& $this->refs; return $parser->parse($yaml, $flags); }
/** * Decodes a NEON string. * @param string * @return mixed */ public static function decode($input) { if (!is_string($input)) { throw new \InvalidArgumentException("Argument must be a string, " . gettype($input) . " given."); } if (!self::$re) { self::$re = '~(' . implode(')|(', self::$patterns) . ')~Ami'; } $parser = new self(); $parser->tokenize($input); $res = $parser->parse(0); while (isset($parser->tokens[$parser->n])) { if ($parser->tokens[$parser->n][0] === "\n") { $parser->n++; } else { $parser->error(); } } return $res; }
/** * Convenience function for determining if something is a valid coordinate string. * Analogous to creating an instance of the parser, parsing the string and checking isValid on the result. * * @since 0.1 * * @param string $string * * @return boolean */ public static function areCoordinates($string) { static $parser = null; if ($parser === null) { $parser = new self(new ParserOptions()); } return $parser->parse($string)->isValid(); }
/** * @param array $parameters * @param $methodName * @return ParameterParser[] */ public static function create($parameters, $methodName) { $obj = array(); foreach ($parameters as $parameter) { $parser = new self($parameter, $methodName); $obj[] = $parser->parse(); } return $obj; }
/** * Parse data into the string and return all fields as an array. * * @param array $data * @param bool $split_tags_and_fields return fields and separators separated in resultarray (separators are not used in query, so quotes aren't used) * * @return array */ public function getAllParsedFieldsAsArray($data, $split_tags_and_fields = false) { $matches = $this->getAllFieldsAsArray(); Tools::atk_var_dump($matches, 'MATCHES' . ($split_tags_and_fields ? ' (split tags and separators)' : '')); $fields = []; if (is_array($matches)) { foreach ($matches[0] as $match) { // Check if need to parse the match if (strpos($match, '[') !== false && strpos($match, ']') !== false) { $parser = new self($match); if ($split_tags_and_fields) { $fields['tags'][] = $parser->parse($data); } else { $fields[] = $parser->parse($data); } } else { if ($split_tags_and_fields) { $fields['separators'][] = $match; } else { $fields[] = "'" . $match . "'"; } } } } return $fields; }
/** * Метод для быстрого типографирования текста, при котором не нужно * делать настройки тофов, их базовых параметров и т.п. * * @param string $text строка для типографирования * @return string */ public static function quickParse($text) { $typograph = new self($text); return $typograph->parse($typograph->getBaseTofsNames()); }
/** * Create a DBExample and parse it * * @param array $example The DBExample structure * @param array $binds This variables, passed by reference, * will be filled with the binded values during example parsing during example parsing * * @return string the parsed SQL expression */ public static function make($example, &$binds) { $instance = new self($example); return $instance->parse($binds); }