-
Notifications
You must be signed in to change notification settings - Fork 2
/
grammar-test.pl
55 lines (50 loc) · 1.06 KB
/
grammar-test.pl
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
use v6;
grammar Grammar1 {
regex ANY { . }
regex SPACE { <[\ \t]> }
regex BREAK { \n }
regex EOL { \r? \n }
regex NON_BREAK { \N }
regex NON_SPACE_BREAK
{ <![\ \n]> }
regex LOWER { <[a..z]> }
regex UPPER { <[A..Z]> }
regex ALPHANUM { <[A..Za..z0..9]> }
regex WORD { <[A..Za..z0..9_]> }
regex DIGIT { <[0..9]> }
regex STAR { '*' }
regex DOT { '.' }
regex HASH { '#' }
regex BACK { '\\' }
regex SINGLE { "'" }
regex DOUBLE { '"' }
regex ESCAPE { <[0nt]> }
regex TOP {
<equation>
}
regex equation {
<lvalue>
<SPACE>+
<assignment>
<SPACE>+
<operand>
<SPACE>+
<operator>
<SPACE>+
<operand>
<SPACE>+
<ending>
<SPACE>*
<EOS>
}
regex operand {
<number> | <quoted_string> | <variable>
}
regex lvalue { <WORD>+ }
regex ending { ; }
}
class Actions {
}
my $text = "$foo = $bar + 'O HAI';\n";
my $match = Grammar1.parse($testml, :actions(Actions));
say $match.perl;