@ja-platform/parser-core 0.0.0-dev-20261021213526 → 0.0.0-dev-20261027003550

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.
Files changed (69) hide show
  1. package/README.md +50 -0
  2. package/dist/@types/AttributeParseEvent.d.ts +5 -14
  3. package/dist/@types/ParseEvent.d.ts +11 -0
  4. package/dist/@types/attributes/Attribute.d.ts +9 -5
  5. package/dist/@types/attributes/ContentTextAttribute.d.ts +4 -6
  6. package/dist/@types/attributes/TextAttribute.d.ts +2 -2
  7. package/dist/@types/index.d.ts +9 -1
  8. package/dist/@types/input/AttributeInput.d.ts +28 -0
  9. package/dist/@types/input/AttributeParseContext.d.ts +21 -0
  10. package/dist/@types/input/NodeInput.d.ts +35 -0
  11. package/dist/@types/nodes/ContentNode.d.ts +5 -5
  12. package/dist/@types/nodes/EitherNode.d.ts +32 -0
  13. package/dist/@types/nodes/Node.d.ts +19 -20
  14. package/dist/@types/nodes/NodeAlternatives.d.ts +7 -4
  15. package/dist/@types/nodes/RecordNode.d.ts +16 -0
  16. package/dist/@types/parsed/ParsedArrayNode.d.ts +6 -1
  17. package/dist/@types/parsed/ParsedAttribute.d.ts +5 -8
  18. package/dist/@types/parsed/ParsedDiagnostic.d.ts +7 -3
  19. package/dist/@types/parsed/ParsedEitherNode.d.ts +9 -0
  20. package/dist/@types/parsed/ParsedNode.d.ts +5 -7
  21. package/dist/@types/parsed/ParsedRecordNode.d.ts +6 -0
  22. package/dist/@types/source/SourceReference.d.ts +9 -0
  23. package/dist/AttributeParseEvent.js.map +1 -1
  24. package/dist/{XMLParseEvent.js → ParseEvent.js} +1 -1
  25. package/dist/ParseEvent.js.map +1 -0
  26. package/dist/attributes/Attribute.js +33 -55
  27. package/dist/attributes/Attribute.js.map +1 -1
  28. package/dist/attributes/ContentTextAttribute.js +9 -24
  29. package/dist/attributes/ContentTextAttribute.js.map +1 -1
  30. package/dist/attributes/NumberAttribute.js +1 -1
  31. package/dist/attributes/NumberAttribute.js.map +1 -1
  32. package/dist/attributes/TextAttribute.js +11 -9
  33. package/dist/attributes/TextAttribute.js.map +1 -1
  34. package/dist/index.js +9 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/input/AttributeInput.js +14 -0
  37. package/dist/input/AttributeInput.js.map +1 -0
  38. package/dist/input/AttributeParseContext.js +3 -0
  39. package/dist/input/AttributeParseContext.js.map +1 -0
  40. package/dist/input/NodeInput.js +14 -0
  41. package/dist/input/NodeInput.js.map +1 -0
  42. package/dist/nodes/ContentNode.js +13 -11
  43. package/dist/nodes/ContentNode.js.map +1 -1
  44. package/dist/nodes/EitherNode.js +95 -0
  45. package/dist/nodes/EitherNode.js.map +1 -0
  46. package/dist/nodes/Node.js +44 -37
  47. package/dist/nodes/Node.js.map +1 -1
  48. package/dist/nodes/NodeAlternatives.js +28 -21
  49. package/dist/nodes/NodeAlternatives.js.map +1 -1
  50. package/dist/nodes/RecordNode.js +36 -0
  51. package/dist/nodes/RecordNode.js.map +1 -0
  52. package/dist/parsed/ParsedArrayNode.js +9 -5
  53. package/dist/parsed/ParsedArrayNode.js.map +1 -1
  54. package/dist/parsed/ParsedAttribute.js +8 -6
  55. package/dist/parsed/ParsedAttribute.js.map +1 -1
  56. package/dist/parsed/ParsedDiagnostic.js +4 -2
  57. package/dist/parsed/ParsedDiagnostic.js.map +1 -1
  58. package/dist/parsed/ParsedEitherNode.js +16 -0
  59. package/dist/parsed/ParsedEitherNode.js.map +1 -0
  60. package/dist/parsed/ParsedNode.js +15 -12
  61. package/dist/parsed/ParsedNode.js.map +1 -1
  62. package/dist/parsed/ParsedRecordNode.js +14 -0
  63. package/dist/parsed/ParsedRecordNode.js.map +1 -0
  64. package/dist/source/SourceReference.js +3 -0
  65. package/dist/source/SourceReference.js.map +1 -0
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/package.json +5 -6
  68. package/dist/@types/XMLParseEvent.d.ts +0 -37
  69. package/dist/XMLParseEvent.js.map +0 -1
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Parser core
2
+
3
+ `@ja-platform/parser-core` defines nodes, attributes, parsed trees, and value
4
+ providers. Document adapters supply the input, so a definition can read JSON or
5
+ XML without depending on either format.
6
+
7
+ For examples of definitions and the documents they read, see
8
+ [JSON document inputs](../document-json/README.md) and
9
+ [XML document inputs](../document-xml/README.md).
10
+
11
+ ## Resolving values
12
+
13
+ Parsing creates a tree of parsed nodes and expressions. Value providers tell that
14
+ tree how to resolve values. For a document containing constants and defaults:
15
+
16
+ ```ts
17
+ import {
18
+ Node,
19
+ NumberAttribute,
20
+ ConstantExpressionValueProvider,
21
+ ParserDefaultValueProvider
22
+ } from '@ja-platform/parser-core';
23
+ import { JSONNodeInput } from '@ja-platform/parser-document-json';
24
+
25
+ const config = new Node({ name: 'config' });
26
+ config.addAttribute(new NumberAttribute({ name: 'delay', defaultValue: 500 }));
27
+
28
+ const parsed = config.parseTree({
29
+ input: JSONNodeInput.parse('{"delay":250}'),
30
+ report: (diagnostic) => console.warn(diagnostic)
31
+ });
32
+
33
+ const providers = [new ParserDefaultValueProvider(), new ConstantExpressionValueProvider()];
34
+ parsed.setValueProviders(providers);
35
+
36
+ const values = parsed.valueTree();
37
+ console.log(values.current); // { delay: 250 }
38
+
39
+ // Release the value subscription and the providers when finished.
40
+ values.dispose();
41
+ providers.forEach((provider) => provider.dispose());
42
+ ```
43
+
44
+ The constant provider supplies the explicit `250`. With `{}` as the input, the
45
+ default provider supplies `500`. The same provider setup works for a tree parsed
46
+ from XML; it operates on the parsed expressions, not the source format.
47
+
48
+ For dynamic expressions, the host supplies providers that resolve references or
49
+ evaluate code. Keep that setup separate from document parsing so the same
50
+ definitions and inputs can be used in different hosts.
@@ -1,15 +1,6 @@
1
- import type { XMLPositional } from '@journeyapps/common-xml';
2
- import type { XMLParseEvent } from './XMLParseEvent';
3
- import type { ParsedNode } from './parsed/ParsedNode';
4
- export interface AttributeParseInput {
5
- value: string | null;
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 { AttributeParseEvent, AttributeParseInput } from '../AttributeParseEvent';
2
- import { XMLParseEvent } from '../XMLParseEvent';
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, _parseContext?: Record<string, any>): G['Value'];
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(event: XMLParseEvent<ParsedNode>): AttributeParseInput;
74
- parse(event: XMLParseEvent<ParsedNode>, parseContext?: Record<string, any>): ParsedAttribute<G["Value"], this>;
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 { AttributeParseEvent, AttributeParseInput } from '../AttributeParseEvent';
2
- import { CombinedTextExpression, TextAttribute, TextAttributeGenerics, TextAttributeOptions } from './TextAttribute';
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(event: XMLParseEvent<ParsedNode>): AttributeParseInput;
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, parseContext?: Record<string, any>): CombinedTextExpression | null;
16
- protected validateInput(event: AttributeParseEvent, expression: CombinedTextExpression, parseContext: Record<string, any>): void;
15
+ protected getParsedValue(event: AttributeParseEvent): CombinedTextExpression | null;
16
+ protected validateInput(event: AttributeParseEvent, expression: CombinedTextExpression): void;
17
17
  serialize(): any;
18
18
  }
@@ -1,5 +1,5 @@
1
1
  export * from './AttributeParseEvent';
2
- export * from './XMLParseEvent';
2
+ export * from './ParseEvent';
3
3
  export * from './attributes/ConditionType';
4
4
  export * from './attributes/Attribute';
5
5
  export * from './attributes/BooleanAttribute';
@@ -19,6 +19,10 @@ export * from './entities/CommonEntity';
19
19
  export * from './nodes/Node';
20
20
  export * from './nodes/ContentNode';
21
21
  export * from './nodes/NodeAlternatives';
22
+ export * from './nodes/RecordNode';
23
+ export * from './nodes/EitherNode';
24
+ export * from './parsed/ParsedEitherNode';
25
+ export * from './parsed/ParsedRecordNode';
22
26
  export * from './parsed/ParsedArrayNode';
23
27
  export * from './parsed/ParsedAttribute';
24
28
  export * from './parsed/ParsedContentNode';
@@ -32,3 +36,7 @@ export * from './values/ParsedNodeValues';
32
36
  export * from './values/ParsedProviderValue';
33
37
  export * from './values/ParsedValue';
34
38
  export * from './utils/types/valueOf';
39
+ export * from './source/SourceReference';
40
+ export * from './input/AttributeInput';
41
+ export * from './input/NodeInput';
42
+ 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,35 @@
1
+ import type { AttributeInput } from './AttributeInput';
2
+ import type { ParsedDiagnostic } from '../parsed/ParsedDiagnostic';
3
+ import type { SourceReference } from '../source/SourceReference';
4
+ export interface NodeInputSelector {
5
+ name: string;
6
+ key: string;
7
+ isMultiple?: boolean;
8
+ }
9
+ export interface NodeInputSelection {
10
+ inputs: NodeInput[];
11
+ present: boolean;
12
+ source?: SourceReference;
13
+ diagnostics: ParsedDiagnostic[];
14
+ }
15
+ export declare enum NodeInputKind {
16
+ STRING = "string",
17
+ NUMBER = "number",
18
+ BOOLEAN = "boolean",
19
+ NULL = "null",
20
+ OBJECT = "object",
21
+ ARRAY = "array",
22
+ ELEMENT = "element"
23
+ }
24
+ export interface NodeInput {
25
+ readonly kind: NodeInputKind;
26
+ readonly name: string;
27
+ readonly source?: SourceReference;
28
+ attribute(name: string): AttributeInput | undefined;
29
+ content(): AttributeInput | undefined;
30
+ children(): Iterable<NodeInput>;
31
+ /** Select named entries, reporting inputs that cannot represent a record. */
32
+ recordEntries(): NodeInputSelection;
33
+ /** Select declared children in document order, retaining explicit empty collections. */
34
+ selectChildren(selectors: readonly NodeInputSelector[], attributeNames?: readonly string[]): NodeInputSelection;
35
+ }
@@ -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 { AttributeParseInput } from '../AttributeParseEvent';
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(event: XMLParseEvent<ParsedNode>): AttributeParseInput;
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: XMLParseEvent<ParsedNode>;
42
+ event: ParseEvent;
43
43
  }): void;
44
44
  }
45
45
  export {};
@@ -0,0 +1,32 @@
1
+ import { type NodeInput, type NodeInputSelection } from '../input/NodeInput';
2
+ import { ParsedEitherNode } from '../parsed/ParsedEitherNode';
3
+ import { ParsedNode } from '../parsed/ParsedNode';
4
+ import type { ParsedChild } from '../parsed/ParsedNodeTypes';
5
+ import { Node, type NodeGenerics, type NodeOptions, type ParseTreeOptions } from './Node';
6
+ export interface EitherNodeOptions extends NodeOptions {
7
+ alternatives: readonly [Node<any>, Node<any>, ...Node<any>[]];
8
+ }
9
+ interface EitherParseTreeOptions extends ParseTreeOptions {
10
+ alternativeInputs?: NodeInput[];
11
+ }
12
+ /** Select by input shape before parsing, so unsuccessful branches have no side effects. */
13
+ export declare class EitherNode<Value = unknown> extends Node<NodeGenerics<{
14
+ value?: ParsedChild;
15
+ }, ParsedEitherNode<Value>, Value | undefined>> {
16
+ constructor(options: EitherNodeOptions);
17
+ protected createParsedNode(options: ParseTreeOptions): ParsedEitherNode<Value>;
18
+ parse(options: EitherParseTreeOptions): ParsedEitherNode<Value> | null;
19
+ protected parseChildren({ parsed, options }: {
20
+ parsed: ParsedEitherNode<Value>;
21
+ options: EitherParseTreeOptions;
22
+ }): void;
23
+ parseChildrenInto({ parent, inputs, options, selection }: {
24
+ parent: ParsedNode;
25
+ inputs: NodeInput[];
26
+ options: ParseTreeOptions;
27
+ selection?: NodeInputSelection;
28
+ }): void;
29
+ private matches;
30
+ private parseSelection;
31
+ }
32
+ export {};
@@ -1,30 +1,29 @@
1
- import { XMLParseEvent } from '../XMLParseEvent';
2
- import { XMLElement } from '@journeyapps/domparser/lib';
1
+ import { ParseEvent } from '../ParseEvent';
2
+ import type { NodeInput, NodeInputSelector, NodeInputSelection } 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: XMLParseEvent<ParsedNode>;
16
- parentEvent: XMLParseEvent<ParsedNode>;
14
+ event: ParseEvent;
15
+ parentEvent: ParseEvent;
17
16
  }): any;
18
17
  /**
19
- * Before child elements are parsed.
18
+ * Before child inputs are parsed.
20
19
  */
21
- preChildrenParse?(event: XMLParseEvent<ParsedNode>): void;
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: XMLParseEvent<ParsedNode>;
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
- event: XMLParseEvent<ParsedNode>;
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?: XMLParseEvent<ParsedNode>;
93
+ parentEvent?: ParseEvent;
97
94
  }): void;
98
95
  protected shouldParse(_options: ParseTreeOptions): boolean;
99
96
  protected createParsedNode(options: ParseTreeOptions): G['Parsed'];
@@ -103,26 +100,28 @@ 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: XMLParseEvent<ParsedNode>;
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, elements, options }: {
109
+ get inputSelectors(): readonly NodeInputSelector[];
110
+ parseChildrenInto({ parent, inputs, options, selection }: {
113
111
  parent: ParsedNode;
114
- elements: XMLElement[];
112
+ inputs: NodeInput[];
115
113
  options: ParseTreeOptions;
114
+ selection?: NodeInputSelection;
116
115
  }): void;
117
- parseElement({ parent, options, element, key }: {
116
+ parseInput({ parent, options, input, key }: {
118
117
  parent: ParsedNode;
119
118
  options: ParseTreeOptions;
120
- element: XMLElement;
119
+ input: NodeInput;
121
120
  key: string;
122
121
  }): ParsedNode | null;
123
- protected validateChildElementCount({ context, definition, matchingElements }: {
122
+ protected validateChildCount({ context, definition, matchingInputs }: {
124
123
  context: NodeValidationContext;
125
124
  definition: Node<any>;
126
- matchingElements: XMLElement[];
125
+ matchingInputs: NodeInput[];
127
126
  }): void;
128
127
  }
@@ -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 { XMLElement } from '@journeyapps/domparser/lib';
4
+ import type { NodeInput, NodeInputSelector, NodeInputSelection } from '../input/NodeInput';
5
5
  export interface NodeAlternativesOptions extends Omit<NodeOptions, 'name'> {
6
6
  key: string;
7
7
  alternatives: Node<any>[];
@@ -10,14 +10,17 @@ export interface NodeAlternativesOptions extends Omit<NodeOptions, 'name'> {
10
10
  export declare class NodeAlternatives<Shape extends ParsedNodeShape = ParsedNodeShape> extends Node<NodeGenerics<Shape>> {
11
11
  private readonly exclusiveValue;
12
12
  private readonly alternatives;
13
+ private readonly selectors;
13
14
  constructor(options: NodeAlternativesOptions);
14
15
  get exclusive(): boolean;
15
- parseChildrenInto({ parent, elements, options }: {
16
+ get inputSelectors(): readonly NodeInputSelector[];
17
+ parseChildrenInto({ parent, inputs, options, selection }: {
16
18
  parent: ParsedNode;
17
- elements: XMLElement[];
19
+ inputs: NodeInput[];
18
20
  options: ParseTreeOptions;
21
+ selection?: NodeInputSelection;
19
22
  }): void;
20
- private parseAlternativeElement;
23
+ private parseAlternativeInput;
21
24
  private getMatchingAlternatives;
22
25
  private validateAlternativeCount;
23
26
  private validateDefinitionCount;
@@ -0,0 +1,16 @@
1
+ import { ParsedNode } from '../parsed/ParsedNode';
2
+ import { ParsedRecordNode } from '../parsed/ParsedRecordNode';
3
+ import { Node, type NodeGenerics, type NodeOptions, type ParseTreeOptions } from './Node';
4
+ type RecordShape<Entry extends Node<any>> = Record<string, ReturnType<Entry['parseTree']>>;
5
+ /** Parse named entries using one shared definition, retaining each entry's source. */
6
+ export declare class RecordNode<Entry extends Node<any>, Value = Entry extends Node<infer G> ? G['Value'] : never> extends Node<NodeGenerics<RecordShape<Entry>, ParsedRecordNode<ReturnType<Entry['parseTree']>, Value>, Record<string, Value>>> {
7
+ constructor(options: NodeOptions & {
8
+ entry: Entry;
9
+ });
10
+ protected createParsedNode(options: ParseTreeOptions): ParsedRecordNode<ReturnType<Entry['parseTree']>, Value>;
11
+ protected parseChildren({ parsed, options }: {
12
+ parsed: ParsedNode<RecordShape<Entry>, Record<string, Value>>;
13
+ options: ParseTreeOptions;
14
+ }): void;
15
+ }
16
+ export {};
@@ -1,6 +1,7 @@
1
1
  import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
2
2
  import { ParsedExpressionValue } from './ParsedNodeTypes';
3
3
  import { TreeNode } from '@journeyapps/common-tree';
4
+ import type { SourceReference } from '../source/SourceReference';
4
5
  import { Node } from '../nodes/Node';
5
6
  import { AbstractValueProvider } from '../values/AbstractValueProvider';
6
7
  import { ParsedDiagnostic } from './ParsedDiagnostic';
@@ -8,10 +9,14 @@ import { ParsedNode } from './ParsedNode';
8
9
  export interface ParsedArrayNodeOptions {
9
10
  definition: Node<any>;
10
11
  key: string;
12
+ inputPresent?: boolean;
13
+ source?: SourceReference;
11
14
  }
12
15
  export type ParsedArrayNodeChild = ParsedNode<any, any> | ParsedArrayNode<any>;
13
16
  export declare class ParsedArrayNode<Child extends ParsedArrayNodeChild = ParsedNode<any, any>> extends TreeNode {
14
17
  readonly definition: Node<any>;
18
+ readonly inputPresent?: boolean;
19
+ readonly source?: SourceReference;
15
20
  private readonly diagnostics;
16
21
  constructor(options: ParsedArrayNodeOptions);
17
22
  nodes(): Child[];
@@ -21,7 +26,7 @@ export declare class ParsedArrayNode<Child extends ParsedArrayNodeChild = Parsed
21
26
  valueTree(): ParsedNodeValuesLike<ParsedExpressionValue<Child>[]>;
22
27
  at(index: number): Child | undefined;
23
28
  setValueProviders(providers: readonly AbstractValueProvider[]): this;
24
- pushError({ message, element, type }: ParsedDiagnostic): ParsedDiagnostic;
29
+ pushError({ message, source, type }: ParsedDiagnostic): ParsedDiagnostic;
25
30
  errors(): ParsedDiagnostic[];
26
31
  hasErrors(): boolean;
27
32
  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
- event: XMLParseEvent<ParsedNode>;
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 sourceElement: XMLPositional;
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, element, type }: ParsedDiagnostic): ParsedDiagnostic;
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 { XMLDiagnostic as ParsedDiagnostic } from '@journeyapps/common-xml';
1
+ import type { SourceReference } from '../source/SourceReference';
2
2
  import type { ExpressionDiagnostic } from '@ja-platform/parser-expressions';
3
- export type { XMLDiagnostic as ParsedDiagnostic } from '@journeyapps/common-xml';
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, element, type }: ParsedDiagnostic): ParsedDiagnostic;
13
+ pushError({ message, type, source }: ParsedDiagnostic): ParsedDiagnostic;
10
14
  errors(): ParsedDiagnostic[];
11
15
  hasErrors(): boolean;
12
16
  }
@@ -0,0 +1,9 @@
1
+ import { ParsedNode } from './ParsedNode';
2
+ import type { ParsedChild } from './ParsedNodeTypes';
3
+ import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
4
+ /** Preserve the selected branch's value without adding an object to the output. */
5
+ export declare class ParsedEitherNode<Value> extends ParsedNode<{
6
+ value?: ParsedChild;
7
+ }, Value | undefined> {
8
+ valueTree(): ParsedNodeValuesLike<Value | undefined>;
9
+ }
@@ -1,7 +1,7 @@
1
1
  import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
2
2
  import { TreeNode, TreeNodeListener } from '@journeyapps/common-tree';
3
- import { XMLParseEvent } from '../XMLParseEvent';
4
- import { XMLElement } from '@journeyapps/domparser/lib';
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 sourceElement: XMLElement;
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, element, type }: ParsedDiagnostic): ParsedDiagnostic;
81
+ pushError({ message, source, type }: ParsedDiagnostic): ParsedDiagnostic;
84
82
  reportDiagnostic(diagnostic: ParsedDiagnostic): void;
85
83
  errors(options?: {
86
84
  deep?: boolean;
@@ -0,0 +1,6 @@
1
+ import { ParsedNode } from './ParsedNode';
2
+ import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
3
+ /** Only document keys become entries; the entry definition does not imply a default key. */
4
+ export declare class ParsedRecordNode<Entry extends ParsedNode<any, any>, Value> extends ParsedNode<Record<string, Entry>, Record<string, Value>> {
5
+ valueTree(): ParsedNodeValuesLike<Record<string, Value>>;
6
+ }
@@ -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 { XMLPositional } from '@journeyapps/common-xml';\nimport type { XMLParseEvent } from './XMLParseEvent';\nimport type { ParsedNode } from './parsed/ParsedNode';\n\nexport interface AttributeParseInput {\n value: string | null;\n source: XMLPositional;\n}\n\n/**\n * An XML parse event with the input selected for an attribute codec.\n */\nexport interface AttributeParseEvent<Node extends ParsedNode<any, any> = any> extends XMLParseEvent<Node> {\n input: AttributeParseInput & { value: string };\n}\n"]}
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"]}
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=XMLParseEvent.js.map
3
+ //# sourceMappingURL=ParseEvent.js.map