forked from PuqiAR/Fig-TreeWalker
[Fix] 函数调用时参数类型求值使用错误作用域的问题
[Fix] 结构体定义中不可以使用自身类型的bug
[Fix] import导致的重定义bug
[Impl] Parser的precedence调整
[Feat] 支持运算符重载, impl Operator for xxx {} 具体见 lang.fig中解释
[Feat] 新增标准库 std.test
[Feat] 新增内置函数 type,接收一个参数,返回该参数的类型(value.type改名value._type)
推荐使用该函数替换 value._type
[Feat] 新增转换运算符 as,转换失败时抛出TypeError,支持任意类型到String、部分类型到Int, Double等等转换
TypeError实现了Error interface,可被用户catch
推荐使用该feat或与std.value标准库结合
[Feat] 抛出实现Error interface的错误现在会有不一样的log
[Feat] import增加cache(ast + source lines),但import一个module每次会得到不同对象而不是复用,请注意
31 lines
503 B
Plaintext
31 lines
503 B
Plaintext
/*
|
|
Example code: FigFig
|
|
|
|
Token.fig
|
|
Copyright (C) 2020-2026 PuqiAR
|
|
|
|
*/
|
|
struct _TokenTypes
|
|
{
|
|
public EOF = -1;
|
|
public Identifier = 0;
|
|
|
|
public StringLiteral = 1;
|
|
public NumberLiteral = 2;
|
|
public True = 3;
|
|
public False = 4;
|
|
public Null = 5;
|
|
|
|
public Plus = 6;
|
|
public Minus = 7;
|
|
public Asterisk = 8;
|
|
public Slash = 9;
|
|
}
|
|
|
|
public const TokenType := new _TokenTypes{};
|
|
|
|
public struct Token
|
|
{
|
|
public literal: String = "";
|
|
public type: Int = TokenType.EOF;
|
|
} |