-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathlevel4.txt
48 lines (37 loc) · 2.01 KB
/
level4.txt
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
start: program
program: _EOL* command (" ")* (_EOL+ command (" ")*)* _EOL* //lines may end on spaces and might be separated by many newlines
?command: print
| ifelse
| ifs
| ask
| assign_list
| list_access_var
| assign //placing it here means print is will print 'is' and print is Felienne will print 'is Felienne'
| invalid
_EOL: "\r"?"\n"
print : "print " (quoted_text | list_access | var) (" " (quoted_text | list_access | var))*
ask : var " is ask " textwithspaces*
assign_list: var " is " textwithspaces ((", "|",") textwithspaces)+
assign : var " is " textwithspaces
invalid: /^(?!(print|if|and )).+/ //everything that is not the start of a regular command
// new commands for level 4
ifelse : "if " condition " " command " else " command
ifs: "if " condition " " command //'if' cannot be used in Python, hence the name of the rule is 'ifs'
condition: (equality_check|in_list_check) (" and " condition)*
list_access_var : var " is " var " at " (index | random)
equality_check: textwithoutspaces " is " textwithoutspaces
in_list_check: textwithoutspaces " in " var
var: NAME -> var
list_access : var " at " (index | random) -> list_access //todo: could be merged with list_acces_var?
index : NUMBER
random : "random"
textwithspaces: /([^\n,]+)/ -> text //anything can be parsed except for a newline and a comma for list separators
textwithoutspaces: /([^\n, ]+)/ -> text //anything can be parsed except for spaces (plus: a newline and a comma for list separators)
quoted_text_no_escape: /'([^']*)'/ -> text //simply all between quotes should this be used at earlier levels?
quoted_text: /'((?:[^\\']|\\.)*)'/ -> text //text can be between single quotes, but quotes may be escaped with \
%import common.LETTER // imports from terminal library
%import common.DIGIT // imports from terminal library
%import common.WS_INLINE // imports from terminal library
%import common.NEWLINE // imports from terminal library
%import common.SIGNED_INT -> NUMBER
%import common.CNAME -> NAME