This is a work in progress attempt to formalize the Handlebars AST in the style of the SpiderMonkey Parser API.
interface Node {
type: string;
loc: SourceLocation | null;
}
interface SourceLocation {
source: string | null;
start: Position;
end: Position;
}
interface Position {
line: uint >= 1;
column: uint >= 0;
}
interface Program <: Node {
type: "Program";
body: [ Statement ];
}
interface Statement <: Node { }
interface MustacheStatement <: Statement {
type: "MustacheStatement";
sexpr: Subexpression;
escaped: boolean;
}
interface BlockStatement <: Statement {
type: "BlockStatement";
sexpr: Subexpression;
program: Program;
inverse: Program | null;
}
interface PartialStatement <: Statement {
type: "PartialStatement";
sexpr: Subexpression;
}
interface ContentStatement <: Statement {
type: "ContentStatement";
value: string;
original: string;
}
interface CommentStatement <: Statement {
type: "CommentStatement";
value: string;
}
interface Expression <: Node { }
interface Subexpression <: Expression {
type: "Subexpression";
path: PathExpression;
params: [ Expression ];
hash: Hash;
}
interface PathExpression <: Expression {
type: "PathExpression";
data: boolean;
depth: uint >= 0;
parts: [ string ];
original: string;
}
interface Literal <: Expression { }
interface StringLiteral <: Literal {
type: "StringLiteral";
value: string;
}
interface BooleanLiteral <: Literal {
type: "BooleanLiteral";
value: boolean;
}
interface NumberLiteral <: Literal {
type: "NumberLiteral";
value: number;
}
interface Hash <: Node {
type: "Hash";
pairs: [ HashPair ];
}
interface HashPair <: Node {
type: "HashPair";
key: string;
value: Expression;
}