ts-fusion-parser
Version:
Parser for Neos Fusion Files
128 lines (127 loc) • 5.5 kB
TypeScript
import { AbstractNode } from '../common/AbstractNode';
import { Comment } from '../common/Comment';
import { NodePosition } from '../common/NodePosition';
import { AfxParserOptions } from '../dsl/afx/parser';
import { EelParserOptions } from '../dsl/eel/parser';
import { Lexer } from './lexer';
import { AbstractPathSegment } from './nodes/AbstractPathSegment';
import { AbstractPathValue } from './nodes/AbstractPathValue';
import { AbstractStatement } from './nodes/AbstractStatement';
import { AssignedObjectPath } from './nodes/AssignedObjectPath';
import { Block } from './nodes/Block';
import { DslExpressionValue } from './nodes/DslExpressionValue';
import { FusionFile } from './nodes/FusionFile';
import { IncludeStatement } from './nodes/IncludeStatement';
import { ObjectPath } from './nodes/ObjectPath';
import { ObjectStatement } from './nodes/ObjectStatement';
import { PropertyDocumentationDefinition } from './nodes/PropertyDocumentationDefinition';
import { PrototypeDocumentationDefinition } from './nodes/PrototypeDocumentationDefinition';
import { StatementList } from './nodes/StatementList';
import { ValueAssignment } from './nodes/ValueAssignment';
import { ValueCopy } from './nodes/ValueCopy';
import { ValueUnset } from './nodes/ValueUnset';
import { Token } from './token';
export interface FusionParserOptions {
ignoreErrors: boolean;
allowIncompleteObjectStatements: boolean;
afxParserOptions?: AfxParserOptions;
eelParserOptions?: EelParserOptions;
}
export declare class ObjectTreeParser {
protected lexer: Lexer;
protected contextPathAndFilename: string | undefined;
protected nodesByType: Map<typeof AbstractNode, AbstractNode[]>;
protected ignoredErrors: Error[];
protected options: FusionParserOptions;
protected constructor(lexer: Lexer, contextPathAndFilename: string | undefined, options?: FusionParserOptions);
static parse(sourceCode: string, contextPathAndFilename?: string | undefined, options?: FusionParserOptions): FusionFile;
protected consume(): Token;
/**
* Accepts a token of a given type.
* The Lexer will look up the regex for the token and try to match it on the current string.
* First match wins.
*
* @param {number} tokenType
* @return bool
*/
protected accept(tokenType: number, debug?: boolean): boolean;
/**
* Expects a token of a given type.
* The Lexer will look up the regex for the token and try to match it on the current string.
* First match wins.
*
* @param {number} tokenType
* @return Token
* @throws ParserUnexpectedCharException
*/
protected expect(tokenType: number): Token;
/**
* Checks, if the token type matches the current, if so consume it and return true.
* @param {number} tokenType
* @return bool|null
*/
protected lazyExpect(tokenType: number): boolean;
protected lazyBigGap(): Comment[];
protected lazySmallGap(): Comment | undefined;
protected parsePropertyDocumentationDefinition(parent: AbstractNode): PropertyDocumentationDefinition;
protected parsePrototypeDocumentationDefinition(parent: AbstractNode): PrototypeDocumentationDefinition;
protected parseComment(): Comment;
protected parseFusionFile(): FusionFile;
/**
* StatementList
* = ( Statement )*
*
* @param ?int stopLookahead When this tokenType is encountered the loop will be stopped
*/
protected parseStatementList(parent: AbstractNode, stopLookahead?: number | null, debugName?: string): StatementList;
/**
* Statement
* = IncludeStatement / ObjectStatement
*/
protected parseStatement(parent: AbstractNode): AbstractStatement;
/**
* IncludeStatement
* = INCLUDE ( STRING / CHAR / FILE_PATTERN ) EndOfStatement
*/
protected parseIncludeStatement(parent: AbstractNode): IncludeStatement;
/**
* ObjectStatement
* = ObjectPath ( ValueAssignment / ValueUnset / ValueCopy )? ( Block / EndOfStatement )
*/
protected parseObjectStatement(parent: AbstractNode): ObjectStatement;
/**
* ObjectPath
* = PathSegment ( '.' PathSegment )*
*
*/
protected parseObjectPath(parent: AbstractNode): ObjectPath;
/**
* PathSegment
* = ( PROTOTYPE_START FUSION_OBJECT_NAME ')' / OBJECT_PATH_PART / '@' OBJECT_PATH_PART / STRING / CHAR )
*/
protected parsePathSegment(): AbstractPathSegment;
protected parseValueAssignment(parent: AbstractNode): ValueAssignment;
/**
* PathValue
* = ( CHAR / STRING / DSL_EXPRESSION / FusionObject / EelExpression )
*/
protected parsePathValue(): AbstractPathValue;
protected parseDslExpression(): DslExpressionValue;
protected parseValueUnset(parent: AbstractNode): ValueUnset;
protected parseValueCopy(parent: AbstractNode): ValueCopy;
protected parseAssignedObjectPath(parent: AbstractNode): AssignedObjectPath;
/**
* Block:
* = '{' StatementList? '}'
*/
protected parseBlock(parent: AbstractNode, debugName?: string): Block;
/**
* EndOfStatement
* = ( EOF / NEWLINE )
*/
protected parseEndOfStatement(debugFrom?: string): void;
protected createPosition(): NodePosition;
protected endPosition(position: NodePosition, offset?: number): NodePosition;
protected addNodeToNodesByType(node: AbstractNode): void;
protected flushNodesByType(): Map<typeof AbstractNode, AbstractNode[]>;
}