-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.peg
270 lines (234 loc) · 13.4 KB
/
parser.peg
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#tentative Xextan PEG grammar
#Contributors: Filomena Rocca a.k.a. la Tsakap
# text level
text <- _? ( _? discourse)*
discourse <- ( _? sentence)+ _? VU_elidible ( _? connective _? discourse)?
sentence <- (illocutions? _? (clause (XU _?)? / fragment (XU _?)?)+ / illocutions _? &(illocution / end_of_input / DS_terminator)) ( _? connective _? &illocution sentence)?
# phrase/clause level
illocutions <- (discursive_illocution _? modal_illocution) / (modal_illocution _? discursive_illocution) / illocution
binder_phrase <- ( _? modifiers? binder_SS _? adverbs? (term_nucleus / ((preposition_term / adverbs) _?)* GU_elidible) / _? modifiers? binder_LS _? clause _? KU_elidible) ( _? connective _? binder_phrase)?
tag_phrase <- ( _? modifiers? tag_SS _? adverbs? (term_nucleus / ((preposition_term / adverbs) _?)* GU_elidible) / _? modifiers? tag_LS _? clause _? KU_elidible) ( _? connective _? tag_phrase)?
clause <- (fragment (XU _?)?)* frame+ (_? connective _? clause)?
frame <- predicate_term fragment?
predicate <- ( _? modifiers? (serial / verbal)) tag_phrase* (_? connective _? predicate)?
serial <- modifiers? _? (verbal / tag_phrase / binder_phrase) (tag_phrase / binder_phrase)* ( _? serial / _? modifiers? verbal)+
verbal <- (verb_modifier _?)? (verb _? binder_phrase* / verb_N _? clause _? KU_elidible) (_? connective _? verbal)?
fragment <- (noun_terms / adverbs)+
noun_terms <- (noun_term _?)+
noun_term <- preposition_term / free_nominal / connective_nominal
free_nominal <- (free_term / free_noun) (_? connective _? free_nominal)?
connective_nominal <- (free_connective_noun / free_connective_term) (_? connective _? free_nominal)?
term_nucleus <- _? ((preposition_term / adverbs) _?)* (free_term / (predicate / tag_phrase / binder_phrase / modifiers? (pronoun / quote / verb_L) tag_phrase*) _? GU_elidible)
predicate_term <- (_? modifiers? transmogrifier _? (term_nucleus / ((preposition_term / adverbs) _?)* GU_elidible) / (U_elidible _? (predicate / tag_phrase / binder_phrase) _? GU_elidible)) _? (connective _? predicate_term)?
preposition_term <- _? modifiers? (verb_modifier _?)? (preposition_SS _? (term_nucleus / ((preposition_term / adverbs) _?)* GU_elidible) / preposition_LS _? clause _? KU_elidible / preposition_SS _? &illocution discourse) _? (connective _? preposition_term)?
free_term <- _? modifiers? ((determiner_SS _?)+ (term_nucleus / ((preposition_term / adverbs) _?)* GU_elidible) / (determiner_SS _?)* determiner_LS _? clause _? KU_elidible / determiner_SS _? &illocution discourse) _? (connective _? free_term)?
free_connective_term <- _? connective _? (preposition_term / free_term)
free_noun <- SU_elidible modifiers? (pronoun / quote) _? tag_phrase* _? GU_elidible (_? connective _? free_noun)?
free_connective_noun <- _? connective _? free_noun
adverbs <- (adverb_phrase _?)+ / trans_adverb
adverb_phrase <- modifiers? adverbial (_? connective _? adverb_phrase)?
adverbial <- adverb_compound / adverb / onomatopoeia
trans_adverb <- _? modifiers &(connective? _? modifiers? illocution / SS_terminator / LS_terminator / DS_terminator / XU / end_of_input)
modifiers <- (modifier _?)+
quote <- modifiers? _? quoter _? quotation_mark quoted_text quotation_mark
quoted_text <- (!quotation_mark . )+ #: LEAF
U_elidible <- transmogrifier? #&( _? term_nucleus)
SU_elidible <- ( s u )? #&( _? (pronoun / quote))
GU_elidible <- SS_terminator? #/ &((_? adverbs _?)? (connective? _? modifiers? illocution / connective? _? modifiers? pronoun / connective? _? modifiers? predicate_term / connective _? modifiers? adverb_phrase / connective? _? modifiers? quoter / connective? _? modifiers? preposition / connective? _? modifiers? determiner / connective? _? modifiers? transmogrifier / connective _? (tag / binder) / LS_terminator / DS_terminator / ALL_terminator / end_of_input))
KU_elidible <- LS_terminator? #/ &(connective? _? modifiers? illocution / DS_terminator / XU / end_of_input)
VU_elidible <- DS_terminator? #/ &end_of_input
XU <- ALL_terminator
# word level
# verb class count: 3. root, compound, freeword
# particle class count: 21
# 1. illocution [discursive, modal, other], 2. pronoun, 3. suffix, 4. transmogrifier [elidible],
# 5. preposition (S/L), 6. determiner (S/L) [includes posessives and quantifiers], 7. tag (S/L),
# 8. binder (S/L), 9. numeral, 10. math operator, 11. general modifier,
# 12. verb modifier, 13. adverb [includes onomatopoeia], 14. adverb suffix, 15. connective, 16 quoter, 17. utility predicate (S/L),
# 18. short terminator, 19. long terminator, 20. discourse terminator, 21. multi-scope terminator
verb_N <- compound_N / root_N / utility_N
verb_H <- compound_H / root_H
verb_L <- compound_L / root_L
verb <- compound / root / utility / freeword / verb_H / trans_verb
compound_N <- root_N morpheme+
compound_H <- root_H morpheme+
compound_L <- root_L morpheme+
compound <- root morpheme+
trans_verb <- (((numeral / operator) _? )+ / possessive) suffix
morpheme <- root / suffix glottal?
root <- C V !root_H F !ANY_V / CL V
root_N <- C V_HN !root_H F !ANY_V / CL V_HN
root_H <- C V_H F !ANY_V / CL V_H !(CL V F (C / _ / end_of_input))
root_L <- C V_L F !ANY_V / CL V_L
freeword_start <- (FWC / sibilant m / GL) (HD / ANY_H) &((CL3 / FWCL / CL / F C / sibilant m / ANY_C) ANY_V) / ANY_C ANY_H &((!F (CL3 / CL) / FWCL / sibilant m / ANY_C) ANY_V) / glottal? (HD / ANY_H) &((CL3 / FWCL / CL / F C / sibilant m / ANY_C) ANY_V) / ANY_C HD &((CL3 / FWCL / CL / F C / sibilant m / ANY_C) ANY_V)
classic_freeword <- C (V / V_H) FWCL V F root*
freeword <- freeword_start ((CL3 / FWCL / CL / F C / ANY_C) (HD / ANY_H))* (CL3 / FWCL / CL / F C / sibilant m / ANY_C) (D / V / y) F? / classic_freeword # freeword classic(TM)
suffix <- x o !ANY_V / k o !ANY_V / z i !ANY_V / s a !ANY_V / s e !ANY_V / s i !ANY_V / f u !ANY_V / z u !ANY_V
pronoun <- !(root / freeword) (n i e / n i o / t u i / b a !ANY_V / b i !ANY_V / t i !ANY_V / d i !ANY_V / d u !ANY_V / g i !ANY_V / g o !ANY_V / v i !ANY_V / v o !ANY_V / x e !ANY_V / l e !ANY_V / l i !ANY_V / n i !ANY_V)
transmogrifier <- !(root / freeword) (h / glottal)? u !ANY_V
preposition <- preposition_LS / preposition_SS
determiner <- determiner_LS / determiner_SS
tag <- tag_SS / tag_LS
binder <- binder_SS / binder_LS
subject_marker_LS <- !(root / freeword) (t u o_N / t o_N i / t o_N u / (h / glottal)? o_N i / (h / glottal)? o_N u / t o_N !ANY_V / (h / glottal)? o_N !ANY_V)
object_marker_LS <- !(root / freeword) (t u e_N / t e_N i / t e_N u / (h / glottal)? e_N i / (h / glottal)? e_N u / t e_N !ANY_V / (h / glottal)? e_N !ANY_V)
dative_marker_LS <- !(root / freeword) (t u a_N / t a_N i / t a_N u / (h / glottal)? a_N i / (h / glottal)? a_N u / t a_N !ANY_V / (h / glottal)? a_N !ANY_V)
preposition_LS <- !(root / freeword) (subject_marker_LS / object_marker_LS / dative_marker_LS / p i o_N / k i e_N / x u e_N / p a_N i / f a_N i / v e_N i / v o_N i / x o_N i / p a_N u / p e_N u / k o_N u / f a_N u / x a_N u / n a_N u / n e_N u / g e_N i / f o_N !ANY_V / z a_N !ANY_V / f e_N !ANY_V / f i_N !ANY_V)
determiner_LS <- !(root / freeword) (b a_N u / k a_N u / l a_N i / q i_N !ANY_V / l a_N !ANY_V / l o_N !ANY_V / l u_N !ANY_V / t u_N !ANY_V / p o_N !ANY_V / q u_N !ANY_V)
subject_marker_SS <- !(root / freeword) (t u o / t o i / t o u / (h / glottal)? o i / (h / glottal)? o u / t o !ANY_V / (h / glottal)? o !ANY_V)
object_marker_SS <- !(root / freeword) (t u e / t e i / t e u / (h / glottal)? e i / (h / glottal)? e u / t e !ANY_V / (h / glottal)? e !ANY_V)
dative_marker_SS <- !(root / freeword) (t u a / t a i / t a u / (h / glottal)? a i / (h / glottal)? a u / t a !ANY_V / (h / glottal)? a !ANY_V)
preposition_SS <- !(root / freeword) (subject_marker_SS / object_marker_SS / dative_marker_SS / p i o / k i e / x u e / p a i / f a i / v e i / v o i / x o i / p a u / p e u / k o u / f a u / x a u / n a u / n e u / g e i / f o !ANY_V / z a !ANY_V / f e !ANY_V / f i !ANY_V)
determiner_SS <- !(root / freeword) (k a u / b a u / l a i / possessive / ((numeral / operator) _? )+ / quantifier / q i !ANY_V / l a !ANY_V / l o !ANY_V / l u !ANY_V / t u !ANY_V / p o !ANY_V / q u !ANY_V)
possessive <- l i a / n i a / d u a / g u a / v u a / x u a
numeral <- (z o u / x e u / q a u / d u o / t i e / k u a / p e i / l i o / x a i / b u i / g i u / n u e / n u !ANY_V / n e !ANY_V / arabic_numeral)
quantifier <- (s a u / s u a / s u e / s u i / s u o / s u !ANY_V)
illocution <- discursive_illocution / modal_illocution / z o i / q a i / q e i / q o i
discursive_illocution <- (h / glottal)? i !ANY_V / j e / j u
modal_illocution <- j a / j o / j i
modifier <- !(root / freeword) (f e i / s a i / s e i / s o i / b u !ANY_V / s o !ANY_V / n o !ANY_V)
verb_modifier <- !(root / freeword) (g a !ANY_V / g e !ANY_V)
adverb_compound <- adverb adverb_suffix
adverb <- !(root / freeword) (q e u / v o u / v a i / n o i / n a i / z e i / k e i / q u o / x o u / f o u / f i a / f i e / f i o / f i u / w a / w e / w i / w o / w u / n a !ANY_V / x a !ANY_V / f a !ANY_V / p a !ANY_V)
adverb_suffix <- (n i u / l u a / d i e)
connective <- !(root / freeword) (p o i / q a !ANY_V / q e !ANY_V / q o !ANY_V / z e !ANY_V / z o !ANY_V)
binder_SS <- !(root / freeword) (d o u / d o i / d e u / d e i / d a u / d a i / d o !ANY_V / d e !ANY_V / d a !ANY_V / p i !ANY_V)
tag_SS <- !(root / freeword) (k i !ANY_V / k e !ANY_V / p e !ANY_V)
binder_LS <- !(root / freeword) (d o_N u / d o_N i / d e_N u / d e_N i / d a_N u / d a_N i / d o_N !ANY_V / d e_N !ANY_V / d a_N !ANY_V / p i_N !ANY_V)
tag_LS <- !(root / freeword) (k i_N !ANY_V / k e_N !ANY_V / p e_N !ANY_V)
utility <- !(root / freeword) (b o !ANY_V / k a !ANY_V)
utility_N <- !(root / freeword) (b o_N !ANY_V / k a_N !ANY_V)
quoter <- (l o u / l a u)
operator <- !(root / freeword) (x i !ANY_V / p u !ANY_V)
onomatopoeia <- (CL3 / CL / ANY_C)? y ((CL3 / FWCL / CL / F C / ANY_C) y)* F?
SS_terminator <- !(root / freeword) g u !ANY_V
LS_terminator <- !(root / freeword) k u !ANY_V
DS_terminator <- !(root / freeword) v u !ANY_V
ALL_terminator <- !(root / freeword) x u !ANY_V
terminator <- SS_terminator / LS_terminator / DS_terminator
# character level
# All letters
ANY <- C / V / FWC / V_H / V_N / V_HN / y / y_H / y_HN / ['] / GL
# All consonants
ANY_C <- C / FWC / GL / glottal / r
# All vowels
ANY_V <- V / V_H / V_N / V_HN / y / y_H / y_HN / r
# All high tone
ANY_H <- V_H / V_HN / y_H / y_HN
# Consonants
C <- p / b / t / d / k / g / f / v / s / z / x / q / l / n
# Voiced consonants
voiced <- b / d / g / v / z / q
# Unvoiced
unvoiced <- p / t / k / f / s / x
#Sibilant
sibilant <- s / x / z / q
#Other fricative
fricative <- f / v
#Stop
stop <- p / t / k / b / d / g
#Sonorant
sonorant <- l / n
# Vowels
V <- a / e / i / o / u
#Glides off i
IG <- a / e / o / u
#Glides off u
UG <- a / e / i / o
#Glides into i/u
GV <- a / e / o
#Glides off i, high
IG_H <- (a_H / a_HN) / (e_H / e_HN) / (o_H / o_HN) / (u_H / u_HN)
#Glides off u, high
UG_H <- (a_H / a_HN) / (e_H / e_HN) / (i_H / i_HN) / (o_H / o_HN)
#Glides into i/u, high
GV_H <- (a_H / a_HN) / (e_H / e_HN) / (o_H / o_HN)
# Finals
F <- p / b &voiced / t / d &voiced / k / g &voiced / l / n
# Glides
GL <- j / w
# B Root Initial Clusters
CL <- &voiced sibilant (&voiced stop / sonorant) / &unvoiced sibilant (&unvoiced stop / sonorant) / (!(t / d) stop / fricative) l / d &voiced sibilant / t &unvoiced sibilant
# Freeword-only consonants
FWC <- h / m
# Classic freeword finals
FWF <- fricative / sibilant
# Classic freeword clusters
FWCL <- !illegal_CL &(voiced voiced / unvoiced unvoiced / . sonorant) FWF C
# Illegal clusters
illegal_CL <- x s / s x / z q / q z
#Freeword triples
CL3 <- &(CL / FWCL) C (CL / !( . (sibilant / fricative)) FWCL) / F CL
# Nasal vowels
V_N <- a_N / e_N / i_N / o_N / u_N
# High marked vowels
V_H <- a_H / e_H / i_H / o_H / u_H
# High nasal vowels
V_HN <- a_HN / e_HN / i_HN / o_HN / u_HN
# Low marked vowels
V_L <- a_L / e_L / i_L / o_L / u_L
#Diphthongs
D <- i IG / u UG / GV i / GV u / r (V / y) / (V / y) r !(V / y)
# High diphthongs
HD <- i IG_H / u UG_H / GV_H i / GV_H u / r (V_H / V_HN / y_H / y_HN) / (V_H / V_HN / y_H / y_HN) r !ANY_V
#case fixing of letters
p <- [pP] #: LEAF
b <- [bB] #: LEAF
t <- [tT] #: LEAF
d <- [dD] #: LEAF
k <- [kK] #: LEAF
g <- [gG] #: LEAF
f <- [fF] #: LEAF
v <- [vV] #: LEAF
s <- [sS] #: LEAF
z <- [zZ] #: LEAF
x <- [xX] #: LEAF
q <- [qQ] #: LEAF
l <- [lL] #: LEAF
n <- [nN] #: LEAF
j <- [jJ] #: LEAF
w <- [wW] #: LEAF
m <- [mM] #: LEAF
r <- [rR] !r #: LEAF
h <- [hH] #: LEAF
a <- [aA] #: LEAF
e <- [eE] #: LEAF
i <- [iI] #: LEAF
o <- [oO] #: LEAF
u <- [uU] #: LEAF
y <- [yY] #: LEAF
# High
a_H <- [áÁ] #: LEAF
e_H <- [éÉ] #: LEAF
i_H <- [íÍ] #: LEAF
o_H <- [óÓ] #: LEAF
u_H <- [úÚ] #: LEAF
y_H <- [ýÝ] #: LEAF
# Low
a_L <- [àÀ] #: LEAF
e_L <- [èÈ] #: LEAF
i_L <- [ìÌ] #: LEAF
o_L <- [òÒ] #: LEAF
u_L <- [ùÙ] #: LEAF
y_L <- [ỳỲ] #: LEAF
# Nasal
a_N <- [äÄãÃ] #: LEAF
e_N <- [ëËẽẼ] #: LEAF
i_N <- [ïÏĩĨ] #: LEAF
o_N <- [öÖõÕ] #: LEAF
u_N <- [üÜũŨ] #: LEAF
y_N <- [ÿŸỹỸ] #: LEAF
# High Nasal
a_HN <- [âÂ] #: LEAF
e_HN <- [êÊ] #: LEAF
i_HN <- [îÎ] #: LEAF
o_HN <- [ôÔ] #: LEAF
u_HN <- [ûÛ] #: LEAF
y_HN <- [ŷŶ] #: LEAF
punctuation <- [,.:;?!…'"-(){}]
new_line <- "\n"
arabic_numeral <- [1234567890] #: LEAF
_ <- ([ ] / punctuation / new_line)+ / end_of_input
quotation_mark <- [~]+ #: LEAF
glottal <- ['] #: LEAF
end_of_input <- !.