ast
Provides interface for parsing Blade code into Abstract Syntax Trees.
Properties
-
NEWLINE:
newline token
-
LPAREN:
left parenthesis (
(
) token -
RPAREN:
right parenthesis (
)
) token -
LBRACKET:
left bracket (
[
) token -
RBRACKET:
right bracket (
]
) token -
LBRACE:
left brace (
{
) token -
RBRACE:
right brace (
}
) token -
SEMICOLON:
semicolon (
;
) token -
COMMA:
comma (
,
) token -
BACKSLASH:
backslash (
\
) token -
BANG:
not (
!
) token -
BANG_EQ:
not equal (
!=
) token -
COLON:
colon (
:
) token -
AT:
at (
@
) token -
DOT:
dot (
.
) token -
RANGE:
range (
..
) token -
TRI_DOT:
tridot (
...
) token -
PLUS:
plus (
+
) token -
PLUS_EQ:
plus equal (
+=
) token -
INCREMENT:
increment (
++
) token -
MINUS:
minus (
-
) token -
MINUS_EQ:
minus equal (
-=
) token -
DECREMENT:
decrement (
--
) token -
MULTIPLY:
multiply (
*
) token -
MULTIPLY_EQ:
multiply equal (
*=
) token -
POW:
pow (
**
) token -
POW_EQ:
pow equal (
**=
) token -
DIVIDE:
divide (
/
) token -
DIVIDE_EQ:
divide equal (
/=
) token -
FLOOR:
floor division (
//
) token -
FLOOR_EQ:
floor divide equal (
//=
) token -
EQUAL:
assignment (
=
) token -
EQUAL_EQ:
equality (
==
) token -
LESS:
less than (
<
) token -
LESS_EQ:
less than or equal (
<=
) token -
LSHIFT:
left shift (
<<
) token -
LSHIFT_EQ:
left shift equal (
<<=
) token -
GREATER:
greater than (
>
) token -
GREATER_EQ:
greather than or equal (
>=
) token -
RSHIFT:
right shift (
>>
) token -
RSHIFT_EQ:
right shift equal (
>>=
) token -
PERCENT:
modulous (
%
) token -
PERCENT_EQ:
modulous equal (
%=
) token -
AMP:
ampersand (
&
) token -
AMP_EQ:
and equal (
&=
) token -
BAR:
bar (
|
) token -
BAR_EQ:
bar equal (
|=
) token -
TILDE:
tilde/not (
~
) token -
TILDE_EQ:
tilde equal (
~=
) token -
XOR:
exclusive or (
^
) token -
XOR_EQ:
exclusive or equal (
^=
) token -
QUESTION:
question (
?
) token -
AND:
and token
-
AS:
as token
-
ASSERT:
assert token
-
BREAK:
break token
-
CATCH:
catch token
-
CLASS:
class token
-
CONTINUE:
continue token
-
DEF:
def token
-
DEFAULT:
default token
-
RAISE:
raise token
-
DO:
do token
-
ECHO:
echo token
-
ELSE:
else token
-
FALSE:
false token
-
FOR:
for token
-
IF:
if token
-
IMPORT:
import token
-
IN:
in token
-
ITER:
iter token
-
NIL:
nil token
-
OR:
or token
-
PARENT:
parent token
-
RETURN:
return token
-
SELF:
self token
-
STATIC:
static token
-
TRUE:
true token
-
USING:
using token
-
VAR:
var token
-
WHEN:
when token
-
WHILE:
while token
-
LITERAL:
string literal token
-
REG_NUMBER:
regular number token
-
BIN_NUMBER:
binary number token
-
OCT_NUMBER:
octal number token
-
HEX_NUMBER:
hexadecimal number token
-
IDENTIFIER:
identifier token
-
DECORATOR:
decorator token
-
INTERPOLATION:
interpolation token
-
COMMENT:
comment token
-
DOC:
doc block token
-
EOF:
eof token
-
ERROR:
error token
-
EMPTY:
empty token
Functions
parse(source, path)
Parses a given source code and outputs Blade AST objects.
Parameters
- string source
- string? path
Returns
- ParseResult
json(source, path)
Parses the give source code and outputs a JSON representation of it's AST structure.
Parameters
- string source
- string? path
Returns
- string
Classes
class ParseResult
Represents the result of an ast parse operation.
Properties
- @printable
- @serializable
- @iterable
Methods
append(item)
Adds a new item to the parse result
Parameters
- 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.
Parameters
- 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.
Properties
- @printable
Fields
-
has_error ⇢ readonly bool:
Reports if an error was encountered in the scaner.
-
source ⇢ readonly string:
The string to being scanned.
Methods
Scanner(source, file) ⇢ Constructor
Parameters
- string source
scan()
Scans the source and returns a list of tokens.
Returns
- list[Token]
class Token
Blade source code token.
Properties
- @printable
- @serializable
Methods
Token(type, literal, line, file) ⇢ Constructor
Parameters
- number type
- string literal
- number line
class ParseException < Exception
Exception raised for errors during parsing.
Methods
ParseException(message, token) ⇢ Constructor
Parameters
- string message
- Token token
class Stmt
base Stmt class
class EchoStmt < Stmt
Echo Stmt representation.
Properties
- @serializable
Methods
EchoStmt(value) ⇢ Constructor
Parameters
- Stmt|any|nil value
class ExprStmt < Stmt
Expr Stmt representation.
Properties
- @serializable
Methods
ExprStmt(expr) ⇢ Constructor
Parameters
- Stmt|any|nil expr
class IfStmt < Stmt
If Stmt representation.
Properties
- @serializable
Methods
IfStmt(condition, truth, falsy) ⇢ Constructor
Parameters
- Stmt|any|nil condition
- Stmt|any|nil truth
- Stmt|any|nil falsy
class IterStmt < Stmt
Iter Stmt representation.
Properties
- @serializable
Methods
IterStmt(declaration, condition, iterator, body) ⇢ Constructor
Parameters
- Stmt|any|nil declaration
- Stmt|any|nil condition
- Stmt|any|nil iterator
- Stmt|any|nil body
class WhileStmt < Stmt
While Stmt representation.
Properties
- @serializable
Methods
WhileStmt(condition, body) ⇢ Constructor
Parameters
- Stmt|any|nil condition
- Stmt|any|nil body
class DoWhileStmt < Stmt
DoWhile Stmt representation.
Properties
- @serializable
Methods
DoWhileStmt(body, condition) ⇢ Constructor
Parameters
- Stmt|any|nil body
- Stmt|any|nil condition
class ForStmt < Stmt
For Stmt representation.
Properties
- @serializable
Methods
ForStmt(vars, iterable, body) ⇢ Constructor
Parameters
- Stmt|any|nil vars
- Stmt|any|nil iterable
- Stmt|any|nil body
class ContinueStmt < Stmt
Continue Stmt representation.
Properties
- @serializable
class BreakStmt < Stmt
Break Stmt representation.
Properties
- @serializable
class RaiseStmt < Stmt
Raise Stmt representation.
Properties
- @serializable
Methods
RaiseStmt(exception) ⇢ Constructor
Parameters
- Stmt|any|nil exception
class ReturnStmt < Stmt
Return Stmt representation.
Properties
- @serializable
Methods
ReturnStmt(value) ⇢ Constructor
Parameters
- Stmt|any|nil value
class AssertStmt < Stmt
Assert Stmt representation.
Properties
- @serializable
Methods
AssertStmt(expr, message) ⇢ Constructor
Parameters
- Stmt|any|nil expr
- Stmt|any|nil message
class UsingStmt < Stmt
Using Stmt representation.
Properties
- @serializable
Methods
UsingStmt(expr, cases, default_case) ⇢ Constructor
Parameters
- Stmt|any|nil expr
- Stmt|any|nil cases
- Stmt|any|nil default_case
class ImportStmt < Stmt
Import Stmt representation.
Properties
- @serializable
Methods
ImportStmt(path, elements) ⇢ Constructor
Parameters
- Stmt|any|nil path
- Stmt|any|nil elements
class CatchStmt < Stmt
Catch Stmt representation.
Properties
- @serializable
Methods
CatchStmt(body, var_name) ⇢ Constructor
Parameters
- Stmt|any|nil body
- Stmt|any|nil var_name
class CommentStmt < Stmt
Comment Stmt representation.
Properties
- @serializable
Methods
CommentStmt(data) ⇢ Constructor
Parameters
- Stmt|any|nil data
class BlockStmt < Stmt
Block Stmt representation.
Properties
- @serializable
Methods
BlockStmt(body) ⇢ Constructor
Parameters
- Stmt|any|nil body
class AssignStmt < Stmt
Assign Stmt representation.
Properties
- @serializable
Methods
AssignStmt(expr, type, value) ⇢ Constructor
Parameters
- Stmt|any|nil expr
- Stmt|any|nil type
- Stmt|any|nil value
class Defn
base Defn class
class DocDefn < Defn
Doc Defn representation.
Properties
- @serializable
Methods
DocDefn(data) ⇢ Constructor
Parameters
- Defn|any|nil data
class Parser
Parses raw Blade tokens and produces an Abstract Syntax Tree.
Properties
- @printable
Methods
Parser(tokens, path) ⇢ Constructor
Parameters
- 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.
Properties
- @serializable
Methods
VarDecl(name, value) ⇢ Constructor
Parameters
- Decl|any|nil name
- Decl|any|nil value
class FunctionDecl < Decl
Function Decl representation.
Properties
- @serializable
Methods
FunctionDecl(name, params, body) ⇢ Constructor
Parameters
- Decl|any|nil name
- Decl|any|nil params
- Decl|any|nil body
class MethodDecl < Decl
Method Decl representation.
Properties
- @serializable
Methods
MethodDecl(name, params, body, is_static) ⇢ Constructor
Parameters
- Decl|any|nil name
- Decl|any|nil params
- Decl|any|nil body
- Decl|any|nil is_static
class PropertyDecl < Decl
Property Decl representation.
Properties
- @serializable
Methods
PropertyDecl(name, value, is_static) ⇢ Constructor
Parameters
- Decl|any|nil name
- Decl|any|nil value
- Decl|any|nil is_static
class ClassDecl < Decl
Class Decl representation.
Properties
- @serializable
Methods
ClassDecl(name, superclass, properties, methods) ⇢ Constructor
Parameters
- 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.
Properties
- @serializable
Methods
BinaryExpr(left, op, right) ⇢ Constructor
Parameters
- Expr|any|nil left
- Expr|any|nil op
- Expr|any|nil right
class GroupExpr < Expr
Group Expr representation.
Properties
- @serializable
Methods
GroupExpr(expression) ⇢ Constructor
Parameters
- Expr|any|nil expression
class LiteralExpr < Expr
Literal Expr representation.
Properties
- @serializable
Methods
LiteralExpr(value) ⇢ Constructor
Parameters
- Expr|any|nil value
class IdentifierExpr < Expr
Identifier Expr representation.
Properties
- @serializable
Methods
IdentifierExpr(value) ⇢ Constructor
Parameters
- Expr|any|nil value
class UnaryExpr < Expr
Unary Expr representation.
Properties
- @serializable
Methods
UnaryExpr(op, right) ⇢ Constructor
Parameters
- Expr|any|nil op
- Expr|any|nil right
class ConditionExpr < Expr
Condition Expr representation.
Properties
- @serializable
Methods
ConditionExpr(expr, truth, falsy) ⇢ Constructor
Parameters
- Expr|any|nil expr
- Expr|any|nil truth
- Expr|any|nil falsy
class CallExpr < Expr
Call Expr representation.
Properties
- @serializable
Methods
CallExpr(callee, args) ⇢ Constructor
Parameters
- Expr|any|nil callee
- Expr|any|nil args
class GetExpr < Expr
Get Expr representation.
Properties
- @serializable
Methods
GetExpr(expr, name) ⇢ Constructor
Parameters
- Expr|any|nil expr
- Expr|any|nil name
class SetExpr < Expr
Set Expr representation.
Properties
- @serializable
Methods
SetExpr(expr, name, value) ⇢ Constructor
Parameters
- Expr|any|nil expr
- Expr|any|nil name
- Expr|any|nil value
class IndexExpr < Expr
Index Expr representation.
Properties
- @serializable
Methods
IndexExpr(args) ⇢ Constructor
Parameters
- Expr|any|nil args
class ListExpr < Expr
List Expr representation.
Properties
- @serializable
Methods
ListExpr(items) ⇢ Constructor
Parameters
- Expr|any|nil items
class DictExpr < Expr
Dict Expr representation.
Properties
- @serializable
Methods
DictExpr(keys, values) ⇢ Constructor
Parameters
- Expr|any|nil keys
- Expr|any|nil values
class InterpolationExpr < Expr
Interpolation Expr representation.
Properties
- @serializable
Methods
InterpolationExpr(data) ⇢ Constructor
Parameters
- Expr|any|nil data