From 79bac8f30c5e60e1e96aeff01e863532737ca00e Mon Sep 17 00:00:00 2001 From: racemus Date: Fri, 7 Jul 2023 16:07:20 -0400 Subject: [PATCH] basic grammar, unsure of some parts --- grammar/root.peg | 132 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 grammar/root.peg diff --git a/grammar/root.peg b/grammar/root.peg new file mode 100644 index 0000000..79b5ed1 --- /dev/null +++ b/grammar/root.peg @@ -0,0 +1,132 @@ +// uwu peg me flushed emoji + +// common definitions, courtesy of lark-parser + +DIGIT: "0".."9" +HEXDIGIT: "a".."f"|"A".."F"|DIGIT + +INT: DIGIT+ +SIGNED_INT: ["+"|"-"] INT +DECIMAL: INT "." INT? | "." INT + +// float = /-?\d+(\.\d+)?([eE][+-]?\d+)?/ +_EXP: ("e"|"E") SIGNED_INT +FLOAT: INT _EXP | DECIMAL _EXP? +SIGNED_FLOAT: ["+"|"-"] FLOAT + +NUMBER: FLOAT | INT +SIGNED_NUMBER: ["+"|"-"] NUMBER + +// +// Strings +// +_STRING_INNER: /.*?/ +_STRING_ESC_INNER: _STRING_INNER /(? number + | "true" -> true + | "false" -> false + // IDK if we have null but uncomment below if so + // | "null" -> null +list: "[" [value ("," value)*] "]" +tuple: "(" [(value) ("," value)*] ")" + +dict: "{" [kv ("," kv)*] "}" +kv: string ":" value + +string: ESCAPED_STRING +atom: ":" name + +type: name + | name "[]" -> array + | name "?" -> optional + +expr: require + | assign + | create + | invoke + +constant: "constant" + +require: "require" name ("from" string)? +assign: constant? name "=" value + +create: name "with" create_args term +create_args: name ":" [(create | value) ("," create | value)*] + +invoke: (name ".")? name args +args: "(" [(value) ("," value)*] ")" + | [(value) ("," value)*] + +block: enum + | function + | class + | trait + +enum: "type" name [name*] term + +function: static? function_type body return? term + +static: "static" +return: "return" value +body: expr* + +function_type: "function" name params kind +params: "(" [("self" | property) ("," property)*] ")" +kind: "->" type + +class: name ("implements" name)? class_body term +class_cons: function +class_body: [class_cons] [class_prop*] [function*] +class_prop: name ":" type + +trait: name trait_body term +trait_body: [function_type*] \ No newline at end of file