class Parser implements ParserInterface (View source)

The Fusion Parser

Constants

SCAN_PATTERN_COMMENT

SCAN_PATTERN_OPENINGCONFINEMENT

SCAN_PATTERN_CLOSINGCONFINEMENT

SCAN_PATTERN_DECLARATION

SCAN_PATTERN_OBJECTDEFINITION

SCAN_PATTERN_OBJECTPATH

SPLIT_PATTERN_OBJECTPATH

Split an object path like "foo.bar.baz.quux", "foo.'bar.baz.quux'" or "foo.prototype(Neos.Fusion:Something).bar.baz" at the dots (but not the dots inside the prototype definition prototype(...) or dots inside quotes)

SCAN_PATTERN_OBJECTPATHSEGMENT_IS_PROTOTYPE

Analyze an object path segment like "foo" or "prototype(Neos.Fusion:Something)" and detect the latter

SPLIT_PATTERN_COMMENTTYPE

SPLIT_PATTERN_DECLARATION

SPLIT_PATTERN_NAMESPACEDECLARATION

SPLIT_PATTERN_OBJECTDEFINITION

SPLIT_PATTERN_VALUENUMBER

SPLIT_PATTERN_VALUEFLOATNUMBER

SPLIT_PATTERN_VALUELITERAL

SPLIT_PATTERN_VALUEMULTILINELITERAL

SPLIT_PATTERN_VALUEBOOLEAN

SPLIT_PATTERN_VALUENULL

SCAN_PATTERN_VALUEOBJECTTYPE

SCAN_PATTERN_DSL_EXPRESSION_START

SPLIT_PATTERN_DSL_EXPRESSION

Properties

static array $reservedParseTreeKeys

Reserved parse tree keys for internal usage.

protected ObjectManagerInterface $objectManager
protected DslFactory $dslFactory
protected array $objectTree

The Fusion object tree, created by this parser.

protected int $currentLineNumber

The line number which is currently processed

protected array $currentSourceCodeLines

An array of strings of the source code which has

protected array $currentObjectPathStack

The current object path context as defined by confinements.

protected bool $currentBlockCommentState

Determines if a block comment is currently active or not.

protected string $contextPathAndFilename

An optional context path which is used as a prefix for inclusion of further Fusion files

protected array deprecated $objectTypeNamespaces

Namespaces used for resolution of Fusion object names. These namespaces are a mapping from a user defined key (alias) to a package key (the namespace).

Methods

array
parse(string $sourceCode, string $contextPathAndFilename = null, array $objectTreeUntilNow = [], bool $buildPrototypeHierarchy = true)

Parses the given Fusion source code and returns an object tree as the result.

void
setObjectTypeNamespace(string $alias, string $namespace) deprecated

Sets the given alias to the specified namespace.

void
initialize()

Initializes the Fusion parser

string
getNextFusionLine()

Get the next, unparsed line of Fusion from this->currentSourceCodeLines and increase the pointer

void
parseFusionLine(string $fusionLine)

Parses one line of Fusion

void
parseComment(string $fusionLine)

Parses a line with comments or a line while parsing is in block comment mode.

void
parseConfinementBlock(string $fusionLine, bool $isOpeningConfinement)

Parses a line which opens or closes a confinement

void
parseDeclaration(string $fusionLine)

Parses a parser declaration of the form "declarationtype: declaration".

void
parseObjectDefinition(string $fusionLine)

Parses an object definition.

void
parseValueAssignment(string $objectPath, string $value)

Parses a value operation of the type "assignment".

void
parseValueUnAssignment(string $objectPath)

Unsets the object, property or variable specified by the object path.

void
parseValueCopy(string $sourceObjectPath, string $targetObjectPath)

Copies the object or value specified by sourcObjectPath and assigns it to targetObjectPath.

void
parseNamespaceDeclaration(string $namespaceDeclaration)

Parses a namespace declaration and stores the result in the namespace registry.

void
parseInclude(string $include)

Parse an include file. Currently, we start a new parser object; but we could as well re-use the given one.

array
getParsedObjectPath(string $objectPath)

Parse an object path specified as a string and returns an array.

mixed
getProcessedValue(string $unparsedValue)

Parses the given value (which may be a literal, variable or object type) and returns the evaluated result, including variables replaced by their actual value.

mixed
invokeAndParseDsl(string $identifier, $code)

No description

array
setValueInObjectTree(array $objectPathArray, mixed $value, array $objectTree = null)

Assigns a value to a node or a property in the object tree, specified by the object path array.

mixed
getValueFromObjectTree(array $objectPathArray, array $objectTree = null)

Retrieves a value from a node in the object tree, specified by the object path array.

string
getCurrentObjectPathPrefix()

Returns the first part of an object path from the current object path stack which can be used to prefix a relative object path.

void
buildPrototypeHierarchy()

Precalculate merged configuration for inherited prototypes.

string
unquoteString(string $quotedValue)

Removes escapings from a given argument string and trims the outermost quotes.

string
renderCurrentFileAndLineInformation()

Render a hint about the currently rendered file and líne that is to be used in Exception Messages to show where parser errors originate from

Details

array parse(string $sourceCode, string $contextPathAndFilename = null, array $objectTreeUntilNow = [], bool $buildPrototypeHierarchy = true)

Parses the given Fusion source code and returns an object tree as the result.

Parameters

string $sourceCode

The Fusion source code to parse

string $contextPathAndFilename

An optional path and filename to use as a prefix for inclusion of further Fusion files

array $objectTreeUntilNow

Used internally for keeping track of the built object tree

bool $buildPrototypeHierarchy

Merge prototype configurations or not. Will be false for includes to only do that once at the end.

Return Value

array

A Fusion object tree, generated from the source code

Exceptions

Exception

void setObjectTypeNamespace(string $alias, string $namespace) deprecated

deprecated with version 7.3 will be removed with 8.0

Sets the given alias to the specified namespace.

The namespaces defined through this setter or through a "namespace" declaration in one of the Fusions are used to resolve a fully qualified Fusion object name while parsing Fusion code.

The alias is the handle by wich the namespace can be referred to. The namespace is, by convention, a package key which must correspond to a namespace used in the prototype definitions for Fusion object types.

The special alias "default" is used as a fallback for resolution of unqualified Fusion object types.

Parameters

string $alias

An alias for the given namespace, for example "neos"

string $namespace

The namespace, for example "Neos.Neos"

Return Value

void

Exceptions

Exception

protected void initialize()

Initializes the Fusion parser

Return Value

void

protected string getNextFusionLine()

Get the next, unparsed line of Fusion from this->currentSourceCodeLines and increase the pointer

Return Value

string

next line of Fusion to parse

protected void parseFusionLine(string $fusionLine)

Parses one line of Fusion

Parameters

string $fusionLine

One line of Fusion code

Return Value

void

Exceptions

Exception

protected void parseComment(string $fusionLine)

Parses a line with comments or a line while parsing is in block comment mode.

Parameters

string $fusionLine

One line of Fusion code

Return Value

void

Exceptions

Exception

protected void parseConfinementBlock(string $fusionLine, bool $isOpeningConfinement)

Parses a line which opens or closes a confinement

Parameters

string $fusionLine

One line of Fusion code

bool $isOpeningConfinement

Set to true, if an opening confinement is to be parsed and false if it's a closing confinement.

Return Value

void

Exceptions

Exception

protected void parseDeclaration(string $fusionLine)

Parses a parser declaration of the form "declarationtype: declaration".

Parameters

string $fusionLine

One line of Fusion code

Return Value

void

Exceptions

Exception

protected void parseObjectDefinition(string $fusionLine)

Parses an object definition.

Parameters

string $fusionLine

One line of Fusion code

Return Value

void

Exceptions

Exception

protected void parseValueAssignment(string $objectPath, string $value)

Parses a value operation of the type "assignment".

Parameters

string $objectPath

The object path as a string

string $value

The unparsed value as a string

Return Value

void

protected void parseValueUnAssignment(string $objectPath)

Unsets the object, property or variable specified by the object path.

Parameters

string $objectPath

The object path as a string

Return Value

void

Exceptions

Exception

protected void parseValueCopy(string $sourceObjectPath, string $targetObjectPath)

Copies the object or value specified by sourcObjectPath and assigns it to targetObjectPath.

Parameters

string $sourceObjectPath

Specifies the location in the object tree from where the object or value will be taken

string $targetObjectPath

Specifies the location in the object tree where the copy will be stored

Return Value

void

Exceptions

Exception

protected void parseNamespaceDeclaration(string $namespaceDeclaration)

Parses a namespace declaration and stores the result in the namespace registry.

Parameters

string $namespaceDeclaration

The namespace declaration, for example "neos = Neos.Neos"

Return Value

void

Exceptions

Exception

protected void parseInclude(string $include)

Parse an include file. Currently, we start a new parser object; but we could as well re-use the given one.

Parameters

string $include

The include value, for example " FooBar" or " resource://....". Can also include wildcard mask for Fusion globbing.

Return Value

void

Exceptions

Exception

protected array getParsedObjectPath(string $objectPath)

Parse an object path specified as a string and returns an array.

Parameters

string $objectPath

The object path to parse

Return Value

array

An object path array

Exceptions

Exception

protected mixed getProcessedValue(string $unparsedValue)

Parses the given value (which may be a literal, variable or object type) and returns the evaluated result, including variables replaced by their actual value.

Parameters

string $unparsedValue

The unparsed value

Return Value

mixed

The processed value

Exceptions

Exception

protected mixed invokeAndParseDsl(string $identifier, $code)

No description

Parameters

string $identifier
$code

Return Value

mixed

Exceptions

Exception
Exception

protected array setValueInObjectTree(array $objectPathArray, mixed $value, array $objectTree = null)

Assigns a value to a node or a property in the object tree, specified by the object path array.

Parameters

array $objectPathArray

The object path, specifying the node / property to set

mixed $value

The value to assign, is a non-array type or an array with __eelExpression etc.

array $objectTree

The current (sub-) tree, used internally - don't specify!

Return Value

array

The modified object tree

protected mixed getValueFromObjectTree(array $objectPathArray, array $objectTree = null)

Retrieves a value from a node in the object tree, specified by the object path array.

Parameters

array $objectPathArray

The object path, specifying the node to retrieve the value of

array $objectTree

The current (sub-) tree, used internally - don't specify!

Return Value

mixed

The value

protected string getCurrentObjectPathPrefix()

Returns the first part of an object path from the current object path stack which can be used to prefix a relative object path.

Return Value

string

A part of an object path, ready to use as a prefix

protected void buildPrototypeHierarchy()

Precalculate merged configuration for inherited prototypes.

Return Value

void

Exceptions

Exception

protected string unquoteString(string $quotedValue)

Removes escapings from a given argument string and trims the outermost quotes.

This method is meant as a helper for regular expression results.

Parameters

string $quotedValue

Value to unquote

Return Value

string

Unquoted value

protected string renderCurrentFileAndLineInformation()

Render a hint about the currently rendered file and líne that is to be used in Exception Messages to show where parser errors originate from

Return Value

string