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 type { 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 = 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;