program = _{SOI ~ declare_statement* ~ EOI} statement = { if_statement | declare_block | expression } declare_statement = {SYMBOL ~ SYMBOL ~ modifiers? ~ declare_block} /*====================================================================================================================*/ declare_block = { "{" ~ declare_item* ~ "}" } declare_item = _{ SEPARATOR | declare_pair } declare_pair = { Key ~ COLON? ~ declare_block | Key ~ COLON? ~ list_block | Key ~ COLON ~ statement } Key = {StringNormal|SYMBOL|Integer} COLON = _{":"|":"} /*====================================================================================================================*/ if_statement = { kw_if ~ expression ~ block | kw_if ~ expression ~ block ~ else_statement } else_statement = { "else" ~ block } kw_if = { "若"| "如果" | "if" } kw_else = { "否则" | "else" } /*====================================================================================================================*/ expression = { term ~ (op_infix ~ term)* } term = { function | Special | Number | String | SYMBOL } function = { SYMBOL ~ "(" ~ (expression ~ (SEPARATOR ~ expression)* ~ SEPARATOR?)? ~ ")" | SYMBOL ~ "(" ~ (expression ~ (SEPARATOR ~ expression)* ~ SEPARATOR?)? ~ ")" } op_infix = _{ GT | LT | GEQ | LEQ | EQ | NE | ADD_ASSIGN | SUB_ASSIGN } GT = @{">" | "》" | "大于"} LT = @{"<" | "《" | "小于"} EQ = @{"==" | "等于" | "为" | "是"} NE = @{"!=" | "不等于" | "非" | "不是"} GEQ = @{">=" | "》=" | "大于等于" | "不小于"} LEQ = @{"<=" | "《=" | "小于等于" | "不大于"} ADD_ASSIGN = @{"+="} SUB_ASSIGN = @{"-="} /*====================================================================================================================*/ list_block = { "[" ~ (statement|SEPARATOR)* ~ "]" | "【" ~ (statement|SEPARATOR)* ~ "】" } block = { "{" ~ (statement|SEPARATOR)* ~ "}" } /*====================================================================================================================*/ ///#D19A66 Special = @{"true"|"false"|"null"|"真"|"假"|"空"} /*====================================================================================================================*/ //!#D19A66: SignedNumber Number = ${(Integer|Decimal) ~ SYMBOL?} Decimal = ${Integer ~ Dot ~ ("_"? ~ ASCII_DIGIT)*} Integer = @{"0"|ASCII_NONZERO_DIGIT ~ ("_"? ~ ASCII_DIGIT)*} Sign = @{"+"|"-"} /*====================================================================================================================*/ //!#3C963C: String|InlineString|InlineString2|RestLineText String = !{StringNormal} StringNormal = ${ "'" ~ NS* ~ "'" | "\"" ~ NS* ~ "\"" | "“" ~ NS* ~ "”" | "‹" ~ NS* ~ "›" | "«" ~ NS* ~ "»" } NS = @{ "\\u" ~ ASCII_HEX_DIGIT{4} | "\\u" ~ "{" ~(ASCII_HEX_DIGIT|SPACE_SEPARATOR)+ ~ "}" | "\\" ~ ANY | (!("'"|"\""|"\\") ~ ANY)+ } /*====================================================================================================================*/ ///#61AFEF SYMBOL = @{ (XID_START|"_") ~ (XID_CONTINUE|"_")* | "`" ~ ("\\" ~ ANY | !("\\"|"`") ~ ANY)* ~ "`" } modifiers = {SYMBOL+} Dot = @{"."} /*====================================================================================================================*/ ///Gray COMMENT = _{LineComment|OmitComment} WHITESPACE = _{NEWLINE|SPACE_SEPARATOR|"\t"} LineComment = ${("///"|"、") ~ (!NEWLINE ~ ANY)*} OmitComment = _{("//") ~ (!NEWLINE ~ ANY)*} MultiLineComment = ${"/*" ~ (MultiLineComment | !"*/" ~ ANY)* ~ "*/"} SEPARATOR = _{","|";"|","|";"}