|
3 | 3 | ; {} optional - zero or more
|
4 | 4 | ; [] zero or one
|
5 | 5 | ; 'term' terminal
|
6 |
| -; non-term (no quotes) - non terminal |
7 |
| -; reg_ex(...) - regular expression |
| 6 | +; NON-TERMINAL |
| 7 | +; reg_ex(...) - regular |
8 | 8 |
|
9 |
| -S =: module |
| 9 | +S =: MODULE |
10 | 10 |
|
11 |
| -module =: 'module' symbol {i_decls} {decltypes} |
| 11 | +MODULE =: 'module' SYMBOL {IDECLS} {DECLTYPES} |
12 | 12 |
|
13 |
| -idecls =: 'include' (idecl_list | symbol_type) |
14 |
| -idelc_list =: '[' symbol {[,] symbol} ']' |
| 13 | +IDECLS =: 'include' (IDECL_LIST | SYMBOL) |
15 | 14 |
|
16 |
| -decl_types =: {var_decl | func_decl} |
| 15 | +IDELC_LIST =: '[' SYMBOL {[,] SYMBOL} ']' |
17 | 16 |
|
18 |
| -var_decl =: 'var' symbol_type [expression] |
| 17 | +DECLTYPES =: {VAR_DECL | FUNC_DECL} |
19 | 18 |
|
20 |
| -func_decl =: 'func' symbol_type symbol_list {expression} |
| 19 | +VAR_DECL =: 'var' SYMBOL_TYPE [EXPRESSION] |
21 | 20 |
|
22 |
| -expression =: literal |
23 |
| - | symbol_type |
24 |
| - | collection |
25 |
| - | func_call |
26 |
| - | if_expr |
27 |
| - | partial expr |
28 |
| - | group_expr |
29 |
| - | let_expr |
30 |
| - | match_expr |
31 |
| - | lambda_expr |
| 21 | +FUNC_DECL =: 'func' SYMBOL_TYPE SYMBOL_LIST {EXPRESSION} |
32 | 22 |
|
33 |
| -func_call =: func_prefix expression {expression} |
34 |
| -func_prefix =: symbol_type ":" |
| 23 | +EXPRESSION =: LITERAL |
| 24 | + | SYMBOL_TYPE |
| 25 | + | COLLECTION |
| 26 | + | FUNC_CALL |
| 27 | + | IF_EXPR |
| 28 | + | PARTIAL EXPR |
| 29 | + | GROUP_EXPR |
| 30 | + | LET_EXPR |
| 31 | + | MATCH_EXPR |
| 32 | + | LAMBDA_EXPR |
35 | 33 |
|
36 |
| -; Partials are interesting: |
37 |
| -; 1. If the symbol type is func reference and argument counts align, then it becomes a call |
38 |
| -; 2. If the symbol type is func reference and arg count in partial is less, it's a partial declaration |
39 |
| -; 3. If the symbol type is lambda reference and argument counts align, then it becomes a call |
40 |
| -; 4. If the symbol type is lambda reference and arg count in partial is less, it's a partial declaration |
41 |
| -; 5. Otherwise they are partial invocations |
| 34 | +FUNC_CALL =: FUNC_PREFIX EXPRESSION {EXPRESSION} |
42 | 35 |
|
43 |
| -partial_expr =: "(" (func_prefix | symbol_type) {expression} ")" |
| 36 | +PARTIAL_EXPR =: "(" SYMBOL_TYPE {EXPRESSION} ")" |
44 | 37 |
|
45 |
| -group_expr =: "@(" expression {expression} ")" |
| 38 | +GROUP_EXPR =: "@(" EXPRESSION {EXPRESSION} ")" |
46 | 39 |
|
47 |
| -let_expr =: "let" [symbol_type] "[" symbol_type expression {symbol_type expression} "]" expression |
| 40 | +LET_EXPR =: "let" [SYMBOL_TYPE] "[" SYMBOL_TYPE EXPRESSION {SYMBOL_TYPE EXPRESSION} "]" EXPRESSION |
48 | 41 |
|
49 |
| -match_expr =: 'match' [symbol_type] expression match_pair |
| 42 | +MATCH_EXPR =: 'match' [SYMBOL_TYPE] EXPRESSION MATCH_PAIR |
50 | 43 |
|
51 |
| -match_pair =: '|' expression expression {match_pair} |
52 |
| - | ':default' expression |
| 44 | +MATCH_PAIR =: '|' EXPRESSION EXPRESSION {MATCH_PAIR} |
| 45 | + | ':default' EXPRESSION |
53 | 46 |
|
54 |
| -; Lambdas my be interesting: |
55 |
| -; 1. If the body has not references to funcargs, letargs, letresult it's straight up |
56 |
| -; 2. Otherwise it is a closure. Closures need free variable management: |
57 |
| -; 1. Each free variable inserts into the begining of the declared symbol_list |
58 |
| -; 2. It needs to imbue those free vars at the point of declaration |
| 47 | +LAMBDA_EXPR =: '^' SYMBOL_LIST EXPRESSION |
59 | 48 |
|
60 |
| -lambda_expr =: '^' symbol_list expression |
| 49 | +COLLECTION =: MAP_COLLECTION |
| 50 | + | LIST_COLLECTION |
| 51 | + | VECTOR_COLLECTION |
| 52 | + | SET_COLLECTION |
61 | 53 |
|
62 |
| -symbol_list =: "[" "]" |
63 |
| - | "[" symbol_type {[,] symbol_type} "]" |
64 |
| - |
65 |
| -symbol_type =: symbol ; foo |
66 |
| - | reg_ex([a-zA-Z][a-zA-Z0-9_]+!) ; fo_o! |
67 |
| - | reg_ex([a-zA-Z][a-zA-Z0-9_]+\?) ; f_oo? |
68 |
| - |
69 |
| -symbol =: reg_ex([a-zA-Z]([a-zA-Z0-9_]*)?) |
70 |
| - |
71 |
| -collection =: map_collection |
72 |
| - | list_collection |
73 |
| - | vector_collection |
74 |
| - | set_collection |
75 |
| - |
76 |
| -map_collection =: "{" expression expression {[,] expression expression} "}" |
| 54 | +MAP_COLLECTION =: "{" EXPRESSION EXPRESSION {[,] EXPRESSION EXPRESSION} "}" |
77 | 55 | | "{" "}"
|
78 | 56 |
|
79 |
| -list_collection =: "[" expression {[,] expression } "]" |
| 57 | +LIST_COLLECTION =: "[" EXPRESSION {[,] EXPRESSION } "]" |
80 | 58 | | "[" "]"
|
81 | 59 |
|
82 |
| -set_collection =: "#{" expression {[,] expression} "}" |
| 60 | +SET_COLLECTION =: "#{" EXPRESSION {[,] EXPRESSION} "}" |
83 | 61 | | "#{" "}"
|
84 | 62 |
|
85 |
| -vector_collection =: "<" expression {[,] expression} ">" |
| 63 | +VECTOR_COLLECTION =: "<" EXPRESSION {[,] EXPRESSION} ">" |
86 | 64 | | "<" ">"
|
87 | 65 |
|
88 |
| -literal =: integer ; 1234 |
89 |
| - | real ; 0.1, 19.52, 1.39489384938493849384983 |
90 |
| - | hex ; 0x9ab5 |
91 |
| - | bit ; 0b01010101 |
92 |
| - | string ; "Something in quotes" |
93 |
| - | keyword ; :master |
94 |
| - | char ; 'c', 'd', '1' |
| 66 | +LITERAL =: INTEGER |
| 67 | + | REAL |
| 68 | + | HEX |
| 69 | + | BIT |
| 70 | + | STRING |
| 71 | + | KEYWORD |
| 72 | + | CHAR |
| 73 | + |
| 74 | +SYMBOL_LIST =: "[" "]" |
| 75 | + | "[" SYMBOL_TYPE {[,] SYMBOL_TYPE} "]" |
| 76 | + |
| 77 | +SYMBOL_TYPE =: SYMBOL |
| 78 | + | reg_ex("[a-zA-Z][a-zA-Z0-9_]+!") |
| 79 | + | reg_ex("[a-zA-Z][a-zA-Z0-9_]+\?") |
| 80 | + |
| 81 | +SYMBOL =: reg_ex("[a-zA-Z]([a-zA-Z0-9_]*)?") |
| 82 | + |
| 83 | +FUNC_PREFIX =: SYMBOL_TYPE ":" |
| 84 | + |
| 85 | +INTEGER =: regex("-?[0-9]+") |
| 86 | +REAL =: regex("-?(?:0|[1-9]\d*)\.\d*(?:[eE][+\-]?\d+)?") |
| 87 | +HEX =: regex("0[xX][0-9a-fA-F]+") |
| 88 | +BIT =: regex("0[bB][0-1]+") |
| 89 | +STRING =: regex("\"(.|\n)*?\"") |
| 90 | +KEYWORD =: regex(":[a-zA-Z]([a-zA-Z0-9_]*)?") |
| 91 | +CHAR =: regex("\'[0-9a-zA-Z]*?\'") |
| 92 | + |
| 93 | +COMMENT =: regex(";.*") |
| 94 | +IGNORES =: regex("[,\t ]+") |
| 95 | +NLCR =: regex("(\r\n|[\r\n])") |
0 commit comments