Last active
June 13, 2016 18:20
-
-
Save exerro/671a783de1bcf2a9310d08c41833374d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
types.parseMany [[ | |
HasPosition: { "source" = string, "line" = number, "character" = number, "strline" = string } | |
LeftUnaryExpressionOperator: "++" | "--" | "-" | "~" | "#" | "!" | |
TokenType: "String" | "Integer" | "Number" | "Identifier" | "Symbol" | "Hexadecimal" | "Binary" | "Byte" | |
ConstantExpressionType: "StringConstant" | "NumberConstant" | "IntegerConstant" | "ByteConstant" | "HexadecimalConstant" | "BinaryConstant" | |
ThrowExpression: { "type" = "ThrowExpression", "value" = Expression } & HasPosition | |
TypeOfExpression: { "type" = "TypeOfExpression", "rvalue" = Expression, "lvalue" = Expression | nil } & HasPosition | |
FunctionExpression: { "type" = "FunctionExpression", "class" = Type | nil, "parameters" = { number = { "name" = string, "class" = Type }, "body" = Block | nil } & HasPosition | |
TableExpression: { "type" = "TableExpression", "value" = { number = { Expression, Expression } } } & HasPosition | |
ArrayExpression: { "type" = "ArrayExpression", "value" = { number = Expression } } & HasPosition | |
BracketExpression: { "type" = "BracketExpression", "value" = Expression } | |
ConstantExpression: { "type" = ConstantExpressionType, "value" = string } & HasPosition | |
LeftUnaryExpression: { "type" = "LeftUnaryExpression", "value" = Expression, "operator" = LeftUnaryExpressionOperator } & HasPosition | |
RightUnaryExpression: { "type" = "RightUnaryExpression", "value" = Expression, "operator" = "++" | "--" } & HasPosition | |
BinaryExpression: { "type" = "BinaryExpression", "lvalue" = Expression, "rvalue" = Expression, "operator" = Expression } & HasPosition | |
PrimaryExpression: ConstantExpression | ThrowExpression | FunctionExpression | TypeOfExpression | BracketExpression | TableExpression | ArrayExpression | |
UnaryExpression: LeftUnaryExpression | RightUnaryExpression | |
Expression: PrimaryExpression | BinaryExpression | UnaryExpression | |
]] | |
local function const( type, value ) | |
return { type = type, value = value, source = "source", line = 1, character = 1, strline = tostring(value) } | |
end | |
assert( types.check( const( "NumberConstant", "5" ), "Expression" ) ) | |
assert( types.check( | |
const( "ThrowExpression", const( "NumberConstant", "5" ) ), | |
"Expression" | |
) ) | |
assert( types.check( | |
const( "ArrayExpression", { | |
const( "StringConstant", "abc" ); | |
const( "NumberConstant", "5" ); | |
} ), | |
"Expression" ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment