34 lines
1.6 KiB
EBNF
34 lines
1.6 KiB
EBNF
document = prologue, declaration, EOF ;
|
||
prologue = "TCS", version, ";" ;
|
||
version = integer, ".", integer ;
|
||
declaration = declaration_kind, identifier, block ;
|
||
declaration_kind = "PROGRAM" | "MODULE" | "PROTOCOL" | "COMPILER" | "EVENT" | "RECEIPT" ;
|
||
|
||
block = "{", { member }, "}" ;
|
||
member = identifier, ( typed_assignment | assignment | block ) ;
|
||
typed_assignment = ":", type_expression, "=", value, ";" ;
|
||
assignment = "=", value, ";" ;
|
||
|
||
value = string | integer | boolean | null | identifier | array | inline_object ;
|
||
array = "[", [ value, { ",", value } ], "]" ;
|
||
inline_object = "{", [ pair, { ",", pair } ], "}" ;
|
||
pair = identifier, ":", value ;
|
||
|
||
type_expression = identifier, [ "<", type_expression, { ",", type_expression }, ">" ] ;
|
||
boolean = "true" | "false" ;
|
||
null = "null" ;
|
||
integer = [ "-" ], digit, { digit } ;
|
||
identifier = identifier_start, { identifier_continue } ;
|
||
identifier_start = unicode_letter | "_" ;
|
||
identifier_continue = unicode_letter | digit | "_" | "-" | "." | "/" | ":" | "@" ;
|
||
string = '"', { json_string_character }, '"' ;
|
||
|
||
line_comment = "//", { any_character_except_line_break } ;
|
||
block_comment = "/*", { any_character_not_closing_comment }, "*/" ;
|
||
whitespace = " " | "\t" | "\n" | line_comment | block_comment ;
|
||
|
||
(* v0.1 语法闭合规则 *)
|
||
(* PROGRAM 必需区块由字段标准校验,不在词法解析时猜测。 *)
|
||
(* 未知顶层关键字、重复字段、重复区块和尾随 token 全部拒绝。 *)
|
||
(* 字段顺序不改变语义哈希;列表顺序保留。 *)
|
||
|