aboutsummaryrefslogtreecommitdiff
path: root/lib/grammar.txt
blob: d7208efc8f96e4793dc74d282bc4fa20259b2e19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
location: 
    | LOCATION_START EOL*
      line_statement*
      LOCATION_END EOL*
      EOF 

line_statement:
    | COMMENT EOL+              // A comment
    | COLUMN IDENT EOL*         // A location
    | instruction, line_sep     
    | inline_action  line_sep
    | ACT expression COLUMN EOL+ // ACT … END ACT
      line_statement*
      END ACT?                  // Yes you can have END or END ACT
      line_sep
    | IF expression COLUMN EOL+ // IF … END IF
      line_statement*
      elif*
      else
      END IF?                   // Yes you can have END or END IF
      line_sep

elif:
    | ELIF
      expression COLUMN EOL+
      line_statement*

else:
    | ELSE EOL+
      line_statement*
    |

line_sep:
    | EOL+
    | AMPERSAND+ EOL*


instruction:
    | expression
    | let_assignation
    | keyword argument(expression)

keyword:
    | STAR KEYWORD              // A keyword starting with *
    | KEYWORD

let_assignation:
    | assignation
      variable
      assignation_operator
      expression 

assignation: 
    |
    | LET 
    | SET

assignation_operator:
    | EQUAL
    | INCR                      // +=
    | DECR                      // -=

inline_action:
    | ACT expression COLUMN     // There is a recursive code here
    | IF expression COLUMN      // Because ACT: can contains an IF: etc
      (ELSE, instruction)?      // complicated to flatten here.

expression:
    | delimited(l_paren, expression, r_paren) 
    | unary_operator expression 
    | expression binary_operator expression 
    | literal  
    | integer 
    | variable
    | function argument(expression)

unary_operator:
    | OBJ
    | LOC
    | NO
    | MINUS
    | PLUS

binary_operator:
    | EQUAL
    | LT GT                 // Different
    | EXCLAMATION           // Neg, not a comment here
    | PLUS
    | MINUS
    | STAR                  // Not the first char of keyword here
    | DIV
    | MOD
    | GT
    | LT
    | GT EQUAL
    | LT EQUAL
    | EQUAL GT              // Alternative syntax
    | EQUAL LT              // Alternative syntax
    | AND
    | OR