@domorium/validator 1.1.0 → 1.3.0
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/CHANGELOG.md +51 -0
- package/dist/index.cjs.js +2 -2
- package/dist/index.esm.js +612 -479
- package/dist/parser/ast.d.ts +63 -0
- package/dist/parser/index.d.ts +2 -2
- package/dist/parser/lineIndex.d.ts +9 -0
- package/dist/validator/date-v7.d.ts +8 -0
- package/dist/validator/rule-node.d.ts +5 -0
- package/package.json +1 -1
- package/dist/parser/parser.d.ts +0 -7
- package/dist/parser/visitor.d.ts +0 -43
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { IToken } from "@chevrotain/types";
|
|
2
|
+
import { TokenNames } from "./lexer";
|
|
3
|
+
interface Position {
|
|
4
|
+
line: number;
|
|
5
|
+
character: number;
|
|
6
|
+
}
|
|
7
|
+
export interface Range {
|
|
8
|
+
start: Position;
|
|
9
|
+
end: Position;
|
|
10
|
+
}
|
|
11
|
+
export interface ASTToken {
|
|
12
|
+
name: TokenNames;
|
|
13
|
+
/** Character offset of the first character. */
|
|
14
|
+
startOffset: number;
|
|
15
|
+
/** Character offset just past the last character. */
|
|
16
|
+
endOffset: number;
|
|
17
|
+
/** Derived from the offsets; see the note on ASTNode. */
|
|
18
|
+
readonly range: Range;
|
|
19
|
+
value: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ASTNode {
|
|
22
|
+
startOffset: number;
|
|
23
|
+
endOffset: number;
|
|
24
|
+
/**
|
|
25
|
+
* Line and character are computed on access rather than stored. A large
|
|
26
|
+
* document has millions of tokens, and a stored range costs three objects
|
|
27
|
+
* apiece — that alone was most of the syntax tree's memory. Reading `range`
|
|
28
|
+
* in a tight loop allocates; prefer the offsets there.
|
|
29
|
+
*/
|
|
30
|
+
readonly range: Range;
|
|
31
|
+
tokens: Partial<Record<TokenNames, ASTToken>>;
|
|
32
|
+
parent?: ASTNode;
|
|
33
|
+
children: ASTNode[];
|
|
34
|
+
level: number;
|
|
35
|
+
}
|
|
36
|
+
export interface AstResult {
|
|
37
|
+
nodes: ASTNode[];
|
|
38
|
+
pointers: Map<string, ASTNode[]>;
|
|
39
|
+
xrefs: Map<string, ASTToken[]>;
|
|
40
|
+
/** Lines that carry no level, which GEDCOM requires on every line. */
|
|
41
|
+
malformed: ASTNode[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Resolves a node's logical value by following CONT (new line) and CONC
|
|
45
|
+
* (concatenation) continuation children in document order, per the GEDCOM
|
|
46
|
+
* line-continuation rules.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveValue(node: ASTNode): string;
|
|
49
|
+
/**
|
|
50
|
+
* Builds the syntax tree straight from the token stream.
|
|
51
|
+
*
|
|
52
|
+
* There is no grammar to speak of: a GEDCOM line is
|
|
53
|
+
* `level [@xref@] TAG [value]`, and the lexer's modes already decide which is
|
|
54
|
+
* which. A parse tree in between was a second pass over 2.8 million tokens
|
|
55
|
+
* for a 15.6 MB document, and building the real tree from it a third — 543 ms
|
|
56
|
+
* and much of another 828 ms, to add nothing the tokens did not already say.
|
|
57
|
+
*
|
|
58
|
+
* Lines are found by offset against the line index rather than by looking for
|
|
59
|
+
* a level, so a line that has no level still becomes a node and is reported,
|
|
60
|
+
* instead of ending the parse and taking the rest of the document with it.
|
|
61
|
+
*/
|
|
62
|
+
export declare function buildAst(tokens: IToken[], text: string): AstResult;
|
|
63
|
+
export {};
|
package/dist/parser/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { ASTNode, ASTToken } from "./
|
|
2
|
-
export { resolveValue } from "./
|
|
1
|
+
export type { ASTNode, ASTToken } from "./ast";
|
|
2
|
+
export { resolveValue } from "./ast";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Position } from "../types/position";
|
|
2
|
+
/**
|
|
3
|
+
* Offsets at which each line of a document starts. Storing one number per line
|
|
4
|
+
* lets the syntax tree keep character offsets instead of a line/character pair
|
|
5
|
+
* per token, which is where most of a large document's memory went.
|
|
6
|
+
*/
|
|
7
|
+
export type LineIndex = Int32Array;
|
|
8
|
+
export declare function createLineIndex(text: string): LineIndex;
|
|
9
|
+
export declare function offsetToPosition(index: LineIndex, offset: number): Position;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GedcomScheme } from "../schemes/schema-types";
|
|
2
|
+
export declare function isValidDateValue(value: string, scheme: GedcomScheme): boolean;
|
|
3
|
+
export declare function isValidDatePeriod(value: string, scheme: GedcomScheme): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* `DateExact` names no calendar and takes no epoch: it is day, month and year in
|
|
6
|
+
* the Gregorian calendar, and all three are required.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isValidDateExact(value: string, scheme: GedcomScheme): boolean;
|
|
@@ -5,12 +5,17 @@ type FieldType = "boolean" | "string" | "nonNegativeInteger" | "select" | "multi
|
|
|
5
5
|
export declare class RuleNode {
|
|
6
6
|
private readonly scheme;
|
|
7
7
|
pointers: ASTNode[];
|
|
8
|
+
private readonly pointerMap;
|
|
8
9
|
constructor(scheme: GedcomScheme, pointers: Map<string, ASTNode[]>);
|
|
10
|
+
/** Whether `xref` names a record of the kind this pointer type expects. */
|
|
11
|
+
private isPointerTarget;
|
|
9
12
|
getFieldType(tagType: GedcomType): {
|
|
10
13
|
type: FieldType;
|
|
11
14
|
isList: boolean;
|
|
12
15
|
to: GedcomType | undefined;
|
|
13
16
|
};
|
|
17
|
+
private isGedcom7Payload;
|
|
18
|
+
private mayOmitPayload;
|
|
14
19
|
getAvailableValues(tagType: GedcomType): string[] | null;
|
|
15
20
|
/**
|
|
16
21
|
* CONT/CONC are universal line-continuation tags: they are deliberately
|
package/package.json
CHANGED
package/dist/parser/parser.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CstNode, CstParser, ParserMethod } from "chevrotain";
|
|
2
|
-
import { TokenVocabulary } from "@chevrotain/types";
|
|
3
|
-
export declare class GedcomParser extends CstParser {
|
|
4
|
-
root: ParserMethod<[], CstNode>;
|
|
5
|
-
line: ParserMethod<[], CstNode>;
|
|
6
|
-
constructor(lexerDefinition: TokenVocabulary);
|
|
7
|
-
}
|
package/dist/parser/visitor.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { CstNode } from "chevrotain";
|
|
2
|
-
import { CstElement } from "@chevrotain/types";
|
|
3
|
-
import { TokenNames } from "./lexer";
|
|
4
|
-
declare const BaseGedcomVisitor: new (...args: any[]) => import("chevrotain").ICstVisitor<any, any>;
|
|
5
|
-
interface Position {
|
|
6
|
-
line: number;
|
|
7
|
-
character: number;
|
|
8
|
-
}
|
|
9
|
-
export interface Range {
|
|
10
|
-
start: Position;
|
|
11
|
-
end: Position;
|
|
12
|
-
}
|
|
13
|
-
export interface ASTToken {
|
|
14
|
-
name: TokenNames;
|
|
15
|
-
range: Range;
|
|
16
|
-
value: string;
|
|
17
|
-
}
|
|
18
|
-
export interface ASTNode {
|
|
19
|
-
range: Range;
|
|
20
|
-
tokens: Partial<Record<TokenNames, ASTToken>>;
|
|
21
|
-
parent?: ASTNode;
|
|
22
|
-
children: ASTNode[];
|
|
23
|
-
level: number;
|
|
24
|
-
}
|
|
25
|
-
export interface VisitorResult {
|
|
26
|
-
nodes: ASTNode[];
|
|
27
|
-
pointers: Map<string, ASTNode[]>;
|
|
28
|
-
xrefs: Map<string, ASTToken[]>;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Resolves a node's logical value by following CONT (new line) and CONC
|
|
32
|
-
* (concatenation) continuation children in document order, per the GEDCOM
|
|
33
|
-
* line-continuation rules.
|
|
34
|
-
*/
|
|
35
|
-
export declare function resolveValue(node: ASTNode): string;
|
|
36
|
-
export declare class GedcomVisitor extends BaseGedcomVisitor {
|
|
37
|
-
constructor();
|
|
38
|
-
root(ctx: CstNode | undefined): VisitorResult;
|
|
39
|
-
line({ children }: CstNode): ASTNode;
|
|
40
|
-
getTokens(elements?: CstElement[]): ASTToken[];
|
|
41
|
-
buildHierarchy(nodes: ASTNode[]): VisitorResult;
|
|
42
|
-
}
|
|
43
|
-
export {};
|