-
Notifications
You must be signed in to change notification settings - Fork 2
/
ParserTools.spad
125 lines (119 loc) · 4.55 KB
/
ParserTools.spad
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
)abbrev package PRSTOOL ParserTools
++ Functions for s-expression parsing
ParserTools() : with
firstSymbol? : (SExpression, Symbol) -> Boolean
attribute? : SExpression -> Boolean
capsule? : SExpression -> Boolean
case? : SExpression -> Boolean
coerce? : SExpression -> Boolean
collect? : SExpression -> Boolean
domain? : SExpression -> Boolean
exit? : SExpression -> Boolean
function? : SExpression -> Boolean
functor? : SExpression -> Boolean
guard? : SExpression -> Boolean
has? : SExpression -> Boolean
ifelse? : SExpression -> Boolean
if? : SExpression -> Boolean
import? : SExpression -> Boolean
is? : SExpression -> Boolean
itor? : SExpression -> Boolean
join? : SExpression -> Boolean
lambda? : SExpression -> Boolean
let? : SExpression -> Boolean
listof? : SExpression -> Boolean
loop? : SExpression -> Boolean
macro? : SExpression -> Boolean
mapping? : SExpression -> Boolean
marker? : SExpression -> Boolean
nobranch? : SExpression -> Boolean
noderef? : SExpression -> Boolean
origin? : SExpression -> Boolean
package? : SExpression -> Boolean
pretend? : SExpression -> Boolean
progn? : SExpression -> Boolean
quote? : SExpression -> Boolean
record? : SExpression -> Boolean
repeat? : SExpression -> Boolean
segment? : SExpression -> Boolean
select? : SExpression -> Boolean
seq? : SExpression -> Boolean
signature? : SExpression -> Boolean
step? : SExpression -> Boolean
tuple? : SExpression -> Boolean
typevar? : SExpression -> Boolean
union? : SExpression -> Boolean
var? : SExpression -> Boolean
where? : SExpression -> Boolean
while? : SExpression -> Boolean
== add
firstSymbol? (ex, sym) ==
not list? ex => false
fst := car ex
not symbol? fst => false
symbol fst = sym
list_of_eq? : (SExpression, Symbol, Integer) -> Boolean
list_of_eq? (ex, sym, n) ==
not list? ex => false
not (#ex = n) => false
list_ex := destruct ex
not symbol? list_ex.1 => false
symbol list_ex.1 = sym
list_of_ge? : (SExpression, Symbol, Integer) -> Boolean
list_of_ge? (ex, sym, n) ==
not list? ex => false
#ex < n => false
list_ex := destruct ex
not symbol? list_ex.1 => false
symbol list_ex.1 = sym
nobranch? ex ==
symbol? ex and symbol ex = 'noBranch => true
false
functor? ex ==
list_of_ge?(ex, 'DEF, 5) =>
fifth := ex.5
firstSymbol? (car ex.3, 'Category) => true
capsule? fifth => true
list_of_eq?(fifth, 'add, 3) => true
false
attribute? ex == list_of_eq?(ex, 'ATTRIBUTE, 2)
capsule? ex == list_of_ge?(ex, 'CAPSULE, 1)
case? ex == list_of_eq?(ex, 'case, 3)
coerce? ex == list_of_eq?(ex, '::, 3)
collect? ex == list_of_ge?(ex, 'COLLECT, 3)
domain? ex == list_of_ge?(ex, 'CATEGORY, 2) and symbol ex.2 = 'domain
origin? ex == list_of_eq?(ex, 'Sel, 3)
exit? ex == list_of_eq?(ex, 'exit, 3)
function? ex == list_of_eq?(ex, 'DEF, 5)
guard? ex == list_of_eq?(ex, '|, 2)
has? ex == list_of_eq?(ex, 'has, 3)
ifelse? ex == list_of_eq?(ex, 'IF, 4)
import? ex == list_of_eq?(ex, 'import, 2)
is? ex == list_of_eq?(ex, 'is, 3)
itor? ex == list_of_eq?(ex, 'IN, 3)
join? ex == list_of_ge?(ex, 'Join, 2)
lambda? ex == list_of_eq?(ex, '+->, 3)
let? ex == list_of_eq?(ex, 'LET, 3)
listof? ex == list_of_ge?(ex, 'LISTOF, 3)
loop? ex == list_of_ge?(ex, 'REPEAT, 3)
macro? ex == list_of_eq?(ex, 'MDEF, 5)
mapping? ex == list_of_ge?(ex, 'Mapping, 2)
marker? ex == list_of_eq?(ex, '_@Marker, 2)
noderef? ex == list_of_eq?(ex, '_@NodeRef, 3)
package? ex == list_of_ge?(ex, 'CATEGORY, 2) and symbol ex.2 = 'package
pretend? ex == list_of_eq?(ex, 'pretend, 3)
progn? ex == list_of_ge?(ex, 'PROGN, 2)
quote? ex == list_of_eq?(ex, 'QUOTE, 2)
record? ex == list_of_ge?(ex, 'Record, 3)
repeat? ex == list_of_eq?(ex, 'REPEAT, 2)
select? ex == list_of_eq?(ex, '@, 3)
segment? ex == list_of_eq?(ex, 'SEGMENT, 2) or list_of_eq?(ex, 'SEGMENT, 3)
seq? ex == list_of_ge?(ex, 'SEQ, 2)
signature? ex == list_of_eq?(ex, 'SIGNATURE, 3) or list_of_eq?(ex, 'SIGNATURE, 4)
step? ex == list_of_eq?(ex, 'STEP, 4) or list_of_eq?(ex, 'STEP, 5)
tuple? ex == list_of_ge?(ex, '_@Tuple, 3)
typevar? ex == list_of_eq?(ex, '_@TypeVar, 3)
union? ex == list_of_ge?(ex, 'Union, 3)
var? ex == list_of_eq?(ex, ':, 3)
where? ex == list_of_eq?(ex, 'where, 3)
while? ex == list_of_eq?(ex, 'WHILE, 2)