proskomma-core 0.9.10 → 0.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +79 -0
- package/.gitattributes +2 -0
- package/docs/_config.yml +1 -0
- package/docs/index.md +3 -0
- package/docs/pk_edit_0_9.odt +0 -0
- package/docs/pk_edit_0_9.pdf +0 -0
- package/docs/proskomma_101_slideshow.odp +0 -0
- package/docs/proskomma_101_slideshow.pdf +0 -0
- package/docs/proskomma_edit_html.png +0 -0
- package/docs/proskomma_edit_html.svg +451 -0
- package/docs/proskomma_edit_reference.png +0 -0
- package/docs/proskomma_edit_reference.svg +349 -0
- package/docs/repo_logo.png +0 -0
- package/esm/package.json +3 -0
- package/esm/wrapper.mjs +5 -0
- package/index.cjs +6 -0
- package/package.json +18 -15
- package/src/graph/index.cjs +201 -0
- package/src/graph/lib/do_cv.cjs +249 -0
- package/src/graph/lib/dump.cjs +40 -0
- package/src/graph/lib/remake_blocks.cjs +57 -0
- package/src/graph/lib/sequence_chars.cjs +84 -0
- package/src/graph/lib/sort.cjs +39 -0
- package/src/graph/lib/tribos.cjs +97 -0
- package/src/graph/lib/tribos_expression.cjs +556 -0
- package/src/graph/lib/tribos_ohm_UNUSED.cjs +37 -0
- package/src/graph/lib/tribos_step.cjs +434 -0
- package/src/graph/mutations/add.cjs +91 -0
- package/src/graph/mutations/delete.cjs +61 -0
- package/src/graph/mutations/index.cjs +54 -0
- package/src/graph/mutations/rehash.cjs +17 -0
- package/src/graph/mutations/tags.cjs +120 -0
- package/src/graph/mutations/update.cjs +210 -0
- package/src/graph/mutations/versification.cjs +96 -0
- package/src/graph/queries/block.cjs +228 -0
- package/src/graph/queries/cIndex.cjs +87 -0
- package/src/graph/queries/cell.cjs +42 -0
- package/src/graph/queries/cv.cjs +19 -0
- package/src/graph/queries/cvBook.cjs +16 -0
- package/src/graph/queries/cvChapter.cjs +16 -0
- package/src/graph/queries/cvIndex.cjs +47 -0
- package/src/graph/queries/cvNavigation.cjs +116 -0
- package/src/graph/queries/cvVerseElement.cjs +84 -0
- package/src/graph/queries/cvVerses.cjs +14 -0
- package/src/graph/queries/doc_set.cjs +220 -0
- package/src/graph/queries/document.cjs +555 -0
- package/src/graph/queries/idParts.cjs +30 -0
- package/src/graph/queries/index.cjs +151 -0
- package/src/graph/queries/inputBlockSpec.cjs +17 -0
- package/src/graph/queries/inputItemObject.cjs +12 -0
- package/src/graph/queries/input_att_spec.cjs +14 -0
- package/src/graph/queries/input_key_matches.cjs +11 -0
- package/src/graph/queries/input_key_value.cjs +11 -0
- package/src/graph/queries/input_key_values.cjs +11 -0
- package/src/graph/queries/input_selector_spec.cjs +19 -0
- package/src/graph/queries/item.cjs +71 -0
- package/src/graph/queries/itemGroup.cjs +75 -0
- package/src/graph/queries/key_value.cjs +18 -0
- package/src/graph/queries/kv_entry.cjs +21 -0
- package/src/graph/queries/kv_sequence.cjs +151 -0
- package/src/graph/queries/node.cjs +44 -0
- package/src/graph/queries/orig.cjs +11 -0
- package/src/graph/queries/regex_index.cjs +18 -0
- package/src/graph/queries/row_equals_spec.cjs +11 -0
- package/src/graph/queries/row_match_spec.cjs +11 -0
- package/src/graph/queries/selector_spec.cjs +29 -0
- package/src/graph/queries/sequence.cjs +314 -0
- package/src/graph/queries/table_sequence.cjs +192 -0
- package/src/graph/queries/tree_sequence.cjs +58 -0
- package/src/graph/queries/verseNumber.cjs +44 -0
- package/src/graph/queries/verseRange.cjs +11 -0
- package/src/graph/queries/versification.cjs +25 -0
- package/src/index.cjs +583 -0
- package/src/model/doc_set.cjs +389 -0
- package/src/model/doc_set_helpers/block.cjs +232 -0
- package/src/model/doc_set_helpers/enum.cjs +87 -0
- package/src/model/doc_set_helpers/item.cjs +198 -0
- package/src/model/doc_set_helpers/rehash.cjs +53 -0
- package/src/model/doc_set_helpers/selectors.cjs +58 -0
- package/src/model/doc_set_helpers/serialize.cjs +22 -0
- package/src/model/doc_set_helpers/unsuccinctify.cjs +288 -0
- package/src/model/doc_set_helpers/update.cjs +290 -0
- package/src/model/document.cjs +369 -0
- package/src/model/document_helpers/blocks.cjs +135 -0
- package/src/model/document_helpers/chapter_verse.cjs +291 -0
- package/src/model/document_helpers/pre_enums.cjs +67 -0
- package/src/model/document_helpers/sequences.cjs +205 -0
- package/src/model/document_helpers/serialize_succinct.cjs +55 -0
- package/src/model/document_helpers/succinct_filter.cjs +102 -0
- package/src/model/versifications/eng_vrs.cjs +455 -0
- package/src/model/versifications/index.cjs +38 -0
- package/src/model/versifications/lxx_vrs.cjs +950 -0
- package/src/model/versifications/org_vrs.cjs +155 -0
- package/src/model/versifications/rsc_vrs.cjs +342 -0
- package/src/model/versifications/rso_vrs.cjs +541 -0
- package/src/model/versifications/vul_vrs.cjs +835 -0
- package/src/parser/index.cjs +506 -0
- package/src/parser/lexers/index.cjs +11 -0
- package/src/parser/lexers/lexingRegexes.cjs +45 -0
- package/src/parser/lexers/nodes.cjs +123 -0
- package/src/parser/lexers/object_for_fragment.cjs +123 -0
- package/src/parser/lexers/tsv.cjs +45 -0
- package/src/parser/lexers/usfm.cjs +17 -0
- package/src/parser/lexers/usx/index.cjs +7 -0
- package/src/parser/lexers/usx/usx_lexer.cjs +321 -0
- package/src/parser/lib/tokenize.cjs +37 -0
- package/src/parser/model/index.cjs +637 -0
- package/src/parser/parser_specs.cjs +781 -0
- package/src/pipelines/perf2x/index.cjs +7 -0
- package/src/pipelines/perf2x/perf2PkJsonPipeline.json +41 -0
- package/src/pipelines/perf2x/perf2usfmPipeline.json +65 -0
- package/src/transforms/calculateUsfmChapterPositions.cjs +106 -0
- package/src/transforms/index.cjs +9 -0
- package/src/transforms/perf2PkJson.cjs +534 -0
- package/src/transforms/perf2usfm.cjs +294 -0
- package/src/util/byteArray.cjs +251 -0
- package/src/util/canons.cjs +117 -0
- package/src/util/enums.cjs +41 -0
- package/src/util/generateId.cjs +6 -0
- package/src/util/graftDefs.cjs +15 -0
- package/src/util/index.cjs +29 -0
- package/src/util/inspectSuccinct.cjs +59 -0
- package/src/util/itemDefs.cjs +33 -0
- package/src/util/parserConstantDefs.cjs +30 -0
- package/src/util/scopeDefs.cjs +173 -0
- package/src/util/scriptlike/blocksSpec.cjs +192 -0
- package/src/util/scriptlike/dodson_lexicon.xsl +19 -0
- package/src/util/scriptlike/dodson_lexicon_to_entries.cjs +85 -0
- package/src/util/scriptlike/open_scriptures_hebrew_lexicon.xsl +28 -0
- package/src/util/scriptlike/open_scriptures_hebrew_lexicon_to_entries.cjs +85 -0
- package/src/util/succinct.cjs +159 -0
- package/src/util/tags.cjs +28 -0
- package/src/util/tokenDefs.cjs +27 -0
- package/src/util/versification.cjs +364 -0
- package/dist/index.js +0 -8
- package/dist/index.js.LICENSE.txt +0 -23
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const xre = require('xregexp');
|
|
2
|
+
|
|
3
|
+
const makePrintable = (subclass, matchedBits) => ({
|
|
4
|
+
subclass,
|
|
5
|
+
printValue: matchedBits[0],
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const makeChapter = (subclass, matchedBits) => ({
|
|
9
|
+
subclass,
|
|
10
|
+
numberString: matchedBits[2],
|
|
11
|
+
number: parseInt(matchedBits[2]),
|
|
12
|
+
printValue: `\\c ${matchedBits[2]}\n`,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const makeVerses = (subclass, matchedBits) => {
|
|
16
|
+
const ret = {
|
|
17
|
+
subclass,
|
|
18
|
+
numberString: matchedBits[2],
|
|
19
|
+
printValue: `\\v ${matchedBits[2]}\n`,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
if (ret.numberString.includes('-')) {
|
|
23
|
+
const [fromV, toV] = ret.numberString.split('-').map(v => parseInt(v));
|
|
24
|
+
ret.numbers = Array.from(Array((toV - fromV) + 1).keys()).map(v => v + fromV);
|
|
25
|
+
} else {
|
|
26
|
+
ret.numbers = [parseInt(ret.numberString)];
|
|
27
|
+
}
|
|
28
|
+
return ret;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const makeAttribute = (subclass, matchedBits) => {
|
|
32
|
+
let ret;
|
|
33
|
+
|
|
34
|
+
if (subclass === 'defaultAttribute') {
|
|
35
|
+
ret = {
|
|
36
|
+
subclass,
|
|
37
|
+
key: 'default',
|
|
38
|
+
valueString: matchedBits[2].trim().replace(/\//g, '÷'),
|
|
39
|
+
};
|
|
40
|
+
} else {
|
|
41
|
+
ret = {
|
|
42
|
+
subclass,
|
|
43
|
+
key: matchedBits[2],
|
|
44
|
+
valueString: matchedBits[3].trim().replace(/\//g, '÷'),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
ret.values = ret.valueString.split(',').map(vb => vb.trim());
|
|
48
|
+
ret.printValue = `| ${ret.key}="${ret.valueString}"`;
|
|
49
|
+
return ret;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const makePubChapter = (subclass, matchedBits) => ({
|
|
53
|
+
subclass,
|
|
54
|
+
numberString: matchedBits[2],
|
|
55
|
+
printValue: `\\cp ${matchedBits[2]}\n`,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const makeMilestone = (subclass, matchedBits) => {
|
|
59
|
+
const ret = {
|
|
60
|
+
subclass,
|
|
61
|
+
sOrE: null,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
if (subclass === 'endMilestoneMarker') {
|
|
65
|
+
ret.printValue = '\\*';
|
|
66
|
+
} else {
|
|
67
|
+
ret.tagName = matchedBits[2];
|
|
68
|
+
|
|
69
|
+
if (subclass === 'emptyMilestone') {
|
|
70
|
+
ret.printValue = `\\${ret.tagName}\\*`;
|
|
71
|
+
} else {
|
|
72
|
+
ret.printValue = `\\${ret.tagName}`;
|
|
73
|
+
ret.sOrE = matchedBits[3];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return ret;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const makeTag = (subclass, matchedBits) => {
|
|
80
|
+
const ret = {
|
|
81
|
+
subclass,
|
|
82
|
+
tagName: matchedBits[2],
|
|
83
|
+
isNested: false,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
if (ret.tagName.startsWith('+')) {
|
|
87
|
+
ret.isNested = true;
|
|
88
|
+
ret.tagName = ret.tagName.substring(1);
|
|
89
|
+
}
|
|
90
|
+
ret.tagLevel = matchedBits[3] !== '' ? parseInt(matchedBits[3]) : 1;
|
|
91
|
+
ret.fullTagName = `${ret.tagName}${matchedBits[3] === '1' ? '' : matchedBits[3]}`;
|
|
92
|
+
ret.printValue = subclass === 'startTag' ? `\\${ret.fullTagName} ` : `\\${ret.fullTagName}*`;
|
|
93
|
+
return ret;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const constructorForFragment = {
|
|
97
|
+
printable: makePrintable,
|
|
98
|
+
chapter: makeChapter,
|
|
99
|
+
pubchapter: makePubChapter,
|
|
100
|
+
verses: makeVerses,
|
|
101
|
+
tag: makeTag,
|
|
102
|
+
break: makePrintable,
|
|
103
|
+
milestone: makeMilestone,
|
|
104
|
+
attribute: makeAttribute,
|
|
105
|
+
bad: makePrintable,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const preTokenObjectForFragment = (fragment, lexingRegexes) => {
|
|
109
|
+
for (let n = 0; n < lexingRegexes.length; n++) {
|
|
110
|
+
let [tClass, tSubclass, tRE] = lexingRegexes[n];
|
|
111
|
+
let matchedBits = xre.exec(fragment, tRE, 0, 'sticky');
|
|
112
|
+
|
|
113
|
+
if (matchedBits) {
|
|
114
|
+
return constructorForFragment[tClass](tSubclass, matchedBits);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
throw new Error(`Could not match preToken fragment '${fragment}'`);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
module.exports = {
|
|
121
|
+
constructorForFragment,
|
|
122
|
+
preTokenObjectForFragment,
|
|
123
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const utils = require('../../util/index.cjs');
|
|
2
|
+
const { labelForScope } = utils.scopeDefs;
|
|
3
|
+
const { Sequence } = require('../model/index.cjs');
|
|
4
|
+
const { tokenizeString } = require('../lib/tokenize.cjs');
|
|
5
|
+
|
|
6
|
+
const parseTableToDocument = (str, parser, bookCode) => {
|
|
7
|
+
const { rows } = JSON.parse(str);
|
|
8
|
+
parser.headers.id = bookCode;
|
|
9
|
+
parser.headers.bookCode = bookCode;
|
|
10
|
+
const tableSequence = new Sequence('table');
|
|
11
|
+
|
|
12
|
+
for (const [rowN, row] of rows.entries()) {
|
|
13
|
+
for (const [cellN, cell] of row.entries()) {
|
|
14
|
+
tableSequence.newBlock(labelForScope('tTableRow', [`${rowN}`]));
|
|
15
|
+
const lastBlock = tableSequence.lastBlock();
|
|
16
|
+
|
|
17
|
+
lastBlock.addItem({
|
|
18
|
+
type: 'scope',
|
|
19
|
+
subType: 'start',
|
|
20
|
+
payload: `tTableCol/${cellN}`,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
for (const [token, tokenType] of tokenizeString(cell)) {
|
|
24
|
+
lastBlock.addItem({
|
|
25
|
+
type: 'token',
|
|
26
|
+
subType: tokenType,
|
|
27
|
+
payload: token,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
lastBlock.addItem({
|
|
31
|
+
type: 'scope',
|
|
32
|
+
subType: 'end',
|
|
33
|
+
payload: `tTableCol/${cellN}`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
parser.sequences.table.push(tableSequence);
|
|
38
|
+
parser.sequences.main.addBlockGraft({
|
|
39
|
+
type: 'graft',
|
|
40
|
+
subType: 'table',
|
|
41
|
+
payload: tableSequence.id,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = { parseTableToDocument };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const xre = require('xregexp');
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
lexingRegexes,
|
|
5
|
+
mainRegex,
|
|
6
|
+
} = require('./lexingRegexes.cjs');
|
|
7
|
+
const { preTokenObjectForFragment } = require('./object_for_fragment.cjs');
|
|
8
|
+
|
|
9
|
+
const parseUsfm = (str, parser) => {
|
|
10
|
+
const matches = xre.match(str, mainRegex, 'all');
|
|
11
|
+
|
|
12
|
+
for (let n = 0; n < matches.length; n++) {
|
|
13
|
+
parser.parseItem(preTokenObjectForFragment(matches[n], lexingRegexes));
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports = { parseUsfm };
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
const xre = require('xregexp');
|
|
2
|
+
|
|
3
|
+
const sax = require('sax');
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
lexingRegexes,
|
|
7
|
+
mainRegex,
|
|
8
|
+
} = require('../lexingRegexes.cjs');
|
|
9
|
+
const {
|
|
10
|
+
preTokenObjectForFragment,
|
|
11
|
+
constructorForFragment,
|
|
12
|
+
} = require('../object_for_fragment.cjs');
|
|
13
|
+
|
|
14
|
+
class UsxLexer {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.sax = sax.parser(true);
|
|
17
|
+
this.sax.ontext = text => this.handleSaxText(text);
|
|
18
|
+
this.sax.onopentag = ot => this.handleSaxOpenTag(ot);
|
|
19
|
+
this.sax.onclosetag = ct => this.handleSaxCloseTag(ct);
|
|
20
|
+
this.lexed = [];
|
|
21
|
+
this.elementStack = [];
|
|
22
|
+
this.currentText = '';
|
|
23
|
+
this.openTagHandlers = {
|
|
24
|
+
usx: this.ignoreHandler,
|
|
25
|
+
book: this.handleBookOpen,
|
|
26
|
+
chapter: this.handleChapter,
|
|
27
|
+
verse: this.handleVerses,
|
|
28
|
+
para: this.handleParaOpen,
|
|
29
|
+
table: this.ignoreHandler,
|
|
30
|
+
row: this.handleRowOpen,
|
|
31
|
+
cell: this.handleCellOpen,
|
|
32
|
+
char: this.handleCharOpen,
|
|
33
|
+
ms: this.handleMSOpen,
|
|
34
|
+
note: this.handleNoteOpen,
|
|
35
|
+
sidebar: this.handleSidebarOpen,
|
|
36
|
+
periph: this.notHandledHandler,
|
|
37
|
+
figure: this.handleFigureOpen,
|
|
38
|
+
optbreak: this.handleOptBreakOpen,
|
|
39
|
+
ref: this.ignoreHandler, // this.handleRefOpen,
|
|
40
|
+
};
|
|
41
|
+
this.closeTagHandlers = {
|
|
42
|
+
usx: this.ignoreHandler,
|
|
43
|
+
book: this.handleBookClose,
|
|
44
|
+
chapter: this.ignoreHandler,
|
|
45
|
+
verse: this.ignoreHandler,
|
|
46
|
+
para: this.handleParaClose,
|
|
47
|
+
table: this.ignoreHandler,
|
|
48
|
+
row: this.handleRowClose,
|
|
49
|
+
cell: this.handleCellClose,
|
|
50
|
+
char: this.handleCharClose,
|
|
51
|
+
ms: this.handleMSClose,
|
|
52
|
+
note: this.handleNoteClose,
|
|
53
|
+
sidebar: this.handleSidebarClose,
|
|
54
|
+
periph: this.notHandledHandler,
|
|
55
|
+
figure: this.handleFigureClose,
|
|
56
|
+
optbreak: this.handleOptBreakClose,
|
|
57
|
+
ref: this.ignoreHandler, // this.handleRefClose,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
lexAndParse(str, parser) {
|
|
62
|
+
this.parser = parser;
|
|
63
|
+
this.lexed = [];
|
|
64
|
+
this.elementStack = [];
|
|
65
|
+
this.sax.write(str).close();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
handleSaxText(text) {
|
|
69
|
+
this.currentText = this.replaceEntities(text);
|
|
70
|
+
xre.match(this.currentText, mainRegex, 'all')
|
|
71
|
+
.map(f => preTokenObjectForFragment(f, lexingRegexes))
|
|
72
|
+
.forEach(t => this.parser.parseItem(t));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
replaceEntities(text) {
|
|
76
|
+
return text.replace('<', '<')
|
|
77
|
+
.replace('>', '>')
|
|
78
|
+
.replace(''', '\'')
|
|
79
|
+
.replace('"', '"')
|
|
80
|
+
.replace('&', '&');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
handleSaxOpenTag(tagOb) {
|
|
84
|
+
const name = tagOb.name;
|
|
85
|
+
const atts = tagOb.attributes;
|
|
86
|
+
|
|
87
|
+
if (name in this.openTagHandlers) {
|
|
88
|
+
this.openTagHandlers[name](this, 'open', name, atts);
|
|
89
|
+
} else {
|
|
90
|
+
throw new Error(`Unexpected open element tag '${name}' in UsxParser`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
handleSaxCloseTag(name) {
|
|
95
|
+
this.closeTagHandlers[name](this, 'close', name);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
notHandledHandler(lexer, oOrC, tag) {
|
|
99
|
+
console.error(`WARNING: ${oOrC} element tag '${tag}' is not handled by UsxParser`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
stackPush(name, atts) {
|
|
103
|
+
this.elementStack.push([name, atts]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
stackPop() {
|
|
107
|
+
return this.elementStack.pop();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
splitTagNumber(fullTagName) {
|
|
111
|
+
const tagBits = xre.exec(fullTagName, xre('([^1-9]+)(.*)'));
|
|
112
|
+
const tagName = tagBits[1];
|
|
113
|
+
const tagNo = tagBits[2].length > 0 ? tagBits[2] : '1';
|
|
114
|
+
return [tagName, tagNo];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
ignoreHandler(lexer, oOrC, tag) {
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
handleParaOpen(lexer, oOrC, name, atts) {
|
|
121
|
+
lexer.currentText = '';
|
|
122
|
+
const [tagName, tagNo] = lexer.splitTagNumber(atts.style);
|
|
123
|
+
|
|
124
|
+
if (!['cp'].includes(tagName)) {
|
|
125
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, tagName, tagNo]));
|
|
126
|
+
}
|
|
127
|
+
lexer.stackPush(name, atts);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
handleParaClose(lexer) {
|
|
131
|
+
const sAtts = lexer.stackPop()[1];
|
|
132
|
+
const [tagName, tagNo] = lexer.splitTagNumber(sAtts.style);
|
|
133
|
+
|
|
134
|
+
if (['cp'].includes(tagName)) {
|
|
135
|
+
lexer.parser.parseItem(constructorForFragment.pubchapter('pubchapter', [null, null, lexer.currentText]));
|
|
136
|
+
} else {
|
|
137
|
+
lexer.parser.parseItem(constructorForFragment.tag('endTag', [null, null, tagName, tagNo]));
|
|
138
|
+
}
|
|
139
|
+
lexer.currentText = '';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
handleCharOpen(lexer, oOrC, name, atts) {
|
|
143
|
+
const [tagName, tagNo] = lexer.splitTagNumber(atts.style);
|
|
144
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, `+${tagName}`, tagNo]));
|
|
145
|
+
const ignoredAtts = ['sid', 'eid', 'style', 'srcloc', 'link-href', 'link-title', 'link-id', 'closed'];
|
|
146
|
+
|
|
147
|
+
for (const [attName, attValue] of Object.entries(atts)) {
|
|
148
|
+
if (!ignoredAtts.includes(attName)) {
|
|
149
|
+
lexer.parser.parseItem(constructorForFragment.attribute('attribute', [null, null, attName, attValue]));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
lexer.stackPush(name, atts);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
handleCharClose(lexer) {
|
|
156
|
+
const sAtts = lexer.stackPop()[1];
|
|
157
|
+
const [tagName, tagNo] = lexer.splitTagNumber(sAtts.style);
|
|
158
|
+
lexer.parser.parseItem(constructorForFragment.tag('endTag', [null, null, `+${tagName}`, tagNo]));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
handleRefOpen(lexer) {
|
|
162
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, 'xt', '']));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
handleRefClose(lexer) {
|
|
166
|
+
lexer.parser.parseItem(constructorForFragment.tag('endTag', [null, null, 'xt', '']));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
handleRowOpen(lexer, oOrC, name, atts) {
|
|
170
|
+
const [tagName, tagNo] = lexer.splitTagNumber(atts.style);
|
|
171
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, tagName, tagNo]));
|
|
172
|
+
lexer.stackPush(name, atts);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
handleRowClose(lexer) {
|
|
176
|
+
const sAtts = lexer.stackPop()[1];
|
|
177
|
+
const [tagName, tagNo] = lexer.splitTagNumber(sAtts.style);
|
|
178
|
+
lexer.parser.parseItem(constructorForFragment.tag('endTag', [null, null, tagName, tagNo]));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
handleCellOpen(lexer, oOrC, name, atts) {
|
|
182
|
+
const [tagName, tagNo] = lexer.splitTagNumber(atts.style);
|
|
183
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, tagName, tagNo]));
|
|
184
|
+
lexer.stackPush(name, atts);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
handleCellClose(lexer) {
|
|
188
|
+
const sAtts = lexer.stackPop()[1];
|
|
189
|
+
const [tagName, tagNo] = lexer.splitTagNumber(sAtts.style);
|
|
190
|
+
lexer.parser.parseItem(constructorForFragment.tag('endTag', [null, null, tagName, tagNo]));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
handleBookOpen(lexer, oOrC, name, atts) {
|
|
194
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, 'id', '']));
|
|
195
|
+
lexer.parser.parseItem(constructorForFragment.printable('wordLike', [atts.code]));
|
|
196
|
+
lexer.parser.parseItem(constructorForFragment.printable('lineSpace', [' ']));
|
|
197
|
+
lexer.stackPush(name, atts);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
handleBookClose(lexer) {
|
|
201
|
+
lexer.stackPop();
|
|
202
|
+
lexer.parser.parseItem(constructorForFragment.tag('endTag', [null, null, 'id', '']));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
handleChapter(lexer, oOrC, name, atts) {
|
|
206
|
+
if (atts.number) {
|
|
207
|
+
lexer.parser.parseItem(constructorForFragment.chapter('chapter', [null, null, atts.number]));
|
|
208
|
+
|
|
209
|
+
if (atts.pubnumber) {
|
|
210
|
+
lexer.parser.parseItem(constructorForFragment.pubchapter('pubchapter', [null, null, atts.pubnumber]));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (atts.altnumber) {
|
|
214
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, '+ca', '']));
|
|
215
|
+
lexer.parser.parseItem(constructorForFragment.printable('wordLike', [atts.altnumber]));
|
|
216
|
+
lexer.parser.parseItem(constructorForFragment.tag('endTag', [null, null, '+ca', '']));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
handleVerses(lexer, oOrC, name, atts) {
|
|
222
|
+
if (atts.number) {
|
|
223
|
+
lexer.parser.parseItem(constructorForFragment.verses('verses', [null, null, atts.number]));
|
|
224
|
+
|
|
225
|
+
if (atts.pubnumber) {
|
|
226
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, '+vp', '']));
|
|
227
|
+
lexer.parser.parseItem(constructorForFragment.printable('wordLike', [atts.pubnumber]));
|
|
228
|
+
lexer.parser.parseItem(constructorForFragment.tag('endTag', [null, null, '+vp', '']));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (atts.altnumber) {
|
|
232
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, '+va', '']));
|
|
233
|
+
lexer.parser.parseItem(constructorForFragment.printable('wordLike', [atts.altnumber]));
|
|
234
|
+
lexer.parser.parseItem(constructorForFragment.tag('endTag', [null, null, '+va', '']));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
handleNoteOpen(lexer, oOrC, name, atts) {
|
|
240
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, atts.style, '']));
|
|
241
|
+
lexer.parser.parseItem(constructorForFragment.printable('punctuation', [atts.caller]));
|
|
242
|
+
lexer.stackPush(name, atts);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
handleNoteClose(lexer) {
|
|
246
|
+
const sAtts = lexer.stackPop()[1];
|
|
247
|
+
lexer.parser.parseItem(constructorForFragment.tag('endTag', [null, null, sAtts.style, '']));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
handleSidebarOpen(lexer, oOrC, name, atts) {
|
|
251
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, 'esb', '']));
|
|
252
|
+
|
|
253
|
+
if ('category' in atts) {
|
|
254
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, 'cat', '']));
|
|
255
|
+
lexer.parser.parseItem(constructorForFragment.printable('wordLike', [atts.category]));
|
|
256
|
+
lexer.parser.parseItem(constructorForFragment.tag('endTag', [null, null, 'cat', '']));
|
|
257
|
+
}
|
|
258
|
+
lexer.stackPush(name, atts);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
handleSidebarClose(lexer) {
|
|
262
|
+
lexer.stackPop();
|
|
263
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, 'esbe', '']));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
handleMSOpen(lexer, oOrC, name, atts) {
|
|
267
|
+
let matchBits = xre.exec(atts.style, xre('(([a-z1-9]+)-([se]))'));
|
|
268
|
+
|
|
269
|
+
if (matchBits) {
|
|
270
|
+
const startMS = constructorForFragment.milestone('startMilestoneTag', [null, null, matchBits[2], matchBits[3]]);
|
|
271
|
+
lexer.parser.parseItem(startMS);
|
|
272
|
+
const ignoredAtts = ['sid', 'eid', 'style', 'srcloc', 'link-href', 'link-title', 'link-id'];
|
|
273
|
+
|
|
274
|
+
for (const [attName, attValue] of Object.entries(atts)) {
|
|
275
|
+
if (!ignoredAtts.includes(attName)) {
|
|
276
|
+
lexer.parser.parseItem(constructorForFragment.attribute('attribute', [null, null, attName, attValue]));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
lexer.parser.parseItem(constructorForFragment.milestone('endMilestoneMarker'));
|
|
280
|
+
} else {
|
|
281
|
+
const emptyMS = constructorForFragment.milestone('emptyMilestone', [null, null, atts.style, '']);
|
|
282
|
+
lexer.parser.parseItem(emptyMS);
|
|
283
|
+
}
|
|
284
|
+
lexer.stackPush(name, atts);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
handleMSClose(lexer) {
|
|
288
|
+
lexer.stackPop();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
handleFigureOpen(lexer, oOrC, name, atts) {
|
|
292
|
+
lexer.parser.parseItem(constructorForFragment.tag('startTag', [null, null, '+fig', '']));
|
|
293
|
+
|
|
294
|
+
for (const [attName, attValue] of Object.entries(atts)) {
|
|
295
|
+
if (attName === 'style') {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const scopeAttName = (attName === 'file') ? 'src' : attName;
|
|
300
|
+
lexer.parser.parseItem(constructorForFragment.attribute('attribute', [null, null, scopeAttName, attValue]));
|
|
301
|
+
}
|
|
302
|
+
lexer.stackPush(name, atts);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
handleFigureClose(lexer) {
|
|
306
|
+
const sAtts = lexer.stackPop()[1];
|
|
307
|
+
lexer.parser.parseItem(constructorForFragment.tag('endTag', [null, null, `+fig`, '']));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
handleOptBreakOpen(lexer, oOrC, name, atts) {
|
|
312
|
+
lexer.parser.parseItem(constructorForFragment.printable('softLineBreak', ['//']));
|
|
313
|
+
lexer.stackPush(name, atts);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
handleOptBreakClose(lexer) {
|
|
317
|
+
lexer.stackPop();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
module.exports = { UsxLexer };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const xre = require('xregexp');
|
|
2
|
+
const { lexingRegexes } = require('../lexers/lexingRegexes.cjs');
|
|
3
|
+
|
|
4
|
+
const tokenTypes = {};
|
|
5
|
+
const unionComponents = [];
|
|
6
|
+
|
|
7
|
+
for (const lr of lexingRegexes) {
|
|
8
|
+
if (['wordLike', 'eol', 'lineSpace', 'punctuation', 'unknown'].includes(lr[1])) {
|
|
9
|
+
tokenTypes[lr[1]] = xre(`^${lr[2].xregexp.source}$`);
|
|
10
|
+
unionComponents.push(lr[2]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const tokenizeString = str => {
|
|
15
|
+
const unionRegex = xre.union(unionComponents);
|
|
16
|
+
const ret = [];
|
|
17
|
+
|
|
18
|
+
for (const token of xre.match(str, unionRegex, 'all')) {
|
|
19
|
+
let tokenType;
|
|
20
|
+
|
|
21
|
+
if (xre.test(token, tokenTypes['wordLike'])) {
|
|
22
|
+
tokenType = 'wordLike';
|
|
23
|
+
} else if (xre.test(token, tokenTypes['punctuation'])) {
|
|
24
|
+
tokenType = 'punctuation';
|
|
25
|
+
} else if (xre.test(token, tokenTypes['lineSpace'])) {
|
|
26
|
+
tokenType = 'lineSpace';
|
|
27
|
+
} else if (xre.test(token, tokenTypes['eol'])) {
|
|
28
|
+
tokenType = 'eol';
|
|
29
|
+
} else {
|
|
30
|
+
tokenType = 'unknown';
|
|
31
|
+
}
|
|
32
|
+
ret.push([token, tokenType]);
|
|
33
|
+
}
|
|
34
|
+
return ret;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
module.exports = { tokenizeString };
|