psl-parser
Version:
A parser for the Profile Scripting Language
155 lines (154 loc) • 3.85 kB
TypeScript
import { Statement } from './statementParser';
import { Token } from './tokenizer';
/**
* Used for checking the type of Member at runtime
*/
export declare enum MemberClass {
method = 1,
parameter = 2,
property = 3,
declaration = 4,
column = 5,
table = 6,
proc = 7
}
/**
* A generic type that abstracts Method, Parameter, Declaration, etc
*/
export interface Member {
/**
* The Token representing the name of the member.
*/
id: Token;
/**
* An array of types. The 0 index represents the 0 node type.
* For trees the type of the nth node will be found at index n.
*/
types: Token[];
modifiers: Token[];
/**
* The member class to determine the type at runtime
*/
memberClass: MemberClass;
documentation?: string;
}
/**
* Contains information about a Method
*/
export interface Method extends Member {
/**
* The Token of the closing parenthesis after the declaration of all the Method's parameters.
*/
closeParen: Token;
/**
* Currently unused for Methods.
*/
types: Token[];
/**
* All the modifiers before the Method id, like "public", "static", "void", "String", etc.
*/
modifiers: Token[];
/**
* The parameters of the Method, each with their own typing and comment information.
*/
parameters: Parameter[];
/**
* The "type" declarations found within the body of the method.
* Only the location where they are declared is referenced.
*/
declarations: Declaration[];
/**
* The zero-based line where the Method begins
*/
line: number;
/**
* The last line of the Method, right before the start of a new Method
*/
endLine: number;
/**
* Whether the Method (label) is a batch label, such as "OPEN" or "EXEC"
*/
batch: boolean;
statements: Statement[];
}
/**
* A PROPERTYDEF declaration
*/
export interface Property extends Member {
/**
* The other Tokens in the declaration, currently unparsed.
*/
modifiers: Token[];
}
/**
* Represents a parameter, always belonging to a Method
*/
export interface Parameter extends Member {
/**
* If the req keyword is used
*/
req: boolean;
/**
* If the ret keyword is used
*/
ret: boolean;
/**
* If the literal keyword is used.
*/
literal: boolean;
/**
* The contents of the comment for the parameter, i.e.
* ```
* public String name(
* String p1 // a comment
* )
* ```
*/
comment: Token;
}
/**
* A type declaration, typically found within a method.
*/
export interface Declaration extends Member {
/**
* The other Tokens in the declaration, currently unparsed.
*/
modifiers: Token[];
}
/**
* An abstract syntax tree of a PSL document
*/
export interface ParsedDocument {
/**
* An array of Declarations that are not contained within a method.
* This will be empty for valid Profile 7.6 code but is maintained for compatibility.
*/
declarations: Declaration[];
/**
* An array of PROPERTYDEFs
*/
properties: Property[];
/**
* An array of the methods in the document
*/
methods: Method[];
/**
* All the tokens in the document, for reference.
*/
tokens: Token[];
/**
* The Token that represents the parent class.
*/
extending: Token;
/**
* The Token that represents the PSL package.
*/
pslPackage: string;
/**
* The tokens corresponding to line and block comments.
*/
comments: Token[];
}
export declare const NON_TYPE_MODIFIERS: string[];
export declare function parseText(sourceText: string): ParsedDocument;
export declare function parseFile(sourcePath: string): Promise<ParsedDocument>;