Next | Previous

ast

Provides interface for parsing Blade code into Abstract Syntax Trees.

Functions

ast.parse(source, path)

Parses a given source code and outputs Blade AST objects.

  • @params:
    • string source
    • string? path
  • @returns: ParseResult
ast.json(source, path)

Parses the give source code and outputs a JSON representation of it's AST structure.

  • @params:
    • string source
    • string? path
  • @returns: string

Classes

class ParseResult

Represents the result of an ast parse operation.

@printable, @serializable, @iterable

.append(item)

Adds a new item to the parse result

  • @params:
    • Expr|Decl|Defn|Stmt item
.length()

Returns the length of items in the parsed result.

  • @returns: number
.get(index)

Returns the item at the given ParseResult index or throws exception if out of range.

  • @params:
    • int index
  • @returns: Expr|Decl|Defn|Stmt
.to_list()

Returns the items in the ParseResult as a list object.

  • @returns: list[Expr|Decl|Defn|Stmt]
class Scanner

Blade source code scanner.

@printable

.has_errorreadonly bool

Reports if an error was encountered in the scaner.

.sourcereadonly string

The string to being scanned.

.Scanner(source, file) ➝ Constructor

ast.Scanner constructor

  • @params:
    • string source
.scan()

Scans the source and returns a list of tokens.

  • @returns: list[Token]
class Token

Blade source code token.

@printable, @serializable

.Token(type, literal, line, file) ➝ Constructor

ast.Token constructor

  • @params:
    • number type
    • string literal
    • number line
class ParseException < Exception

Exception raised for errors during parsing.

.ParseException(message, token) ➝ Constructor

ast.ParseException constructor

  • @params:
    • string message
    • Token token
class Stmt

base Stmt class

class EchoStmt < Stmt

Echo Stmt representation.

@serializable

.EchoStmt(value) ➝ Constructor

ast.EchoStmt constructor

  • @params:
    • Stmt|any|nil value
class ExprStmt < Stmt

Expr Stmt representation.

@serializable

.ExprStmt(expr) ➝ Constructor

ast.ExprStmt constructor

  • @params:
    • Stmt|any|nil expr
class IfStmt < Stmt

If Stmt representation.

@serializable

.IfStmt(condition, truth, falsy) ➝ Constructor

ast.IfStmt constructor

  • @params:
    • Stmt|any|nil condition
    • Stmt|any|nil truth
    • Stmt|any|nil falsy
class IterStmt < Stmt

Iter Stmt representation.

@serializable

.IterStmt(declaration, condition, iterator, body) ➝ Constructor

ast.IterStmt constructor

  • @params:
    • Stmt|any|nil declaration
    • Stmt|any|nil condition
    • Stmt|any|nil iterator
    • Stmt|any|nil body
class WhileStmt < Stmt

While Stmt representation.

@serializable

.WhileStmt(condition, body) ➝ Constructor

ast.WhileStmt constructor

  • @params:
    • Stmt|any|nil condition
    • Stmt|any|nil body
class DoWhileStmt < Stmt

DoWhile Stmt representation.

@serializable

.DoWhileStmt(body, condition) ➝ Constructor

ast.DoWhileStmt constructor

  • @params:
    • Stmt|any|nil body
    • Stmt|any|nil condition
class ForStmt < Stmt

For Stmt representation.

@serializable

.ForStmt(vars, iterable, body) ➝ Constructor

ast.ForStmt constructor

  • @params:
    • Stmt|any|nil vars
    • Stmt|any|nil iterable
    • Stmt|any|nil body
class ContinueStmt < Stmt

Continue Stmt representation.

@serializable

class BreakStmt < Stmt

Break Stmt representation.

@serializable

class RaiseStmt < Stmt

Raise Stmt representation.

@serializable

.RaiseStmt(exception) ➝ Constructor

ast.RaiseStmt constructor

  • @params:
    • Stmt|any|nil exception
class ReturnStmt < Stmt

Return Stmt representation.

@serializable

.ReturnStmt(value) ➝ Constructor

ast.ReturnStmt constructor

  • @params:
    • Stmt|any|nil value
class AssertStmt < Stmt

Assert Stmt representation.

@serializable

.AssertStmt(expr, message) ➝ Constructor

ast.AssertStmt constructor

  • @params:
    • Stmt|any|nil expr
    • Stmt|any|nil message
class UsingStmt < Stmt

Using Stmt representation.

@serializable

.UsingStmt(expr, cases, default_case) ➝ Constructor

ast.UsingStmt constructor

  • @params:
    • Stmt|any|nil expr
    • Stmt|any|nil cases
    • Stmt|any|nil default_case
class ImportStmt < Stmt

Import Stmt representation.

@serializable

.ImportStmt(path, elements) ➝ Constructor

ast.ImportStmt constructor

  • @params:
    • Stmt|any|nil path
    • Stmt|any|nil elements
class CatchStmt < Stmt

Catch Stmt representation.

@serializable

.CatchStmt(body, var_name) ➝ Constructor

ast.CatchStmt constructor

  • @params:
    • Stmt|any|nil body
    • Stmt|any|nil var_name
class CommentStmt < Stmt

Comment Stmt representation.

@serializable

.CommentStmt(data) ➝ Constructor

ast.CommentStmt constructor

  • @params:
    • Stmt|any|nil data
class BlockStmt < Stmt

Block Stmt representation.

@serializable

.BlockStmt(body) ➝ Constructor

ast.BlockStmt constructor

  • @params:
    • Stmt|any|nil body
class AssignStmt < Stmt

Assign Stmt representation.

@serializable

.AssignStmt(expr, type, value) ➝ Constructor

ast.AssignStmt constructor

  • @params:
    • Stmt|any|nil expr
    • Stmt|any|nil type
    • Stmt|any|nil value
class Defn

base Defn class

class DocDefn < Defn

Doc Defn representation.

@serializable

.DocDefn(data) ➝ Constructor

ast.DocDefn constructor

  • @params:
    • Defn|any|nil data
class Parser

Parses raw Blade tokens and produces an Abstract Syntax Tree.

@printable

.Parser(tokens, path) ➝ Constructor

ast.Parser constructor

  • @params:
    • list[Token] tokens
    • string? path
.parse()

Parses the raw source tokens passed into relevant class and outputs a stream of AST objects that can be one of Expr (expressions), Stmt (statements) or Decl (declarations).

  • @returns: ParseResult
class Decl

base Decl class

class VarDecl < Decl

Var Decl representation.

@serializable

.VarDecl(name, value) ➝ Constructor

ast.VarDecl constructor

  • @params:
    • Decl|any|nil name
    • Decl|any|nil value
class FunctionDecl < Decl

Function Decl representation.

@serializable

.FunctionDecl(name, params, body) ➝ Constructor

ast.FunctionDecl constructor

  • @params:
    • Decl|any|nil name
    • Decl|any|nil params
    • Decl|any|nil body
class MethodDecl < Decl

Method Decl representation.

@serializable

.MethodDecl(name, params, body, is_static) ➝ Constructor

ast.MethodDecl constructor

  • @params:
    • Decl|any|nil name
    • Decl|any|nil params
    • Decl|any|nil body
    • Decl|any|nil is_static
class PropertyDecl < Decl

Property Decl representation.

@serializable

.PropertyDecl(name, value, is_static) ➝ Constructor

ast.PropertyDecl constructor

  • @params:
    • Decl|any|nil name
    • Decl|any|nil value
    • Decl|any|nil is_static
class ClassDecl < Decl

Class Decl representation.

@serializable

.ClassDecl(name, superclass, properties, methods) ➝ Constructor

ast.ClassDecl constructor

  • @params:
    • Decl|any|nil name
    • Decl|any|nil superclass
    • Decl|any|nil properties
    • Decl|any|nil methods
class Expr

base Expr class

class BinaryExpr < Expr

Binary Expr representation.

@serializable

.BinaryExpr(left, op, right) ➝ Constructor

ast.BinaryExpr constructor

  • @params:
    • Expr|any|nil left
    • Expr|any|nil op
    • Expr|any|nil right
class GroupExpr < Expr

Group Expr representation.

@serializable

.GroupExpr(expression) ➝ Constructor

ast.GroupExpr constructor

  • @params:
    • Expr|any|nil expression
class LiteralExpr < Expr

Literal Expr representation.

@serializable

.LiteralExpr(value) ➝ Constructor

ast.LiteralExpr constructor

  • @params:
    • Expr|any|nil value
class IdentifierExpr < Expr

Identifier Expr representation.

@serializable

.IdentifierExpr(value) ➝ Constructor

ast.IdentifierExpr constructor

  • @params:
    • Expr|any|nil value
class UnaryExpr < Expr

Unary Expr representation.

@serializable

.UnaryExpr(op, right) ➝ Constructor

ast.UnaryExpr constructor

  • @params:
    • Expr|any|nil op
    • Expr|any|nil right
class ConditionExpr < Expr

Condition Expr representation.

@serializable

.ConditionExpr(expr, truth, falsy) ➝ Constructor

ast.ConditionExpr constructor

  • @params:
    • Expr|any|nil expr
    • Expr|any|nil truth
    • Expr|any|nil falsy
class CallExpr < Expr

Call Expr representation.

@serializable

.CallExpr(callee, args) ➝ Constructor

ast.CallExpr constructor

  • @params:
    • Expr|any|nil callee
    • Expr|any|nil args
class GetExpr < Expr

Get Expr representation.

@serializable

.GetExpr(expr, name) ➝ Constructor

ast.GetExpr constructor

  • @params:
    • Expr|any|nil expr
    • Expr|any|nil name
class SetExpr < Expr

Set Expr representation.

@serializable

.SetExpr(expr, name, value) ➝ Constructor

ast.SetExpr constructor

  • @params:
    • Expr|any|nil expr
    • Expr|any|nil name
    • Expr|any|nil value
class IndexExpr < Expr

Index Expr representation.

@serializable

.IndexExpr(args) ➝ Constructor

ast.IndexExpr constructor

  • @params:
    • Expr|any|nil args
class ListExpr < Expr

List Expr representation.

@serializable

.ListExpr(items) ➝ Constructor

ast.ListExpr constructor

  • @params:
    • Expr|any|nil items
class DictExpr < Expr

Dict Expr representation.

@serializable

.DictExpr(keys, values) ➝ Constructor

ast.DictExpr constructor

  • @params:
    • Expr|any|nil keys
    • Expr|any|nil values
class InterpolationExpr < Expr

Interpolation Expr representation.

@serializable

.InterpolationExpr(data) ➝ Constructor

ast.InterpolationExpr constructor

  • @params:
    • Expr|any|nil data