-
Notifications
You must be signed in to change notification settings - Fork 3
/
$articleLine.ts
64 lines (60 loc) · 2.31 KB
/
$articleLine.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
import factory from "../factory";
import $indents from "./$indents";
import { ArticleLine } from "../../../node/cst/line";
import { $__, $_EOL } from "./lexical";
import $articleTitle from "./$articleTitle";
import $columnsOrSentences from "./$sentencesArray";
import makeRangesRule from "./makeRangesRule";
import { WithErrorRule } from "../util";
const { $ranges: $articleRanges } = makeRangesRule(() => $articleTitle);
/**
* The parser rule for {@link ArticleLine} that represents a first line of an article. Please see the source code for the detailed syntax, and the [test code](https://github.com/yamachig/Lawtext/blob/main/core/src/parser/cst/rules/$articleLine.spec.ts) for examples.
*/
export const $articleLine: WithErrorRule<ArticleLine> = factory
.withName("articleLine")
.sequence(s => s
.and(() => $indents, "indentsStruct")
.and( r => r
.sequence(s => s
.and(() => $articleRanges, "title")
.action(({ title, text }) => {
return {
value: text(),
errors: title.errors,
};
})
)
, "title")
.and(r => r
.zeroOrOne(r => r
.sequence(c => c
.and(() => $__, "midSpace")
.and(() => $columnsOrSentences, "columns")
.action(({ midSpace, columns }) => {
return { midSpace, columns };
})
)
)
, "contentStruct")
.and(() => $_EOL, "lineEndText")
.action(({ range, indentsStruct, title, contentStruct, lineEndText }) => {
const errors = [
...indentsStruct.errors,
...title.errors,
...(contentStruct?.columns.errors ?? []),
];
return {
value: new ArticleLine({
range: range(),
indentTexts: indentsStruct.value.indentTexts,
title: title.value,
midSpace: contentStruct?.midSpace ?? "",
sentencesArray: contentStruct?.columns.value ?? [],
lineEndText,
}),
errors,
};
})
)
;
export default $articleLine;