OILS / tools / find / find.pgen2 View on Github | oilshell.org

98 lines, 57 significant
1# Grammar for find
2
3# TODO: Could we encode numeric arguments into the grammar?
4# find apparently supports n +n -n.
5# #
6# Separately parsed:
7# - printf format string
8# - perm mode string
9# - regex and glob (passed through to libc, most likely)
10
11start: concatenation ENDMARKER
12
13concatenation: disjunction (',' disjunction)*
14
15disjunction: conjunction ('-o' conjunction)*
16
17# implicit and is allowed
18conjunction: negation (['-a'] negation)*
19
20negation: ['!'] group
21
22group: '(' concatenation ')' | expr
23
24expr: (
25# atoms
26 '-true'
27| '-false'
28
29# paths
30| '-name' STRING
31| '-iname' STRING
32
33| '-lname' STRING
34| '-ilname' STRING
35
36| '-path' STRING
37| '-ipath' STRING
38
39| '-regex' STRING
40| '-iregex' STRING
41
42| '-readable'
43| '-writable'
44| '-executable'
45
46# stat
47| '-empty'
48
49| '-size' STRING
50| '-type' STRING
51| '-xtype' STRING
52| '-perm' STRING
53
54| '-group' STRING
55| '-user' STRING
56| '-gid' STRING
57| '-uid' STRING
58| '-nogroup'
59| '-nouser'
60
61# for time (TODO)
62| '-amin' STRING
63| '-anewer' STRING
64| '-atime' STRING
65
66| '-cmin' STRING
67| '-cnewer' STRING
68| '-ctime' STRING
69
70| '-mmin' STRING
71| '-newer' STRING # note -newer not -mnewer
72| '-mtime' STRING
73| '-newerXY' STRING
74
75# actions
76| '-delete'
77| '-prune'
78| '-quit'
79
80| '-print'
81| '-print0'
82| '-printf' STRING
83| '-ls'
84
85| '-fprint' STRING
86| '-fprint0' STRING
87| '-fprintf' STRING STRING
88| '-fls' STRING
89
90 # TODO: can the command be empty?
91 # parse {}? That is replaced with the current filename.
92| '-exec' STRING* terminator
93| '-execdir' STRING* terminator
94| '-ok' STRING* terminator
95| '-okdir' STRING* terminator
96)
97
98terminator: ';' | '+'