1 module commands.grammar;
2 import pegged.grammar;
3 
4 void main() {
5     asModule("commands.grammar", "../cli/source/commands/grammar", `
6 CommandParser:
7     Primary < FunctionCall
8     # Parens are optional if there's no args
9     FunctionCall < FunctionIdentifier (Args / EmptyArgs)?
10     FunctionIdentifier < FunctionNamespace? Function
11     FunctionNamespace < identifier :'.'
12     Function < identifier
13     # TO-DO: Expand this further
14     ArgTypes < String / HexLiteral / Number / FunctionCall
15     Args <- :'(' Line(ArgTypes, ',') :')'
16     EmptyArgs <- :'(' :')'
17 
18     # Base types taken from the PEGGED examples
19     String <~ :doublequote (!doublequote Char)* :doublequote
20     Char   <~ backslash ( doublequote  # '\' Escapes
21                         / quote
22                         / backslash
23                         / [bfnrt]
24                         / [0-2][0-7][0-7]
25                         / [0-7][0-7]?
26                         / 'x' Hex Hex
27                         / 'u' Hex Hex Hex Hex
28                         / 'U' Hex Hex Hex Hex Hex Hex Hex Hex
29                         )
30              / . # Or any char, really
31     Hex      < ~([0-9a-fA-F]+)
32     HexLiteral < '0x' Hex*
33     Number   < ~([0-9]+)
34 
35     Line(Elem, Sep = ' ') < Elem (:Sep Elem)*
36     `);
37 }