-
Notifications
You must be signed in to change notification settings - Fork 3
/
$nameListHead.ts
176 lines (169 loc) · 7.97 KB
/
$nameListHead.ts
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
// import * as std from "../../../law/std";
import { __Text, ____PointerRanges } from "../../../node/el/controls";
import factory from "../factory";
import { WithErrorRule } from "../util";
const reAfterScope = /(?:の規定)?/;
const reAfterInferior = /(?:において|中(?:の)?|の|における)(?:(?:使用する)?用語は)?(?:解釈に(?:関して|ついて)は)?(?:、)?/;
const reAfterImport = /(?:において|で)使用する用語の例による(?:ほか|外)(?:、)?/;
const reNameRef = /(?:次|左)(?:の各号)?に掲げる用語(?:の意義|の定義)?は(?:、)?/;
const reOther = /(?:別段の定め(?:が|の)ある場合を除き)(?:、)?/;
const reDefRef = /(?:それぞれ)?(?:次|左|当該各号)(?:の各号)?(?:に|の)(?:定める|示す|掲げる|定義に従う|とおりとする|例による|意味に用いる|ところによる|ものとする)+。/;
const reCombinedWithoutInferiorIncludingImport = new RegExp(`^${reAfterScope.source}${reAfterInferior.source}(?:(.*?)${reAfterImport.source})?(?:${reNameRef.source})?(?:${reOther.source})?${reDefRef.source}$`);
const reCombinedBeforeInferior = new RegExp(`^${reAfterScope.source}(?:又は)$`);
const reCombinedAfterInferiorIncludingImport = new RegExp(`^(?:の規定)?${reAfterInferior.source}(?:(.*?)${reAfterImport.source})?(?:${reNameRef.source})?(?:${reOther.source})?${reDefRef.source}$`);
const reCombinedAfterInferiorBeforeImport = new RegExp(`^(?:の規定)?${reAfterInferior.source}(.*)$`);
const reCombinedBeforeImportWithoutInferior = new RegExp(`^${reAfterScope.source}${reAfterInferior.source}(.*)$`);
const reCombinedAfterImport = new RegExp(`^(.*)?${reAfterImport.source}(?:${reNameRef.source})?(?:${reOther.source})?${reDefRef.source}$`);
export const $nameListHead: WithErrorRule<{
pointerRanges: ____PointerRanges,
// pointerRangesModifier: __Parentheses | null,
}> = factory
.withName("nameListHead")
.sequence(s => s
.and(r => r
.oneMatch(({ item }) => {
if (
(item instanceof ____PointerRanges)
) { return item; } else { return null; }
})
, "pointerRanges")
// .and(r => r
// .zeroOrOne(r => r
// .oneMatch(({ item }) => {
// if (
// (item instanceof __Parentheses)
// ) { return item; } else { return null; }
// })
// )
// , "pointerRangesModifier")
.and(r => r
.choice(c => c
.orSequence(r => r
.and(r => r
.oneMatch(({ item }) => {
let m: RegExpExecArray | null;
if (
(item instanceof __Text)
&& (m = reCombinedWithoutInferiorIncludingImport.exec(item.text()))
) {
return [
item,
[m.index, m.index + m[0].length],
];
} else { return null; }
})
)
)
.orSequence(r => r
.andOmit(r => r
.oneMatch(({ item }) => {
if (
(item instanceof __Text)
&& reCombinedBeforeInferior.test(item.text())
) { return item; } else { return null; }
})
)
.andOmit(r => r
.oneMatch(({ item }) => {
if (
(item instanceof ____PointerRanges)
) { return item; } else { return null; }
})
)
.andOmit(r => r
.oneMatch(({ item }) => {
if (
(item instanceof __Text)
&& reCombinedAfterInferiorIncludingImport.test(item.text())
) { return item; } else { return null; }
})
)
)
.orSequence(r => r
.and(r => r
.oneMatch(({ item }) => {
if (
(item instanceof __Text)
&& reCombinedBeforeImportWithoutInferior.test(item.text())
) { return item; } else { return null; }
})
)
.and(r => r
.oneOrMore(r => r
.oneMatch(({ item }) => {
if (
!(
(item instanceof __Text)
&& reCombinedAfterImport.test(item.text())
)
) { return item; } else { return null; }
})
)
)
.and(r => r
.oneMatch(({ item }) => {
if (
(item instanceof __Text)
&& reCombinedAfterImport.test(item.text())
) { return item; } else { return null; }
})
)
)
.orSequence(r => r
.andOmit(r => r
.oneMatch(({ item }) => {
if (
(item instanceof __Text)
&& reCombinedBeforeInferior.test(item.text())
) { return item; } else { return null; }
})
)
.andOmit(r => r
.oneMatch(({ item }) => {
if (
(item instanceof ____PointerRanges)
) { return item; } else { return null; }
})
)
.and(r => r
.oneMatch(({ item }) => {
if (
(item instanceof __Text)
&& reCombinedAfterInferiorBeforeImport.test(item.text())
) { return item; } else { return null; }
})
)
.and(r => r
.zeroOrMore(r => r
.oneMatch(({ item }) => {
if (
!(
(item instanceof __Text)
&& !reCombinedAfterImport.test(item.text())
)
) { return item; } else { return null; }
})
)
)
.and(r => r
.oneMatch(({ item }) => {
if (
(item instanceof __Text)
&& reCombinedAfterImport.test(item.text())
) { return item; } else { return null; }
})
)
)
)
, "importSentenceChildren")
.action(({ pointerRanges, importSentenceChildren }) => {
const value = {
pointerRanges,
// pointerRangesModifier,
importSentenceChildren: importSentenceChildren ? importSentenceChildren.flat() : null,
};
return { value, errors: [] };
})
)
;
export default $nameListHead;