@traqula/core 0.0.1-alpha.143 → 0.0.1-alpha.148
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/lib/grammar-builder/builderTypes.d.ts +14 -5
- package/lib/grammar-builder/builderTypes.js.map +1 -1
- package/lib/grammar-builder/parserBuilder.d.ts +38 -20
- package/lib/grammar-builder/parserBuilder.js +56 -114
- package/lib/grammar-builder/parserBuilder.js.map +1 -1
- package/lib/grammar-builder/ruleDefTypes.d.ts +44 -28
- package/lib/grammar-builder/ruleDefTypes.js.map +1 -1
- package/lib/index.cjs +45 -414
- package/package.json +4 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ruleDefTypes.js","sourceRoot":"","sources":["ruleDefTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AtLeastOneSepMethodOpts,\n DSLMethodOpts,\n DSLMethodOptsWithErr,\n GrammarAction,\n IOrAlt,\n ManySepMethodOpts,\n OrMethodOpts,\n} from '@chevrotain/types';\nimport type * as RDF from '@rdfjs/types';\nimport type { ConsumeMethodOpts, IToken, TokenType } from 'chevrotain';\nimport type { DataFactory } from 'rdf-data-factory';\n\nexport type RuleDef<\n NameType extends string = string,\n ReturnType = unknown,\n ParamType extends unknown[] = unknown[],\n> = {\n name: NameType;\n impl: (def: ImplArgs) => (...args: ArrayElementsUndefinable<ParamType>) => ReturnType;\n};\n\nexport type RuleDefReturn<T> = T extends RuleDef<any, infer Ret, any> ? Ret : never;\n\ntype ArrayElementsUndefinable<ArrayType extends any[]> =\n ArrayType extends [infer First, ...infer Rest] ? [First | undefined, ...ArrayElementsUndefinable<Rest>] : [];\n\nexport interface ImplArgs extends CstDef {\n cache: WeakMap<RuleDef, unknown>;\n context: {\n dataFactory: DataFactory<RDF.BaseQuad>;\n /**\n * Current scoped prefixes. Used for resolving prefixed names.\n */\n prefixes: Record<string, string>;\n /**\n * The base IRI for the query. Used for resolving relative IRIs.\n */\n baseIRI: string | undefined;\n /**\n * Can be used to disable the validation that used variables in a select clause are in scope.\n */\n skipValidation: boolean;\n /**\n * Set of queryModes. Primarily used for note 8, 14.\n */\n parseMode: Set<symbol>;\n };\n}\n\ntype SubRuleFunc = <T extends string, U = unknown, ARGS extends any[] = []>(\n cstDef: RuleDef<T, U, ARGS>,\n ...argument: ARGS\n) => U;\ntype BacktrackFunc = <T extends string, U = unknown, ARGS extends any[] = []>(\n cstDef: RuleDef<T, U, ARGS>,\n ...argument: ARGS\n) => () => boolean;\n\nexport interface CstDef {\n /**\n *\n * A Parsing DSL method use to consume a single Token.\n * In EBNF terms this is equivalent to a Terminal.\n *\n * A Token will be consumed, IFF the next token in the token vector matches `tokType`.\n * otherwise the parser may attempt to perform error recovery (if enabled).\n *\n * The index in the method name indicates the unique occurrence of a terminal consumption\n * inside a the top level rule. What this means is that if a terminal appears\n * more than once in a single rule, each appearance must have a **different** index.\n *\n * For example:\n * ```\n * this.RULE(\"qualifiedName\", () => {\n * this.CONSUME1(Identifier);\n * this.MANY(() => {\n * this.CONSUME1(Dot);\n * // here we use CONSUME2 because the terminal\n * // 'Identifier' has already appeared previously in the\n * // the rule 'parseQualifiedName'\n * this.CONSUME2(Identifier);\n * });\n * })\n * ```\n *\n * - See more details on the [unique suffixes requirement](http://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES).\n *\n * @param tokType - The Type of the token to be consumed.\n * @param options - optional properties to modify the behavior of CONSUME.\n */\n CONSUME: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME1: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME2: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME3: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME4: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME5: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME6: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME7: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME8: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME9: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n /**\n * Parsing DSL Method that Indicates an Optional production.\n * in EBNF notation this is equivalent to: \"[...]\".\n *\n * Note that there are two syntax forms:\n * - Passing the grammar action directly:\n * ```\n * this.OPTION(() => {\n * this.CONSUME(Digit)}\n * );\n * ```\n *\n * - using an \"options\" object:\n * ```\n * this.OPTION({\n * GATE:predicateFunc,\n * DEF: () => {\n * this.CONSUME(Digit)\n * }});\n * ```\n *\n * The optional 'GATE' property in \"options\" object form can be used to add constraints\n * to invoking the grammar action.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the optional production in it's top rule.\n *\n * @param actionORMethodDef - The grammar action to optionally invoke once\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n * @returns The `GrammarAction` return value (OUT) if the optional syntax is encountered\n * or `undefined` if not.\n */\n OPTION: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION1: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION2: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION3: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION4: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION5: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION6: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION7: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION8: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION9: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n /**\n * Parsing DSL method that indicates a choice between a set of alternatives must be made.\n * This is equivalent to an EBNF alternation (A | B | C | D ...), except\n * that the alternatives are ordered like in a PEG grammar.\n * This means that the **first** matching alternative is always chosen.\n *\n * There are several forms for the inner alternatives array:\n *\n * - Passing alternatives array directly:\n * ```\n * this.OR([\n * { ALT:() => { this.CONSUME(One) }},\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - Passing alternative array directly with predicates (GATE):\n * ```\n * this.OR([\n * { GATE: predicateFunc1, ALT:() => { this.CONSUME(One) }},\n * { GATE: predicateFuncX, ALT:() => { this.CONSUME(Two) }},\n * { GATE: predicateFuncX, ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - These syntax forms can also be mixed:\n * ```\n * this.OR([\n * {\n * GATE: predicateFunc1,\n * ALT:() => { this.CONSUME(One) }\n * },\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - Additionally an \"options\" object may be used:\n * ```\n * this.OR({\n * DEF:[\n * { ALT:() => { this.CONSUME(One) }},\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ],\n * // OPTIONAL property\n * ERR_MSG: \"A Number\"\n * })\n * ```\n *\n * The 'predicateFuncX' in the long form can be used to add constraints to choosing the alternative.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the alternation production in it's top rule.\n *\n * @param altsOrOpts - A set of alternatives or an \"OPTIONS\" object describing the alternatives\n * and optional properties.\n *\n * @returns The result of invoking the chosen alternative.\n */\n OR: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR1: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR2: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR3: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR4: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR5: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR6: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR7: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR8: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR9: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n /**\n * Parsing DSL method, that indicates a repetition of zero or more.\n * This is equivalent to EBNF repetition \\{...\\}.\n *\n * Note that there are two syntax forms:\n * - Passing the grammar action directly:\n * ```\n * this.MANY(() => {\n * this.CONSUME(Comma)\n * this.CONSUME(Digit)\n * })\n * ```\n *\n * - using an \"options\" object:\n * ```\n * this.MANY({\n * GATE: predicateFunc,\n * DEF: () => {\n * this.CONSUME(Comma)\n * this.CONSUME(Digit)\n * }\n * });\n * ```\n *\n * The optional 'GATE' property in \"options\" object form can be used to add constraints\n * to invoking the grammar action.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the repetition production in it's top rule.\n *\n * @param actionORMethodDef - The grammar action to optionally invoke multiple times\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n */\n MANY: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY1: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY2: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY3: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY4: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY5: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY6: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY7: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY8: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY9: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n /**\n * Parsing DSL method, that indicates a repetition of zero or more with a separator\n * Token between the repetitions.\n *\n * Example:\n *\n * ```\n * this.MANY_SEP({\n * SEP:Comma,\n * DEF: () => {\n * this.CONSUME(Number};\n * // ...\n * })\n * ```\n *\n * Note that because this DSL method always requires more than one argument the options object is always required\n * and it is not possible to use a shorter form like in the MANY DSL method.\n *\n * Note that for the purposes of deciding on whether or not another iteration exists\n * Only a single Token is examined (The separator). Therefore if the grammar being implemented is\n * so \"crazy\" to require multiple tokens to identify an item separator please use the more basic DSL methods\n * to implement it.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the repetition production in it's top rule.\n *\n * @param options - An object defining the grammar of each iteration and the separator between iterations\n *\n */\n MANY_SEP: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP1: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP2: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP3: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP4: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP5: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP6: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP7: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP8: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP9: (options: ManySepMethodOpts<any>) => void;\n /**\n * Convenience method, same as MANY but the repetition is of one or more.\n * failing to match at least one repetition will result in a parsing error and\n * cause a parsing error.\n *\n * @see MANY\n *\n * @param actionORMethodDef - The grammar action to optionally invoke multiple times\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n */\n AT_LEAST_ONE: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE1: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE2: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE3: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE4: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE5: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE6: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE7: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE8: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE9: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n /**\n * Convenience method, same as MANY_SEP but the repetition is of one or more.\n * failing to match at least one repetition will result in a parsing error and\n * cause the parser to attempt error recovery.\n *\n * Note that an additional optional property ERR_MSG can be used to provide custom error messages.\n *\n * @see MANY_SEP\n *\n * @param options - An object defining the grammar of each iteration and the separator between iterations\n *\n * @return {ISeparatedIterationResult<OUT>}\n */\n AT_LEAST_ONE_SEP: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP1: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP2: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP3: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP4: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP5: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP6: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP7: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP8: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP9: (options: AtLeastOneSepMethodOpts<any>) => void;\n ACTION: <T>(impl: () => T) => T;\n BACKTRACK: BacktrackFunc;\n SUBRULE: SubRuleFunc;\n SUBRULE1: SubRuleFunc;\n SUBRULE2: SubRuleFunc;\n SUBRULE3: SubRuleFunc;\n SUBRULE4: SubRuleFunc;\n SUBRULE5: SubRuleFunc;\n SUBRULE6: SubRuleFunc;\n SUBRULE7: SubRuleFunc;\n SUBRULE8: SubRuleFunc;\n SUBRULE9: SubRuleFunc;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ruleDefTypes.js","sourceRoot":"","sources":["ruleDefTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AtLeastOneSepMethodOpts,\n DSLMethodOpts,\n DSLMethodOptsWithErr,\n EmbeddedActionsParser,\n GrammarAction,\n IOrAlt,\n ManySepMethodOpts,\n OrMethodOpts,\n} from '@chevrotain/types';\nimport type {ConsumeMethodOpts, IToken, TokenType} from 'chevrotain';\n\n/**\n * Get the return-type of a RuleDef\n */\nexport type RuleDefReturn<T extends RuleDef> = T extends RuleDef<any, string, infer Ret> ? Ret : never;\n\n/**\n * Type used to declare grammar rules.\n */\nexport type RuleDef<\n /**\n * Context object available in rule implementation.\n */\n Context = any,\n /**\n * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.\n */\n NameType extends string = string,\n /**\n * Type that will be returned after a correct parse of this rule.\n * This type will be the return type of calling SUBRULE with this grammar rule.\n */\n ReturnType = unknown,\n /**\n * Function arguments that can be given to convey the state of the current parse operation.\n */\n ParamType = any,\n> = {\n name: NameType;\n impl: (def: ImplArgs) => (context: Context, params: ParamType) => ReturnType;\n};\n\n/**\n * Type expected by grammar rules in the main `impl` function.\n */\nexport interface ImplArgs extends CstDef {\n cache: WeakMap<RuleDef, unknown>;\n}\n\n/**\n * Type definition used by {@link CstDef.SUBRULE} and family.\n */\ntype SubRuleFunc = <T extends string, U = unknown, ARGS = any>(\n cstDef: RuleDef<any, T, U, ARGS>,\n argument: ARGS\n) => U;\n/**\n * Type definition used by {@link CstDef.BACKTRACK}.\n */\ntype BacktrackFunc = <T extends string, U = unknown, ARGS = any>(\n cstDef: RuleDef<any, T, U, ARGS>,\n argument: ARGS\n) => () => boolean;\n\n/**\n * Mainly a repetition of the functions exposed by the {@link EmbeddedActionsParser},\n * with some small adjustments that allow for the API changes made by traqula.\n * Specifically changes are made to the {@link CstDef.SUBRULE} (and family) interface,\n * and to the {@link CstDef.BACKTRACK} interface.\n */\nexport interface CstDef {\n /**\n *\n * A Parsing DSL method use to consume a single Token.\n * In EBNF terms this is equivalent to a Terminal.\n *\n * A Token will be consumed, IFF the next token in the token vector matches `tokType`.\n * otherwise the parser may attempt to perform error recovery (if enabled).\n *\n * The index in the method name indicates the unique occurrence of a terminal consumption\n * inside a the top level rule. What this means is that if a terminal appears\n * more than once in a single rule, each appearance must have a **different** index.\n *\n * For example:\n * ```\n * this.RULE(\"qualifiedName\", () => {\n * this.CONSUME1(Identifier);\n * this.MANY(() => {\n * this.CONSUME1(Dot);\n * // here we use CONSUME2 because the terminal\n * // 'Identifier' has already appeared previously in the\n * // the rule 'parseQualifiedName'\n * this.CONSUME2(Identifier);\n * });\n * })\n * ```\n *\n * - See more details on the [unique suffixes requirement](http://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES).\n *\n * @param tokType - The Type of the token to be consumed.\n * @param options - optional properties to modify the behavior of CONSUME.\n */\n CONSUME: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME1: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME2: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME3: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME4: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME5: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME6: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME7: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME8: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME9: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n /**\n * Parsing DSL Method that Indicates an Optional production.\n * in EBNF notation this is equivalent to: \"[...]\".\n *\n * Note that there are two syntax forms:\n * - Passing the grammar action directly:\n * ```\n * this.OPTION(() => {\n * this.CONSUME(Digit)}\n * );\n * ```\n *\n * - using an \"options\" object:\n * ```\n * this.OPTION({\n * GATE:predicateFunc,\n * DEF: () => {\n * this.CONSUME(Digit)\n * }});\n * ```\n *\n * The optional 'GATE' property in \"options\" object form can be used to add constraints\n * to invoking the grammar action.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the optional production in it's top rule.\n *\n * @param actionORMethodDef - The grammar action to optionally invoke once\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n * @returns The `GrammarAction` return value (OUT) if the optional syntax is encountered\n * or `undefined` if not.\n */\n OPTION: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION1: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION2: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION3: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION4: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION5: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION6: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION7: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION8: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION9: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n /**\n * Parsing DSL method that indicates a choice between a set of alternatives must be made.\n * This is equivalent to an EBNF alternation (A | B | C | D ...), except\n * that the alternatives are ordered like in a PEG grammar.\n * This means that the **first** matching alternative is always chosen.\n *\n * There are several forms for the inner alternatives array:\n *\n * - Passing alternatives array directly:\n * ```\n * this.OR([\n * { ALT:() => { this.CONSUME(One) }},\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - Passing alternative array directly with predicates (GATE):\n * ```\n * this.OR([\n * { GATE: predicateFunc1, ALT:() => { this.CONSUME(One) }},\n * { GATE: predicateFuncX, ALT:() => { this.CONSUME(Two) }},\n * { GATE: predicateFuncX, ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - These syntax forms can also be mixed:\n * ```\n * this.OR([\n * {\n * GATE: predicateFunc1,\n * ALT:() => { this.CONSUME(One) }\n * },\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - Additionally an \"options\" object may be used:\n * ```\n * this.OR({\n * DEF:[\n * { ALT:() => { this.CONSUME(One) }},\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ],\n * // OPTIONAL property\n * ERR_MSG: \"A Number\"\n * })\n * ```\n *\n * The 'predicateFuncX' in the long form can be used to add constraints to choosing the alternative.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the alternation production in it's top rule.\n *\n * @param altsOrOpts - A set of alternatives or an \"OPTIONS\" object describing the alternatives\n * and optional properties.\n *\n * @returns The result of invoking the chosen alternative.\n */\n OR: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR1: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR2: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR3: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR4: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR5: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR6: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR7: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR8: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR9: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n /**\n * Parsing DSL method, that indicates a repetition of zero or more.\n * This is equivalent to EBNF repetition \\{...\\}.\n *\n * Note that there are two syntax forms:\n * - Passing the grammar action directly:\n * ```\n * this.MANY(() => {\n * this.CONSUME(Comma)\n * this.CONSUME(Digit)\n * })\n * ```\n *\n * - using an \"options\" object:\n * ```\n * this.MANY({\n * GATE: predicateFunc,\n * DEF: () => {\n * this.CONSUME(Comma)\n * this.CONSUME(Digit)\n * }\n * });\n * ```\n *\n * The optional 'GATE' property in \"options\" object form can be used to add constraints\n * to invoking the grammar action.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the repetition production in it's top rule.\n *\n * @param actionORMethodDef - The grammar action to optionally invoke multiple times\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n */\n MANY: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY1: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY2: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY3: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY4: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY5: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY6: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY7: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY8: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY9: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n /**\n * Parsing DSL method, that indicates a repetition of zero or more with a separator\n * Token between the repetitions.\n *\n * Example:\n *\n * ```\n * this.MANY_SEP({\n * SEP:Comma,\n * DEF: () => {\n * this.CONSUME(Number};\n * // ...\n * })\n * ```\n *\n * Note that because this DSL method always requires more than one argument the options object is always required\n * and it is not possible to use a shorter form like in the MANY DSL method.\n *\n * Note that for the purposes of deciding on whether or not another iteration exists\n * Only a single Token is examined (The separator). Therefore if the grammar being implemented is\n * so \"crazy\" to require multiple tokens to identify an item separator please use the more basic DSL methods\n * to implement it.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the repetition production in it's top rule.\n *\n * @param options - An object defining the grammar of each iteration and the separator between iterations\n *\n */\n MANY_SEP: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP1: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP2: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP3: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP4: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP5: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP6: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP7: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP8: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP9: (options: ManySepMethodOpts<any>) => void;\n /**\n * Convenience method, same as MANY but the repetition is of one or more.\n * failing to match at least one repetition will result in a parsing error and\n * cause a parsing error.\n *\n * @see MANY\n *\n * @param actionORMethodDef - The grammar action to optionally invoke multiple times\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n */\n AT_LEAST_ONE: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE1: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE2: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE3: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE4: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE5: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE6: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE7: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE8: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE9: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n /**\n * Convenience method, same as MANY_SEP but the repetition is of one or more.\n * failing to match at least one repetition will result in a parsing error and\n * cause the parser to attempt error recovery.\n *\n * Note that an additional optional property ERR_MSG can be used to provide custom error messages.\n *\n * @see MANY_SEP\n *\n * @param options - An object defining the grammar of each iteration and the separator between iterations\n *\n * @return ISeparatedIterationResult<OUT>\n */\n AT_LEAST_ONE_SEP: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP1: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP2: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP3: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP4: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP5: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP6: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP7: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP8: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP9: (options: AtLeastOneSepMethodOpts<any>) => void;\n ACTION: <T>(impl: () => T) => T;\n BACKTRACK: BacktrackFunc;\n SUBRULE: SubRuleFunc;\n SUBRULE1: SubRuleFunc;\n SUBRULE2: SubRuleFunc;\n SUBRULE3: SubRuleFunc;\n SUBRULE4: SubRuleFunc;\n SUBRULE5: SubRuleFunc;\n SUBRULE6: SubRuleFunc;\n SUBRULE7: SubRuleFunc;\n SUBRULE8: SubRuleFunc;\n SUBRULE9: SubRuleFunc;\n}\n"]}
|
package/lib/index.cjs
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
6
|
var __export = (target, all) => {
|
|
12
7
|
for (var name in all)
|
|
13
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -20,314 +15,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
20
15
|
}
|
|
21
16
|
return to;
|
|
22
17
|
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
31
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
19
|
|
|
33
|
-
// ../../node_modules/rdf-data-factory/lib/BlankNode.js
|
|
34
|
-
var require_BlankNode = __commonJS({
|
|
35
|
-
"../../node_modules/rdf-data-factory/lib/BlankNode.js"(exports2) {
|
|
36
|
-
"use strict";
|
|
37
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
38
|
-
exports2.BlankNode = void 0;
|
|
39
|
-
var BlankNode = class {
|
|
40
|
-
constructor(value) {
|
|
41
|
-
this.termType = "BlankNode";
|
|
42
|
-
this.value = value;
|
|
43
|
-
}
|
|
44
|
-
equals(other) {
|
|
45
|
-
return !!other && other.termType === "BlankNode" && other.value === this.value;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
exports2.BlankNode = BlankNode;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// ../../node_modules/rdf-data-factory/lib/DefaultGraph.js
|
|
53
|
-
var require_DefaultGraph = __commonJS({
|
|
54
|
-
"../../node_modules/rdf-data-factory/lib/DefaultGraph.js"(exports2) {
|
|
55
|
-
"use strict";
|
|
56
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
57
|
-
exports2.DefaultGraph = void 0;
|
|
58
|
-
var DefaultGraph = class {
|
|
59
|
-
constructor() {
|
|
60
|
-
this.termType = "DefaultGraph";
|
|
61
|
-
this.value = "";
|
|
62
|
-
}
|
|
63
|
-
equals(other) {
|
|
64
|
-
return !!other && other.termType === "DefaultGraph";
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
exports2.DefaultGraph = DefaultGraph;
|
|
68
|
-
DefaultGraph.INSTANCE = new DefaultGraph();
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// ../../node_modules/rdf-data-factory/lib/NamedNode.js
|
|
73
|
-
var require_NamedNode = __commonJS({
|
|
74
|
-
"../../node_modules/rdf-data-factory/lib/NamedNode.js"(exports2) {
|
|
75
|
-
"use strict";
|
|
76
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
77
|
-
exports2.NamedNode = void 0;
|
|
78
|
-
var NamedNode = class {
|
|
79
|
-
constructor(value) {
|
|
80
|
-
this.termType = "NamedNode";
|
|
81
|
-
this.value = value;
|
|
82
|
-
}
|
|
83
|
-
equals(other) {
|
|
84
|
-
return !!other && other.termType === "NamedNode" && other.value === this.value;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
exports2.NamedNode = NamedNode;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// ../../node_modules/rdf-data-factory/lib/Literal.js
|
|
92
|
-
var require_Literal = __commonJS({
|
|
93
|
-
"../../node_modules/rdf-data-factory/lib/Literal.js"(exports2) {
|
|
94
|
-
"use strict";
|
|
95
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
96
|
-
exports2.Literal = void 0;
|
|
97
|
-
var NamedNode_1 = require_NamedNode();
|
|
98
|
-
var Literal = class _Literal {
|
|
99
|
-
constructor(value, languageOrDatatype) {
|
|
100
|
-
this.termType = "Literal";
|
|
101
|
-
this.value = value;
|
|
102
|
-
if (typeof languageOrDatatype === "string") {
|
|
103
|
-
this.language = languageOrDatatype;
|
|
104
|
-
this.datatype = _Literal.RDF_LANGUAGE_STRING;
|
|
105
|
-
this.direction = "";
|
|
106
|
-
} else if (languageOrDatatype) {
|
|
107
|
-
if ("termType" in languageOrDatatype) {
|
|
108
|
-
this.language = "";
|
|
109
|
-
this.datatype = languageOrDatatype;
|
|
110
|
-
this.direction = "";
|
|
111
|
-
} else {
|
|
112
|
-
this.language = languageOrDatatype.language;
|
|
113
|
-
this.datatype = languageOrDatatype.direction ? _Literal.RDF_DIRECTIONAL_LANGUAGE_STRING : _Literal.RDF_LANGUAGE_STRING;
|
|
114
|
-
this.direction = languageOrDatatype.direction || "";
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
this.language = "";
|
|
118
|
-
this.datatype = _Literal.XSD_STRING;
|
|
119
|
-
this.direction = "";
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
equals(other) {
|
|
123
|
-
return !!other && other.termType === "Literal" && other.value === this.value && other.language === this.language && (other.direction === this.direction || !other.direction && this.direction === "") && this.datatype.equals(other.datatype);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
exports2.Literal = Literal;
|
|
127
|
-
Literal.RDF_LANGUAGE_STRING = new NamedNode_1.NamedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
|
|
128
|
-
Literal.RDF_DIRECTIONAL_LANGUAGE_STRING = new NamedNode_1.NamedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#dirLangString");
|
|
129
|
-
Literal.XSD_STRING = new NamedNode_1.NamedNode("http://www.w3.org/2001/XMLSchema#string");
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// ../../node_modules/rdf-data-factory/lib/Quad.js
|
|
134
|
-
var require_Quad = __commonJS({
|
|
135
|
-
"../../node_modules/rdf-data-factory/lib/Quad.js"(exports2) {
|
|
136
|
-
"use strict";
|
|
137
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
138
|
-
exports2.Quad = void 0;
|
|
139
|
-
var Quad = class {
|
|
140
|
-
constructor(subject, predicate, object, graph) {
|
|
141
|
-
this.termType = "Quad";
|
|
142
|
-
this.value = "";
|
|
143
|
-
this.subject = subject;
|
|
144
|
-
this.predicate = predicate;
|
|
145
|
-
this.object = object;
|
|
146
|
-
this.graph = graph;
|
|
147
|
-
}
|
|
148
|
-
equals(other) {
|
|
149
|
-
return !!other && (other.termType === "Quad" || !other.termType) && this.subject.equals(other.subject) && this.predicate.equals(other.predicate) && this.object.equals(other.object) && this.graph.equals(other.graph);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
exports2.Quad = Quad;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
// ../../node_modules/rdf-data-factory/lib/Variable.js
|
|
157
|
-
var require_Variable = __commonJS({
|
|
158
|
-
"../../node_modules/rdf-data-factory/lib/Variable.js"(exports2) {
|
|
159
|
-
"use strict";
|
|
160
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
161
|
-
exports2.Variable = void 0;
|
|
162
|
-
var Variable = class {
|
|
163
|
-
constructor(value) {
|
|
164
|
-
this.termType = "Variable";
|
|
165
|
-
this.value = value;
|
|
166
|
-
}
|
|
167
|
-
equals(other) {
|
|
168
|
-
return !!other && other.termType === "Variable" && other.value === this.value;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
exports2.Variable = Variable;
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
// ../../node_modules/rdf-data-factory/lib/DataFactory.js
|
|
176
|
-
var require_DataFactory = __commonJS({
|
|
177
|
-
"../../node_modules/rdf-data-factory/lib/DataFactory.js"(exports2) {
|
|
178
|
-
"use strict";
|
|
179
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
180
|
-
exports2.DataFactory = void 0;
|
|
181
|
-
var BlankNode_1 = require_BlankNode();
|
|
182
|
-
var DefaultGraph_1 = require_DefaultGraph();
|
|
183
|
-
var Literal_1 = require_Literal();
|
|
184
|
-
var NamedNode_1 = require_NamedNode();
|
|
185
|
-
var Quad_1 = require_Quad();
|
|
186
|
-
var Variable_1 = require_Variable();
|
|
187
|
-
var dataFactoryCounter = 0;
|
|
188
|
-
var DataFactory2 = class {
|
|
189
|
-
constructor(options) {
|
|
190
|
-
this.blankNodeCounter = 0;
|
|
191
|
-
options = options || {};
|
|
192
|
-
this.blankNodePrefix = options.blankNodePrefix || `df_${dataFactoryCounter++}_`;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* @param value The IRI for the named node.
|
|
196
|
-
* @return A new instance of NamedNode.
|
|
197
|
-
* @see NamedNode
|
|
198
|
-
*/
|
|
199
|
-
namedNode(value) {
|
|
200
|
-
return new NamedNode_1.NamedNode(value);
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* @param value The optional blank node identifier.
|
|
204
|
-
* @return A new instance of BlankNode.
|
|
205
|
-
* If the `value` parameter is undefined a new identifier
|
|
206
|
-
* for the blank node is generated for each call.
|
|
207
|
-
* @see BlankNode
|
|
208
|
-
*/
|
|
209
|
-
blankNode(value) {
|
|
210
|
-
return new BlankNode_1.BlankNode(value || `${this.blankNodePrefix}${this.blankNodeCounter++}`);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* @param value The literal value.
|
|
214
|
-
* @param languageOrDatatype The optional language, datatype, or directional language.
|
|
215
|
-
* If `languageOrDatatype` is a NamedNode,
|
|
216
|
-
* then it is used for the value of `NamedNode.datatype`.
|
|
217
|
-
* If `languageOrDatatype` is a NamedNode, it is used for the value
|
|
218
|
-
* of `NamedNode.language`.
|
|
219
|
-
* Otherwise, it is used as a directional language,
|
|
220
|
-
* from which the language is set to `languageOrDatatype.language`
|
|
221
|
-
* and the direction to `languageOrDatatype.direction`.
|
|
222
|
-
* @return A new instance of Literal.
|
|
223
|
-
* @see Literal
|
|
224
|
-
*/
|
|
225
|
-
literal(value, languageOrDatatype) {
|
|
226
|
-
return new Literal_1.Literal(value, languageOrDatatype);
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* This method is optional.
|
|
230
|
-
* @param value The variable name
|
|
231
|
-
* @return A new instance of Variable.
|
|
232
|
-
* @see Variable
|
|
233
|
-
*/
|
|
234
|
-
variable(value) {
|
|
235
|
-
return new Variable_1.Variable(value);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* @return An instance of DefaultGraph.
|
|
239
|
-
*/
|
|
240
|
-
defaultGraph() {
|
|
241
|
-
return DefaultGraph_1.DefaultGraph.INSTANCE;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* @param subject The quad subject term.
|
|
245
|
-
* @param predicate The quad predicate term.
|
|
246
|
-
* @param object The quad object term.
|
|
247
|
-
* @param graph The quad graph term.
|
|
248
|
-
* @return A new instance of Quad.
|
|
249
|
-
* @see Quad
|
|
250
|
-
*/
|
|
251
|
-
quad(subject, predicate, object, graph) {
|
|
252
|
-
return new Quad_1.Quad(subject, predicate, object, graph || this.defaultGraph());
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Create a deep copy of the given term using this data factory.
|
|
256
|
-
* @param original An RDF term.
|
|
257
|
-
* @return A deep copy of the given term.
|
|
258
|
-
*/
|
|
259
|
-
fromTerm(original) {
|
|
260
|
-
switch (original.termType) {
|
|
261
|
-
case "NamedNode":
|
|
262
|
-
return this.namedNode(original.value);
|
|
263
|
-
case "BlankNode":
|
|
264
|
-
return this.blankNode(original.value);
|
|
265
|
-
case "Literal":
|
|
266
|
-
if (original.language) {
|
|
267
|
-
return this.literal(original.value, original.language);
|
|
268
|
-
}
|
|
269
|
-
if (!original.datatype.equals(Literal_1.Literal.XSD_STRING)) {
|
|
270
|
-
return this.literal(original.value, this.fromTerm(original.datatype));
|
|
271
|
-
}
|
|
272
|
-
return this.literal(original.value);
|
|
273
|
-
case "Variable":
|
|
274
|
-
return this.variable(original.value);
|
|
275
|
-
case "DefaultGraph":
|
|
276
|
-
return this.defaultGraph();
|
|
277
|
-
case "Quad":
|
|
278
|
-
return this.quad(this.fromTerm(original.subject), this.fromTerm(original.predicate), this.fromTerm(original.object), this.fromTerm(original.graph));
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Create a deep copy of the given quad using this data factory.
|
|
283
|
-
* @param original An RDF quad.
|
|
284
|
-
* @return A deep copy of the given quad.
|
|
285
|
-
*/
|
|
286
|
-
fromQuad(original) {
|
|
287
|
-
return this.fromTerm(original);
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Reset the internal blank node counter.
|
|
291
|
-
*/
|
|
292
|
-
resetBlankNodeCounter() {
|
|
293
|
-
this.blankNodeCounter = 0;
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
exports2.DataFactory = DataFactory2;
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
// ../../node_modules/rdf-data-factory/index.js
|
|
301
|
-
var require_rdf_data_factory = __commonJS({
|
|
302
|
-
"../../node_modules/rdf-data-factory/index.js"(exports2) {
|
|
303
|
-
"use strict";
|
|
304
|
-
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
305
|
-
if (k2 === void 0) k2 = k;
|
|
306
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
307
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
308
|
-
desc = { enumerable: true, get: function() {
|
|
309
|
-
return m[k];
|
|
310
|
-
} };
|
|
311
|
-
}
|
|
312
|
-
Object.defineProperty(o, k2, desc);
|
|
313
|
-
} : function(o, m, k, k2) {
|
|
314
|
-
if (k2 === void 0) k2 = k;
|
|
315
|
-
o[k2] = m[k];
|
|
316
|
-
});
|
|
317
|
-
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
|
|
318
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
319
|
-
};
|
|
320
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
321
|
-
__exportStar(require_BlankNode(), exports2);
|
|
322
|
-
__exportStar(require_DataFactory(), exports2);
|
|
323
|
-
__exportStar(require_DefaultGraph(), exports2);
|
|
324
|
-
__exportStar(require_Literal(), exports2);
|
|
325
|
-
__exportStar(require_NamedNode(), exports2);
|
|
326
|
-
__exportStar(require_Quad(), exports2);
|
|
327
|
-
__exportStar(require_Variable(), exports2);
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
|
|
331
20
|
// lib/index.ts
|
|
332
21
|
var index_exports = {};
|
|
333
22
|
__export(index_exports, {
|
|
@@ -1706,8 +1395,8 @@ var Promise2 = getNative_default(root_default, "Promise");
|
|
|
1706
1395
|
var Promise_default = Promise2;
|
|
1707
1396
|
|
|
1708
1397
|
// ../../node_modules/lodash-es/_Set.js
|
|
1709
|
-
var
|
|
1710
|
-
var Set_default =
|
|
1398
|
+
var Set = getNative_default(root_default, "Set");
|
|
1399
|
+
var Set_default = Set;
|
|
1711
1400
|
|
|
1712
1401
|
// ../../node_modules/lodash-es/_getTag.js
|
|
1713
1402
|
var mapTag2 = "[object Map]";
|
|
@@ -9560,7 +9249,6 @@ var EmbeddedActionsParser = class extends Parser {
|
|
|
9560
9249
|
};
|
|
9561
9250
|
|
|
9562
9251
|
// lib/grammar-builder/parserBuilder.ts
|
|
9563
|
-
var import_rdf_data_factory = __toESM(require_rdf_data_factory(), 1);
|
|
9564
9252
|
function listToRuleDefMap(rules) {
|
|
9565
9253
|
const newRules = {};
|
|
9566
9254
|
for (const rule of rules) {
|
|
@@ -9570,7 +9258,7 @@ function listToRuleDefMap(rules) {
|
|
|
9570
9258
|
}
|
|
9571
9259
|
var Builder = class _Builder {
|
|
9572
9260
|
/**
|
|
9573
|
-
* Create a builder
|
|
9261
|
+
* Create a builder from some initial grammar rules or an existing builder.
|
|
9574
9262
|
* If a builder is provided, a new copy will be created.
|
|
9575
9263
|
*/
|
|
9576
9264
|
static createBuilder(start) {
|
|
@@ -9612,10 +9300,20 @@ var Builder = class _Builder {
|
|
|
9612
9300
|
this.rules = { ...this.rules, ...listToRuleDefMap(rules) };
|
|
9613
9301
|
return this;
|
|
9614
9302
|
}
|
|
9303
|
+
/**
|
|
9304
|
+
* Delete a grammar rule by its name.
|
|
9305
|
+
*/
|
|
9615
9306
|
deleteRule(ruleName) {
|
|
9616
9307
|
delete this.rules[ruleName];
|
|
9617
9308
|
return this;
|
|
9618
9309
|
}
|
|
9310
|
+
/**
|
|
9311
|
+
* Merge this grammar builder with another.
|
|
9312
|
+
* It is best to merge the bigger grammar with the smaller one.
|
|
9313
|
+
* If the two builders both have a grammar rule with the same name, no error will be thrown case they map to the same ruledef object.
|
|
9314
|
+
* If they map to a different object, an error will be thrown.
|
|
9315
|
+
* To fix this problem, the overridingRules array should contain a rule with the same conflicting name, this rule implementation will be used.
|
|
9316
|
+
*/
|
|
9619
9317
|
merge(builder, overridingRules) {
|
|
9620
9318
|
const otherRules = { ...builder.rules };
|
|
9621
9319
|
const myRules = this.rules;
|
|
@@ -9637,7 +9335,7 @@ var Builder = class _Builder {
|
|
|
9637
9335
|
this.rules = otherRules;
|
|
9638
9336
|
return this;
|
|
9639
9337
|
}
|
|
9640
|
-
consumeToParser({ tokenVocabulary, parserConfig = {}, lexerConfig = {} }
|
|
9338
|
+
consumeToParser({ tokenVocabulary, parserConfig = {}, lexerConfig = {} }) {
|
|
9641
9339
|
const lexer = new Lexer(tokenVocabulary, {
|
|
9642
9340
|
positionTracking: "onlyStart",
|
|
9643
9341
|
recoveryEnabled: false,
|
|
@@ -9646,10 +9344,10 @@ var Builder = class _Builder {
|
|
|
9646
9344
|
ensureOptimizations: true,
|
|
9647
9345
|
...lexerConfig
|
|
9648
9346
|
});
|
|
9649
|
-
const parser = this.consume({ tokenVocabulary, config: parserConfig }
|
|
9347
|
+
const parser = this.consume({ tokenVocabulary, config: parserConfig });
|
|
9650
9348
|
const selfSufficientParser = {};
|
|
9651
9349
|
for (const rule of Object.values(this.rules)) {
|
|
9652
|
-
selfSufficientParser[rule.name] = (input,
|
|
9350
|
+
selfSufficientParser[rule.name] = (input, context, arg) => {
|
|
9653
9351
|
input = input.replaceAll(
|
|
9654
9352
|
/\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{8})/gu,
|
|
9655
9353
|
(_, unicode4, unicode8) => {
|
|
@@ -9669,9 +9367,9 @@ var Builder = class _Builder {
|
|
|
9669
9367
|
throw new Error(`Invalid unicode codepoint of surrogate pair without corresponding codepoint`);
|
|
9670
9368
|
}
|
|
9671
9369
|
const lexResult = lexer.tokenize(input);
|
|
9672
|
-
parser.reset();
|
|
9673
9370
|
parser.input = lexResult.tokens;
|
|
9674
|
-
|
|
9371
|
+
parser.setContext(context);
|
|
9372
|
+
const result = parser[rule.name](context, arg);
|
|
9675
9373
|
if (parser.errors.length > 0) {
|
|
9676
9374
|
throw new Error(`Parse error on line ${parser.errors.map((x) => x.token.startLine).join(", ")}
|
|
9677
9375
|
${parser.errors.map((x) => `${x.token.startLine}: ${x.message}`).join("\n")}`);
|
|
@@ -9681,9 +9379,18 @@ ${parser.errors.map((x) => `${x.token.startLine}: ${x.message}`).join("\n")}`);
|
|
|
9681
9379
|
}
|
|
9682
9380
|
return selfSufficientParser;
|
|
9683
9381
|
}
|
|
9684
|
-
consume({ tokenVocabulary, config = {} }
|
|
9382
|
+
consume({ tokenVocabulary, config = {} }) {
|
|
9685
9383
|
const rules = this.rules;
|
|
9686
9384
|
class MyParser extends EmbeddedActionsParser {
|
|
9385
|
+
getSafeContext() {
|
|
9386
|
+
if (this.context === void 0) {
|
|
9387
|
+
throw new Error("context was not correctly set");
|
|
9388
|
+
}
|
|
9389
|
+
return this.context;
|
|
9390
|
+
}
|
|
9391
|
+
setContext(context) {
|
|
9392
|
+
this.context = context;
|
|
9393
|
+
}
|
|
9687
9394
|
constructor() {
|
|
9688
9395
|
super(tokenVocabulary, {
|
|
9689
9396
|
// RecoveryEnabled: true,
|
|
@@ -9691,39 +9398,23 @@ ${parser.errors.map((x) => `${x.token.startLine}: ${x.message}`).join("\n")}`);
|
|
|
9691
9398
|
// SkipValidations: true,
|
|
9692
9399
|
...config
|
|
9693
9400
|
});
|
|
9401
|
+
this.context = void 0;
|
|
9694
9402
|
const selfRef = this.getSelfRef();
|
|
9695
|
-
this.initialParseContext = {
|
|
9696
|
-
dataFactory: new import_rdf_data_factory.DataFactory({ blankNodePrefix: "g_" }),
|
|
9697
|
-
baseIRI: void 0,
|
|
9698
|
-
parseMode: /* @__PURE__ */ new Set(),
|
|
9699
|
-
skipValidation: false,
|
|
9700
|
-
...context,
|
|
9701
|
-
prefixes: context.prefixes ? { ...context.prefixes } : {}
|
|
9702
|
-
};
|
|
9703
|
-
this.runningContext = {
|
|
9704
|
-
...this.initialParseContext,
|
|
9705
|
-
prefixes: { ...this.initialParseContext.prefixes },
|
|
9706
|
-
parseMode: new Set(this.initialParseContext.parseMode)
|
|
9707
|
-
};
|
|
9708
9403
|
const implArgs = {
|
|
9709
9404
|
...selfRef,
|
|
9710
|
-
cache: /* @__PURE__ */ new WeakMap()
|
|
9711
|
-
context: this.runningContext
|
|
9405
|
+
cache: /* @__PURE__ */ new WeakMap()
|
|
9712
9406
|
};
|
|
9713
9407
|
for (const rule of Object.values(rules)) {
|
|
9714
9408
|
this[rule.name] = this.RULE(rule.name, rule.impl(implArgs));
|
|
9715
9409
|
}
|
|
9716
9410
|
this.performSelfAnalysis();
|
|
9717
9411
|
}
|
|
9718
|
-
reset() {
|
|
9719
|
-
super.reset();
|
|
9720
|
-
Object.assign(this.runningContext, {
|
|
9721
|
-
...this.initialParseContext
|
|
9722
|
-
});
|
|
9723
|
-
this.runningContext.prefixes = { ...this.initialParseContext.prefixes };
|
|
9724
|
-
this.runningContext.parseMode = new Set(this.initialParseContext.parseMode);
|
|
9725
|
-
}
|
|
9726
9412
|
getSelfRef() {
|
|
9413
|
+
const subRuleImpl = (chevrotainSubrule) => {
|
|
9414
|
+
return (cstDef, arg) => {
|
|
9415
|
+
return chevrotainSubrule(this[cstDef.name], { ARGS: [this.context, arg] });
|
|
9416
|
+
};
|
|
9417
|
+
};
|
|
9727
9418
|
return {
|
|
9728
9419
|
CONSUME: (tokenType, option) => this.CONSUME(tokenType, option),
|
|
9729
9420
|
CONSUME1: (tokenType, option) => this.CONSUME1(tokenType, option),
|
|
@@ -9803,76 +9494,16 @@ ${parser.errors.map((x) => `${x.token.startLine}: ${x.message}`).join("\n")}`);
|
|
|
9803
9494
|
throw error;
|
|
9804
9495
|
}
|
|
9805
9496
|
},
|
|
9806
|
-
SUBRULE: (
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
|
|
9811
|
-
|
|
9812
|
-
|
|
9813
|
-
|
|
9814
|
-
|
|
9815
|
-
|
|
9816
|
-
} catch (error) {
|
|
9817
|
-
throw error;
|
|
9818
|
-
}
|
|
9819
|
-
},
|
|
9820
|
-
SUBRULE2: (cstDef, ...args) => {
|
|
9821
|
-
try {
|
|
9822
|
-
return this.SUBRULE2(this[cstDef.name], { ARGS: args });
|
|
9823
|
-
} catch (error) {
|
|
9824
|
-
throw error;
|
|
9825
|
-
}
|
|
9826
|
-
},
|
|
9827
|
-
SUBRULE3: (cstDef, ...args) => {
|
|
9828
|
-
try {
|
|
9829
|
-
return this.SUBRULE3(this[cstDef.name], { ARGS: args });
|
|
9830
|
-
} catch (error) {
|
|
9831
|
-
throw error;
|
|
9832
|
-
}
|
|
9833
|
-
},
|
|
9834
|
-
SUBRULE4: (cstDef, ...args) => {
|
|
9835
|
-
try {
|
|
9836
|
-
return this.SUBRULE4(this[cstDef.name], { ARGS: args });
|
|
9837
|
-
} catch (error) {
|
|
9838
|
-
throw error;
|
|
9839
|
-
}
|
|
9840
|
-
},
|
|
9841
|
-
SUBRULE5: (cstDef, ...args) => {
|
|
9842
|
-
try {
|
|
9843
|
-
return this.SUBRULE5(this[cstDef.name], { ARGS: args });
|
|
9844
|
-
} catch (error) {
|
|
9845
|
-
throw error;
|
|
9846
|
-
}
|
|
9847
|
-
},
|
|
9848
|
-
SUBRULE6: (cstDef, ...args) => {
|
|
9849
|
-
try {
|
|
9850
|
-
return this.SUBRULE6(this[cstDef.name], { ARGS: args });
|
|
9851
|
-
} catch (error) {
|
|
9852
|
-
throw error;
|
|
9853
|
-
}
|
|
9854
|
-
},
|
|
9855
|
-
SUBRULE7: (cstDef, ...args) => {
|
|
9856
|
-
try {
|
|
9857
|
-
return this.SUBRULE7(this[cstDef.name], { ARGS: args });
|
|
9858
|
-
} catch (error) {
|
|
9859
|
-
throw error;
|
|
9860
|
-
}
|
|
9861
|
-
},
|
|
9862
|
-
SUBRULE8: (cstDef, ...args) => {
|
|
9863
|
-
try {
|
|
9864
|
-
return this.SUBRULE8(this[cstDef.name], { ARGS: args });
|
|
9865
|
-
} catch (error) {
|
|
9866
|
-
throw error;
|
|
9867
|
-
}
|
|
9868
|
-
},
|
|
9869
|
-
SUBRULE9: (cstDef, ...args) => {
|
|
9870
|
-
try {
|
|
9871
|
-
return this.SUBRULE9(this[cstDef.name], { ARGS: args });
|
|
9872
|
-
} catch (error) {
|
|
9873
|
-
throw error;
|
|
9874
|
-
}
|
|
9875
|
-
}
|
|
9497
|
+
SUBRULE: subRuleImpl((rule, args) => this.SUBRULE(rule, args)),
|
|
9498
|
+
SUBRULE1: subRuleImpl((rule, args) => this.SUBRULE1(rule, args)),
|
|
9499
|
+
SUBRULE2: subRuleImpl((rule, args) => this.SUBRULE2(rule, args)),
|
|
9500
|
+
SUBRULE3: subRuleImpl((rule, args) => this.SUBRULE3(rule, args)),
|
|
9501
|
+
SUBRULE4: subRuleImpl((rule, args) => this.SUBRULE4(rule, args)),
|
|
9502
|
+
SUBRULE5: subRuleImpl((rule, args) => this.SUBRULE5(rule, args)),
|
|
9503
|
+
SUBRULE6: subRuleImpl((rule, args) => this.SUBRULE6(rule, args)),
|
|
9504
|
+
SUBRULE7: subRuleImpl((rule, args) => this.SUBRULE7(rule, args)),
|
|
9505
|
+
SUBRULE8: subRuleImpl((rule, args) => this.SUBRULE8(rule, args)),
|
|
9506
|
+
SUBRULE9: subRuleImpl((rule, args) => this.SUBRULE9(rule, args))
|
|
9876
9507
|
};
|
|
9877
9508
|
}
|
|
9878
9509
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@traqula/core",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.148+1455821",
|
|
4
4
|
"description": "Core components of TRAQULA",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,12 +38,10 @@
|
|
|
38
38
|
"build:transpile": "node \"../../node_modules/esbuild/bin/esbuild\" --format=cjs --bundle --log-level=error --outfile=lib/index.cjs lib/index.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"chevrotain": "^11.0.3"
|
|
42
|
-
"rdf-data-factory": "^2.0.1"
|
|
41
|
+
"chevrotain": "^11.0.3"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
|
-
"@chevrotain/types": "^11.0.3"
|
|
46
|
-
"@rdfjs/types": "^2.0.0"
|
|
44
|
+
"@chevrotain/types": "^11.0.3"
|
|
47
45
|
},
|
|
48
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "14558218b5c59739a791015d2bfbb466c5da9e62"
|
|
49
47
|
}
|