@ja-platform/parser-core 0.0.0-dev-20261021212654 → 0.0.0-dev-20261022223751
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/dist/@types/AttributeParseEvent.d.ts +5 -14
- package/dist/@types/ParseEvent.d.ts +11 -0
- package/dist/@types/attributes/Attribute.d.ts +9 -5
- package/dist/@types/attributes/ContentTextAttribute.d.ts +4 -6
- package/dist/@types/attributes/TextAttribute.d.ts +2 -2
- package/dist/@types/index.d.ts +5 -1
- package/dist/@types/input/AttributeInput.d.ts +28 -0
- package/dist/@types/input/AttributeParseContext.d.ts +21 -0
- package/dist/@types/input/NodeInput.d.ts +9 -0
- package/dist/@types/nodes/ContentNode.d.ts +5 -5
- package/dist/@types/nodes/Node.d.ts +17 -20
- package/dist/@types/nodes/NodeAlternatives.d.ts +4 -4
- package/dist/@types/parsed/ParsedArrayNode.d.ts +1 -1
- package/dist/@types/parsed/ParsedAttribute.d.ts +5 -8
- package/dist/@types/parsed/ParsedDiagnostic.d.ts +7 -3
- package/dist/@types/parsed/ParsedNode.d.ts +5 -7
- package/dist/@types/source/SourceReference.d.ts +9 -0
- package/dist/AttributeParseEvent.js.map +1 -1
- package/dist/{XMLParseEvent.js → ParseEvent.js} +1 -1
- package/dist/ParseEvent.js.map +1 -0
- package/dist/attributes/Attribute.js +33 -55
- package/dist/attributes/Attribute.js.map +1 -1
- package/dist/attributes/ContentTextAttribute.js +9 -24
- package/dist/attributes/ContentTextAttribute.js.map +1 -1
- package/dist/attributes/NumberAttribute.js +1 -1
- package/dist/attributes/NumberAttribute.js.map +1 -1
- package/dist/attributes/TextAttribute.js +11 -9
- package/dist/attributes/TextAttribute.js.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/input/AttributeInput.js +14 -0
- package/dist/input/AttributeInput.js.map +1 -0
- package/dist/input/AttributeParseContext.js +3 -0
- package/dist/input/AttributeParseContext.js.map +1 -0
- package/dist/input/NodeInput.js +3 -0
- package/dist/input/NodeInput.js.map +1 -0
- package/dist/nodes/ContentNode.js +13 -11
- package/dist/nodes/ContentNode.js.map +1 -1
- package/dist/nodes/Node.js +30 -35
- package/dist/nodes/Node.js.map +1 -1
- package/dist/nodes/NodeAlternatives.js +20 -20
- package/dist/nodes/NodeAlternatives.js.map +1 -1
- package/dist/parsed/ParsedArrayNode.js +4 -4
- package/dist/parsed/ParsedArrayNode.js.map +1 -1
- package/dist/parsed/ParsedAttribute.js +8 -6
- package/dist/parsed/ParsedAttribute.js.map +1 -1
- package/dist/parsed/ParsedDiagnostic.js +4 -2
- package/dist/parsed/ParsedDiagnostic.js.map +1 -1
- package/dist/parsed/ParsedNode.js +12 -12
- package/dist/parsed/ParsedNode.js.map +1 -1
- package/dist/source/SourceReference.js +3 -0
- package/dist/source/SourceReference.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -6
- package/dist/@types/XMLParseEvent.d.ts +0 -37
- package/dist/XMLParseEvent.js.map +0 -1
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
source: XMLPositional;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* An XML parse event with the input selected for an attribute codec.
|
|
10
|
-
*/
|
|
11
|
-
export interface AttributeParseEvent<Node extends ParsedNode<any, any> = any> extends XMLParseEvent<Node> {
|
|
12
|
-
input: AttributeParseInput & {
|
|
13
|
-
value: string;
|
|
14
|
-
};
|
|
1
|
+
import type { TextAttributeInput } from './input/AttributeInput';
|
|
2
|
+
import type { AttributeParseContext } from './input/AttributeParseContext';
|
|
3
|
+
export interface AttributeParseEvent {
|
|
4
|
+
input: TextAttributeInput;
|
|
5
|
+
context?: AttributeParseContext;
|
|
15
6
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { NodeInput } from './input/NodeInput';
|
|
2
|
+
import type { AttributeParseContext } from './input/AttributeParseContext';
|
|
3
|
+
import type { ParsedNode } from './parsed/ParsedNode';
|
|
4
|
+
import type { ValidationContext } from '@ja-platform/parser-expressions';
|
|
5
|
+
export interface ParseEvent extends AttributeParseContext {
|
|
6
|
+
input?: NodeInput;
|
|
7
|
+
parsedNode?: ParsedNode;
|
|
8
|
+
scope?: ValidationContext;
|
|
9
|
+
/** Prepare a node after its attributes and before its children are parsed. */
|
|
10
|
+
prepareNode?(node: ParsedNode): void;
|
|
11
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { NodeInput } from '../input/NodeInput';
|
|
2
|
+
import type { AttributeInput } from '../input/AttributeInput';
|
|
3
|
+
import type { AttributeParseContext } from '../input/AttributeParseContext';
|
|
4
|
+
import { AttributeParseEvent } from '../AttributeParseEvent';
|
|
3
5
|
import { AbstractExpression, ExpressionParser, ConstantExpression, EvaluatedExpression } from '@ja-platform/parser-expressions';
|
|
4
6
|
import { Type } from '@ja-platform/parser-type-system';
|
|
5
7
|
import { CommonEntity, CommonEntityListener, CommonEntityOptions } from '../entities/CommonEntity';
|
|
@@ -67,9 +69,11 @@ export declare class Attribute<G extends AttributeGenerics = AttributeGenerics>
|
|
|
67
69
|
normalizeValue(value: unknown): G['NormalizedValue'];
|
|
68
70
|
isEnclosedWith(checkerCB: (helper: NodeChecker) => boolean): boolean;
|
|
69
71
|
serialize(): any;
|
|
70
|
-
protected getParsedValue(event: AttributeParseEvent
|
|
72
|
+
protected getParsedValue(event: AttributeParseEvent): G['Value'];
|
|
71
73
|
stringify(value: G['Value'], parent: ParsedNode): StringifyDirective;
|
|
72
74
|
createParsedAttribute(options: ParsedAttributeOptions<G['Value'], this>): ParsedAttribute<G['Value'], this>;
|
|
73
|
-
protected getInput(
|
|
74
|
-
parse(
|
|
75
|
+
protected getInput(node?: NodeInput): AttributeInput | undefined;
|
|
76
|
+
parse(node?: NodeInput, context?: AttributeParseContext): ParsedAttribute<G["Value"], this>;
|
|
77
|
+
/** Instantiate an attribute from document input, or from its definition alone. */
|
|
78
|
+
parseInput(input?: AttributeInput, context?: AttributeParseContext): ParsedAttribute<G["Value"], this>;
|
|
75
79
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { NodeInput } from '../input/NodeInput';
|
|
2
|
+
import type { AttributeInput } from '../input/AttributeInput';
|
|
3
|
+
import { TextAttribute, TextAttributeGenerics, TextAttributeOptions } from './TextAttribute';
|
|
3
4
|
import { StringifyDirective } from './Attribute';
|
|
4
5
|
import { ParsedNode } from '../parsed/ParsedNode';
|
|
5
|
-
import { XMLParseEvent } from '../XMLParseEvent';
|
|
6
6
|
export interface ContentTextAttributeOptions extends Omit<TextAttributeOptions, 'configurable'> {
|
|
7
7
|
}
|
|
8
8
|
export declare class ContentTextAttribute extends TextAttribute<TextAttributeGenerics & {
|
|
@@ -10,9 +10,7 @@ export declare class ContentTextAttribute extends TextAttribute<TextAttributeGen
|
|
|
10
10
|
}> {
|
|
11
11
|
static TYPE: string;
|
|
12
12
|
constructor(options: ContentTextAttributeOptions);
|
|
13
|
-
protected getInput(
|
|
14
|
-
protected getParsedValue(event: AttributeParseEvent, parseContext?: Record<string, any>): CombinedTextExpression | null;
|
|
15
|
-
protected validateInput(event: AttributeParseEvent, expression: CombinedTextExpression, parseContext: Record<string, any>): void;
|
|
13
|
+
protected getInput(node?: NodeInput): AttributeInput | undefined;
|
|
16
14
|
stringify(value: TextAttributeGenerics['Value'], parent: ParsedNode): StringifyDirective;
|
|
17
15
|
serialize(): any;
|
|
18
16
|
}
|
|
@@ -12,7 +12,7 @@ export declare class TextAttribute<T extends TextAttributeGenerics<unknown> = Te
|
|
|
12
12
|
static TYPE: string;
|
|
13
13
|
constructor(options: T['Options']);
|
|
14
14
|
static isInstanceOf(attr: Attribute): attr is TextAttribute<TextAttributeGenerics<unknown>>;
|
|
15
|
-
protected getParsedValue(event: AttributeParseEvent
|
|
16
|
-
protected validateInput(event: AttributeParseEvent, expression: CombinedTextExpression
|
|
15
|
+
protected getParsedValue(event: AttributeParseEvent): CombinedTextExpression | null;
|
|
16
|
+
protected validateInput(event: AttributeParseEvent, expression: CombinedTextExpression): void;
|
|
17
17
|
serialize(): any;
|
|
18
18
|
}
|
package/dist/@types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './AttributeParseEvent';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './ParseEvent';
|
|
3
3
|
export * from './attributes/ConditionType';
|
|
4
4
|
export * from './attributes/Attribute';
|
|
5
5
|
export * from './attributes/BooleanAttribute';
|
|
@@ -32,3 +32,7 @@ export * from './values/ParsedNodeValues';
|
|
|
32
32
|
export * from './values/ParsedProviderValue';
|
|
33
33
|
export * from './values/ParsedValue';
|
|
34
34
|
export * from './utils/types/valueOf';
|
|
35
|
+
export * from './source/SourceReference';
|
|
36
|
+
export * from './input/AttributeInput';
|
|
37
|
+
export * from './input/NodeInput';
|
|
38
|
+
export * from './input/AttributeParseContext';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SourceReference } from '../source/SourceReference';
|
|
2
|
+
export declare enum AttributeInputKind {
|
|
3
|
+
TEXT = "text",
|
|
4
|
+
LITERAL = "literal"
|
|
5
|
+
}
|
|
6
|
+
export declare enum AttributeInputLocation {
|
|
7
|
+
ATTRIBUTE = "attribute",
|
|
8
|
+
CONTENT = "content"
|
|
9
|
+
}
|
|
10
|
+
export type AttributeLiteralValue = string | number | boolean | null | readonly AttributeLiteralValue[] | {
|
|
11
|
+
readonly [key: string]: AttributeLiteralValue;
|
|
12
|
+
};
|
|
13
|
+
export interface AttributeInputBase {
|
|
14
|
+
readonly source?: SourceReference;
|
|
15
|
+
readonly location?: AttributeInputLocation;
|
|
16
|
+
}
|
|
17
|
+
/** Text is interpreted using the attribute's expression syntax. */
|
|
18
|
+
export interface TextAttributeInput extends AttributeInputBase {
|
|
19
|
+
readonly kind: AttributeInputKind.TEXT;
|
|
20
|
+
readonly value: string;
|
|
21
|
+
}
|
|
22
|
+
/** Native data bypasses expression syntax and uses the attribute's value type. */
|
|
23
|
+
export interface LiteralAttributeInput extends AttributeInputBase {
|
|
24
|
+
readonly kind: AttributeInputKind.LITERAL;
|
|
25
|
+
readonly value: AttributeLiteralValue;
|
|
26
|
+
}
|
|
27
|
+
/** Undefined input means absent; a literal null is explicitly authored. */
|
|
28
|
+
export type AttributeInput = TextAttributeInput | LiteralAttributeInput;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AttributeInputLocation } from './AttributeInput';
|
|
2
|
+
import type { AbstractExpression } from '@ja-platform/parser-expressions';
|
|
3
|
+
import type { Attribute } from '../attributes/Attribute';
|
|
4
|
+
import type { ParsedDiagnostic } from '../parsed/ParsedDiagnostic';
|
|
5
|
+
import type { SourceReference } from '../source/SourceReference';
|
|
6
|
+
import type { ParsedNode } from '../parsed/ParsedNode';
|
|
7
|
+
export interface AttributeParseContext {
|
|
8
|
+
/** The enclosing parsed node, e.g. the field containing an option node. */
|
|
9
|
+
parentNode?: ParsedNode;
|
|
10
|
+
validateExpression?(input: {
|
|
11
|
+
attribute: Attribute;
|
|
12
|
+
expression: AbstractExpression;
|
|
13
|
+
source?: SourceReference;
|
|
14
|
+
location?: AttributeInputLocation;
|
|
15
|
+
}): void;
|
|
16
|
+
report(diagnostic: ParsedDiagnostic): void;
|
|
17
|
+
parseAttributeExpression?(input: {
|
|
18
|
+
attribute: Attribute;
|
|
19
|
+
source: string;
|
|
20
|
+
}): AbstractExpression | undefined;
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AttributeInput } from './AttributeInput';
|
|
2
|
+
import type { SourceReference } from '../source/SourceReference';
|
|
3
|
+
export interface NodeInput {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly source?: SourceReference;
|
|
6
|
+
attribute(name: string): AttributeInput | undefined;
|
|
7
|
+
content(): AttributeInput | undefined;
|
|
8
|
+
children(): Iterable<NodeInput>;
|
|
9
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { NodeInput } from '../input/NodeInput';
|
|
2
|
+
import type { AttributeInput } from '../input/AttributeInput';
|
|
1
3
|
import { ConstantExpression, ExpressionParser, AbstractExpression } from '@ja-platform/parser-expressions';
|
|
2
4
|
import { Type } from '@ja-platform/parser-type-system';
|
|
3
5
|
import { Attribute } from '../attributes/Attribute';
|
|
4
|
-
import {
|
|
5
|
-
import { XMLParseEvent } from '../XMLParseEvent';
|
|
6
|
-
import { ParsedNode } from '../parsed/ParsedNode';
|
|
6
|
+
import { ParseEvent } from '../ParseEvent';
|
|
7
7
|
import { ParsedContentNode, ParsedContentNodeShape } from '../parsed/ParsedContentNode';
|
|
8
8
|
import { ParseTreeOptions } from './Node';
|
|
9
9
|
import { Node, NodeGenerics, NodeOptions } from './Node';
|
|
@@ -25,7 +25,7 @@ interface ContentNodeGenerics<Value, Expression extends AbstractExpression> exte
|
|
|
25
25
|
* Adapt element content to the shared value-provider pipeline.
|
|
26
26
|
*/
|
|
27
27
|
export declare class ContentValueAttribute extends Attribute {
|
|
28
|
-
protected getInput(
|
|
28
|
+
protected getInput(node?: NodeInput): AttributeInput | undefined;
|
|
29
29
|
stringify(value: AbstractExpression): {
|
|
30
30
|
isAttribute: boolean;
|
|
31
31
|
value: string;
|
|
@@ -39,7 +39,7 @@ export declare class ContentNode<Value, Expression extends AbstractExpression =
|
|
|
39
39
|
protected createParsedNode(options: ParseTreeOptions): ParsedContentNode<Expression, Value>;
|
|
40
40
|
protected parseAttributes({ parsed, event }: {
|
|
41
41
|
parsed: ParsedContentNode<Expression, Value>;
|
|
42
|
-
event:
|
|
42
|
+
event: ParseEvent;
|
|
43
43
|
}): void;
|
|
44
44
|
}
|
|
45
45
|
export {};
|
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ParseEvent } from '../ParseEvent';
|
|
2
|
+
import type { NodeInput } from '../input/NodeInput';
|
|
3
3
|
import { Attribute } from '../attributes/Attribute';
|
|
4
4
|
import { ContentTextAttribute } from '../attributes/ContentTextAttribute';
|
|
5
5
|
import { CommonEntity, CommonEntityGenerics, CommonEntityOptions } from '../entities/CommonEntity';
|
|
6
6
|
import { ParsedNode } from '../parsed/ParsedNode';
|
|
7
7
|
import { ParsedNodeShape } from '../parsed/ParsedNodeTypes';
|
|
8
|
-
import { AbstractValueProvider } from '../values/AbstractValueProvider';
|
|
9
8
|
import type { NodeValidationContext } from '../parsed/ParsedNode';
|
|
10
9
|
export interface NodeListener<Shape extends ParsedNodeShape = ParsedNodeShape> {
|
|
11
10
|
/**
|
|
12
11
|
* before the node is parsed
|
|
13
12
|
*/
|
|
14
13
|
preParse?({ event, parentEvent }: {
|
|
15
|
-
event:
|
|
16
|
-
parentEvent:
|
|
14
|
+
event: ParseEvent;
|
|
15
|
+
parentEvent: ParseEvent;
|
|
17
16
|
}): any;
|
|
18
17
|
/**
|
|
19
|
-
* Before child
|
|
18
|
+
* Before child inputs are parsed.
|
|
20
19
|
*/
|
|
21
|
-
preChildrenParse?(event:
|
|
20
|
+
preChildrenParse?(event: ParseEvent): void;
|
|
22
21
|
/**
|
|
23
22
|
* Once this node has been parsed
|
|
24
23
|
*/
|
|
25
24
|
postParse?({ parsed, parentEvent }: {
|
|
26
25
|
parsed: ParsedNode<Shape>;
|
|
27
|
-
parentEvent:
|
|
26
|
+
parentEvent: ParseEvent;
|
|
28
27
|
}): any;
|
|
29
28
|
}
|
|
30
29
|
/**
|
|
@@ -59,11 +58,9 @@ export interface NodeGenerics<Shape extends ParsedNodeShape = ParsedNodeShape, P
|
|
|
59
58
|
Options: NodeOptions;
|
|
60
59
|
Listener: NodeListener<Shape>;
|
|
61
60
|
}
|
|
62
|
-
export interface ParseTreeOptions {
|
|
63
|
-
|
|
64
|
-
parentEvent?: XMLParseEvent<ParsedNode>;
|
|
61
|
+
export interface ParseTreeOptions extends ParseEvent {
|
|
62
|
+
parentEvent?: ParseEvent;
|
|
65
63
|
key?: string;
|
|
66
|
-
valueProviders?: readonly AbstractValueProvider[];
|
|
67
64
|
}
|
|
68
65
|
export declare class Node<G extends NodeGenerics<any> = NodeGenerics<any>> extends CommonEntity<G> {
|
|
69
66
|
attributes: Attribute[];
|
|
@@ -93,7 +90,7 @@ export declare class Node<G extends NodeGenerics<any> = NodeGenerics<any>> exten
|
|
|
93
90
|
parseTree(options: ParseTreeOptions): G['Parsed'];
|
|
94
91
|
validateParsedNode({ parsed, parentEvent }: {
|
|
95
92
|
parsed: ParsedNode<G['Shape'], G['Value']>;
|
|
96
|
-
parentEvent?:
|
|
93
|
+
parentEvent?: ParseEvent;
|
|
97
94
|
}): void;
|
|
98
95
|
protected shouldParse(_options: ParseTreeOptions): boolean;
|
|
99
96
|
protected createParsedNode(options: ParseTreeOptions): G['Parsed'];
|
|
@@ -103,26 +100,26 @@ export declare class Node<G extends NodeGenerics<any> = NodeGenerics<any>> exten
|
|
|
103
100
|
}): void;
|
|
104
101
|
protected parseAttributes({ parsed, event }: {
|
|
105
102
|
parsed: ParsedNode<G['Shape'], G['Value']>;
|
|
106
|
-
event:
|
|
103
|
+
event: ParseEvent;
|
|
107
104
|
}): void;
|
|
108
105
|
protected parseChildren({ parsed, options }: {
|
|
109
106
|
parsed: ParsedNode<G['Shape'], G['Value']>;
|
|
110
107
|
options: ParseTreeOptions;
|
|
111
108
|
}): void;
|
|
112
|
-
parseChildrenInto({ parent,
|
|
109
|
+
parseChildrenInto({ parent, inputs, options }: {
|
|
113
110
|
parent: ParsedNode;
|
|
114
|
-
|
|
111
|
+
inputs: NodeInput[];
|
|
115
112
|
options: ParseTreeOptions;
|
|
116
113
|
}): void;
|
|
117
|
-
|
|
114
|
+
parseInput({ parent, options, input, key }: {
|
|
118
115
|
parent: ParsedNode;
|
|
119
116
|
options: ParseTreeOptions;
|
|
120
|
-
|
|
117
|
+
input: NodeInput;
|
|
121
118
|
key: string;
|
|
122
119
|
}): ParsedNode | null;
|
|
123
|
-
protected
|
|
120
|
+
protected validateChildCount({ context, definition, matchingInputs }: {
|
|
124
121
|
context: NodeValidationContext;
|
|
125
122
|
definition: Node<any>;
|
|
126
|
-
|
|
123
|
+
matchingInputs: NodeInput[];
|
|
127
124
|
}): void;
|
|
128
125
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ParsedNode } from '../parsed/ParsedNode';
|
|
2
2
|
import { ParsedNodeShape } from '../parsed/ParsedNodeTypes';
|
|
3
3
|
import { ParseTreeOptions, Node, NodeGenerics, NodeOptions } from './Node';
|
|
4
|
-
import {
|
|
4
|
+
import type { NodeInput } from '../input/NodeInput';
|
|
5
5
|
export interface NodeAlternativesOptions extends Omit<NodeOptions, 'name'> {
|
|
6
6
|
key: string;
|
|
7
7
|
alternatives: Node<any>[];
|
|
@@ -12,12 +12,12 @@ export declare class NodeAlternatives<Shape extends ParsedNodeShape = ParsedNode
|
|
|
12
12
|
private readonly alternatives;
|
|
13
13
|
constructor(options: NodeAlternativesOptions);
|
|
14
14
|
get exclusive(): boolean;
|
|
15
|
-
parseChildrenInto({ parent,
|
|
15
|
+
parseChildrenInto({ parent, inputs, options }: {
|
|
16
16
|
parent: ParsedNode;
|
|
17
|
-
|
|
17
|
+
inputs: NodeInput[];
|
|
18
18
|
options: ParseTreeOptions;
|
|
19
19
|
}): void;
|
|
20
|
-
private
|
|
20
|
+
private parseAlternativeInput;
|
|
21
21
|
private getMatchingAlternatives;
|
|
22
22
|
private validateAlternativeCount;
|
|
23
23
|
private validateDefinitionCount;
|
|
@@ -21,7 +21,7 @@ export declare class ParsedArrayNode<Child extends ParsedArrayNodeChild = Parsed
|
|
|
21
21
|
valueTree(): ParsedNodeValuesLike<ParsedExpressionValue<Child>[]>;
|
|
22
22
|
at(index: number): Child | undefined;
|
|
23
23
|
setValueProviders(providers: readonly AbstractValueProvider[]): this;
|
|
24
|
-
pushError({ message,
|
|
24
|
+
pushError({ message, source, type }: ParsedDiagnostic): ParsedDiagnostic;
|
|
25
25
|
errors(): ParsedDiagnostic[];
|
|
26
26
|
hasErrors(): boolean;
|
|
27
27
|
map<T>(cb: (node: Child, index: number) => T): T[];
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
+
import type { AttributeInput } from '../input/AttributeInput';
|
|
1
2
|
import { TreeEntity } from '@journeyapps/common-tree';
|
|
2
|
-
import { XMLParseEvent } from '../XMLParseEvent';
|
|
3
|
-
import { XMLPositional } from '@journeyapps/common-xml';
|
|
4
3
|
import { Attribute } from '../attributes/Attribute';
|
|
5
4
|
import { ParsedDiagnostic } from './ParsedDiagnostic';
|
|
6
|
-
import { ParsedNode } from './ParsedNode';
|
|
7
5
|
export interface ParsedAttributeOptions<Expression = any, Definition extends Attribute = Attribute> {
|
|
8
6
|
definition: Definition;
|
|
9
|
-
|
|
7
|
+
input?: AttributeInput;
|
|
8
|
+
reportError?: (diagnostic: ParsedDiagnostic) => void;
|
|
10
9
|
expression: Expression;
|
|
11
|
-
parseContext?: Record<string, any>;
|
|
12
10
|
}
|
|
13
11
|
export declare class ParsedAttribute<Expression = any, Definition extends Attribute = Attribute> extends TreeEntity {
|
|
14
12
|
readonly definition: Definition;
|
|
15
13
|
private expressionValue;
|
|
16
|
-
readonly
|
|
17
|
-
readonly parseContext?: Record<string, any>;
|
|
14
|
+
readonly input?: AttributeInput;
|
|
18
15
|
private readonly diagnostics;
|
|
19
16
|
private readonly reportError;
|
|
20
17
|
constructor(options: ParsedAttributeOptions<Expression, Definition>);
|
|
21
18
|
get name(): string;
|
|
22
19
|
expression(): Expression;
|
|
23
20
|
setExpression(value: Expression): void;
|
|
24
|
-
pushError({ message,
|
|
21
|
+
pushError({ message, type, source }: ParsedDiagnostic): ParsedDiagnostic;
|
|
25
22
|
errors(): ParsedDiagnostic[];
|
|
26
23
|
hasErrors(): boolean;
|
|
27
24
|
stringify(): import("../attributes/Attribute").StringifyDirective;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SourceReference } from '../source/SourceReference';
|
|
2
2
|
import type { ExpressionDiagnostic } from '@ja-platform/parser-expressions';
|
|
3
|
-
export
|
|
3
|
+
export interface ParsedDiagnostic {
|
|
4
|
+
message: string;
|
|
5
|
+
type?: 'error' | 'warning';
|
|
6
|
+
source?: SourceReference;
|
|
7
|
+
}
|
|
4
8
|
export interface ParsedValidationDiagnostic extends ParsedDiagnostic {
|
|
5
9
|
token?: ExpressionDiagnostic['token'];
|
|
6
10
|
}
|
|
7
11
|
export declare class ParsedDiagnosticStore {
|
|
8
12
|
private readonly diagnostics;
|
|
9
|
-
pushError({ message,
|
|
13
|
+
pushError({ message, type, source }: ParsedDiagnostic): ParsedDiagnostic;
|
|
10
14
|
errors(): ParsedDiagnostic[];
|
|
11
15
|
hasErrors(): boolean;
|
|
12
16
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
2
2
|
import { TreeNode, TreeNodeListener } from '@journeyapps/common-tree';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { ParseEvent } from '../ParseEvent';
|
|
4
|
+
import type { NodeInput } from '../input/NodeInput';
|
|
5
5
|
import { Node } from '../nodes/Node';
|
|
6
6
|
import { ParsedAttribute } from './ParsedAttribute';
|
|
7
7
|
import { ParsedDiagnostic, ParsedValidationDiagnostic } from './ParsedDiagnostic';
|
|
@@ -9,11 +9,9 @@ import type { ValidationContext } from '@ja-platform/parser-expressions';
|
|
|
9
9
|
import { ParsedChild, ParsedChildNamesMarker, ParsedNodeAttribute, ParsedNodeAttributeShape, ParsedNodeAttributeName, ParsedNodeChild, ParsedNodeExpressionKey, ParsedNodeKnownChildKey, ParsedNodeValue, ParsedNodeValueRequest, ParsedNodeValueRequestKey, ParsedNodeRequiredAttributeName, ParsedNodeShape, ParsedNodeUntypedExpressionKey } from './ParsedNodeTypes';
|
|
10
10
|
import { ParsedValue } from '../values/ParsedValue';
|
|
11
11
|
import { AbstractValueProvider } from '../values/AbstractValueProvider';
|
|
12
|
-
export interface ParsedNodeOptions {
|
|
12
|
+
export interface ParsedNodeOptions extends ParseEvent {
|
|
13
13
|
definition: Node<any>;
|
|
14
|
-
event: XMLParseEvent<ParsedNode>;
|
|
15
14
|
key?: string;
|
|
16
|
-
valueProviders?: readonly AbstractValueProvider[];
|
|
17
15
|
}
|
|
18
16
|
export interface ParsedNodeValidationContext {
|
|
19
17
|
scope: ValidationContext;
|
|
@@ -43,7 +41,7 @@ export declare class ParsedNode<T extends ParsedNodeShape = ParsedNodeShape, Val
|
|
|
43
41
|
private childrenByKey;
|
|
44
42
|
private valueProviders?;
|
|
45
43
|
readonly definition: Node<any>;
|
|
46
|
-
readonly
|
|
44
|
+
readonly input?: NodeInput;
|
|
47
45
|
readonly parseParentNode?: ParsedNode;
|
|
48
46
|
private parsedContent;
|
|
49
47
|
private readonly diagnostics;
|
|
@@ -80,7 +78,7 @@ export declare class ParsedNode<T extends ParsedNodeShape = ParsedNodeShape, Val
|
|
|
80
78
|
* Diagnostics are returned without changing parse errors or reading values.
|
|
81
79
|
*/
|
|
82
80
|
validate({ scope }: ParsedNodeValidationContext): ParsedValidationDiagnostic[];
|
|
83
|
-
pushError({ message,
|
|
81
|
+
pushError({ message, source, type }: ParsedDiagnostic): ParsedDiagnostic;
|
|
84
82
|
reportDiagnostic(diagnostic: ParsedDiagnostic): void;
|
|
85
83
|
errors(options?: {
|
|
86
84
|
deep?: boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Offsets use UTF-16 code units; end is exclusive. */
|
|
2
|
+
export interface SourceRange {
|
|
3
|
+
readonly start: number;
|
|
4
|
+
readonly end: number;
|
|
5
|
+
}
|
|
6
|
+
/** Format adapters can extend this with their original syntax objects. */
|
|
7
|
+
export interface SourceReference {
|
|
8
|
+
readonly range: SourceRange;
|
|
9
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttributeParseEvent.js","sourceRoot":"","sources":["../src/AttributeParseEvent.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"AttributeParseEvent.js","sourceRoot":"","sources":["../src/AttributeParseEvent.ts"],"names":[],"mappings":"","sourcesContent":["import type { TextAttributeInput } from './input/AttributeInput';\nimport type { AttributeParseContext } from './input/AttributeParseContext';\n\nexport interface AttributeParseEvent {\n input: TextAttributeInput;\n context?: AttributeParseContext;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParseEvent.js","sourceRoot":"","sources":["../src/ParseEvent.ts"],"names":[],"mappings":"","sourcesContent":["import type { NodeInput } from './input/NodeInput';\nimport type { AttributeParseContext } from './input/AttributeParseContext';\nimport type { ParsedNode } from './parsed/ParsedNode';\nimport type { ValidationContext } from '@ja-platform/parser-expressions';\n\nexport interface ParseEvent extends AttributeParseContext {\n input?: NodeInput;\n parsedNode?: ParsedNode;\n scope?: ValidationContext;\n /** Prepare a node after its attributes and before its children are parsed. */\n prepareNode?(node: ParsedNode): void;\n}\n"]}
|
|
@@ -1,40 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.Attribute = void 0;
|
|
37
|
-
const
|
|
4
|
+
const AttributeInput_1 = require("../input/AttributeInput");
|
|
38
5
|
const parser_expressions_1 = require("@ja-platform/parser-expressions");
|
|
39
6
|
const parser_type_system_1 = require("@ja-platform/parser-type-system");
|
|
40
7
|
const CommonEntity_1 = require("../entities/CommonEntity");
|
|
@@ -84,10 +51,10 @@ class Attribute extends CommonEntity_1.CommonEntity {
|
|
|
84
51
|
serialize() {
|
|
85
52
|
return Object.assign(Object.assign({}, super.serialize()), { required: this.options.required, defaultValue: this.options.defaultValue, docs: this.options.docs, type: 'standard', advanced: !!this.options.advanced });
|
|
86
53
|
}
|
|
87
|
-
getParsedValue(event
|
|
54
|
+
getParsedValue(event) {
|
|
88
55
|
var _a, _b;
|
|
89
56
|
var _c;
|
|
90
|
-
return ((_c = (_b = (_a = event.
|
|
57
|
+
return ((_c = (_b = (_a = event.context) === null || _a === void 0 ? void 0 : _a.parseAttributeExpression) === null || _b === void 0 ? void 0 : _b.call(_a, { attribute: this, source: event.input.value })) !== null && _c !== void 0 ? _c : this.options.syntax.parse(event.input.value));
|
|
91
58
|
}
|
|
92
59
|
stringify(value, parent) {
|
|
93
60
|
if (value == null) {
|
|
@@ -104,38 +71,49 @@ class Attribute extends CommonEntity_1.CommonEntity {
|
|
|
104
71
|
createParsedAttribute(options) {
|
|
105
72
|
return new ParsedAttribute_1.ParsedAttribute(options);
|
|
106
73
|
}
|
|
107
|
-
getInput(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
};
|
|
74
|
+
getInput(node) {
|
|
75
|
+
return node === null || node === void 0 ? void 0 : node.attribute(this.name);
|
|
76
|
+
}
|
|
77
|
+
parse(node, context) {
|
|
78
|
+
return this.parseInput(this.getInput(node), context);
|
|
113
79
|
}
|
|
114
|
-
|
|
115
|
-
|
|
80
|
+
/** Instantiate an attribute from document input, or from its definition alone. */
|
|
81
|
+
parseInput(input, context) {
|
|
82
|
+
var _a;
|
|
83
|
+
var _b;
|
|
116
84
|
let expression = null;
|
|
117
85
|
let failure;
|
|
118
86
|
try {
|
|
119
|
-
if (input
|
|
120
|
-
|
|
87
|
+
if ((input === null || input === void 0 ? void 0 : input.kind) === AttributeInput_1.AttributeInputKind.LITERAL) {
|
|
88
|
+
const valueType = this.options.valueType;
|
|
89
|
+
if (!valueType) {
|
|
90
|
+
throw new SyntaxError(`Attribute ${this.name} does not support native literal input`);
|
|
91
|
+
}
|
|
92
|
+
expression = new parser_expressions_1.ConstantExpression({
|
|
93
|
+
value: valueType.parse(input.value),
|
|
94
|
+
valueType,
|
|
95
|
+
tokens: [],
|
|
96
|
+
start: (_b = (_a = input.source) === null || _a === void 0 ? void 0 : _a.range.start) !== null && _b !== void 0 ? _b : 0
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else if (input) {
|
|
100
|
+
expression = this.getParsedValue({ input, context });
|
|
121
101
|
}
|
|
122
102
|
}
|
|
123
103
|
catch (error) {
|
|
124
|
-
if (!(error instanceof SyntaxError))
|
|
104
|
+
if (!(error instanceof SyntaxError))
|
|
125
105
|
throw error;
|
|
126
|
-
}
|
|
127
106
|
failure = error;
|
|
128
107
|
}
|
|
129
|
-
const
|
|
108
|
+
const parsed = this.createParsedAttribute({
|
|
130
109
|
definition: this,
|
|
131
|
-
event,
|
|
132
110
|
expression,
|
|
133
|
-
|
|
111
|
+
input,
|
|
112
|
+
reportError: (diagnostic) => context === null || context === void 0 ? void 0 : context.report(diagnostic)
|
|
134
113
|
});
|
|
135
|
-
if (failure)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return parsedAttribute;
|
|
114
|
+
if (failure)
|
|
115
|
+
parsed.pushError({ message: failure.message });
|
|
116
|
+
return parsed;
|
|
139
117
|
}
|
|
140
118
|
}
|
|
141
119
|
exports.Attribute = Attribute;
|