@traqula/core 0.0.1-alpha.137

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/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from './grammar-builder/builderTypes';
2
+ export * from './grammar-builder/parserBuilder';
3
+ export * from './grammar-builder/ruleDefTypes';
4
+ export * from './grammar-helpers/utils';
5
+ export * from './lexer-builder/LexerBuilder';
6
+ export * from './lexer-helper/utils';
7
+ export * from './Wildcard';
package/lib/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from './grammar-builder/builderTypes';
2
+ export * from './grammar-builder/parserBuilder';
3
+ export * from './grammar-builder/ruleDefTypes';
4
+ export * from './grammar-helpers/utils';
5
+ export * from './lexer-builder/LexerBuilder';
6
+ export * from './lexer-helper/utils';
7
+ export * from './Wildcard';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC","sourcesContent":["export * from './grammar-builder/builderTypes';\nexport * from './grammar-builder/parserBuilder';\nexport * from './grammar-builder/ruleDefTypes';\nexport * from './grammar-helpers/utils';\nexport * from './lexer-builder/LexerBuilder';\nexport * from './lexer-helper/utils';\nexport * from './Wildcard';\n"]}
@@ -0,0 +1,21 @@
1
+ import type { TokenType } from 'chevrotain';
2
+ import type { CheckOverlap } from '../grammar-builder/builderTypes';
3
+ type NamedToken<Name extends string> = TokenType & {
4
+ name: Name;
5
+ };
6
+ export declare class LexerBuilder<NAMES extends string = string> {
7
+ private readonly tokens;
8
+ static create<U extends LexerBuilder<T>, T extends string = ''>(starter?: U): U;
9
+ constructor(starter?: LexerBuilder<NAMES>);
10
+ get(index: number): TokenType;
11
+ merge<OtherNames extends string, OW extends string>(merge: LexerBuilder<OtherNames>, overwrite?: NamedToken<OW>[]): LexerBuilder<NAMES | OtherNames>;
12
+ add<Name extends string>(...token: CheckOverlap<Name, NAMES, NamedToken<Name>[]>): LexerBuilder<Name | NAMES>;
13
+ addBefore<Name extends string>(before: NamedToken<NAMES>, ...token: CheckOverlap<Name, NAMES, NamedToken<Name>[]>): LexerBuilder<NAMES | Name>;
14
+ private moveBeforeOrAfter;
15
+ moveBefore<Name extends string>(before: NamedToken<NAMES>, ...tokens: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>): LexerBuilder<NAMES>;
16
+ moveAfter<Name extends string>(after: NamedToken<NAMES>, ...tokens: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>): LexerBuilder<NAMES>;
17
+ addAfter<Name extends string>(after: NamedToken<NAMES>, ...token: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>): LexerBuilder<NAMES | Name>;
18
+ delete<Name extends NAMES>(...token: NamedToken<Name>[]): LexerBuilder<Exclude<NAMES, Name>>;
19
+ build(): TokenType[];
20
+ }
21
+ export {};
@@ -0,0 +1,84 @@
1
+ export class LexerBuilder {
2
+ static create(starter) {
3
+ return new LexerBuilder(starter);
4
+ }
5
+ constructor(starter) {
6
+ this.tokens = starter?.tokens ? [...starter.tokens] : [];
7
+ }
8
+ get(index) {
9
+ return this.tokens[index];
10
+ }
11
+ merge(merge, overwrite = []) {
12
+ const extraTokens = merge.tokens.filter((token) => {
13
+ const overwriteToken = overwrite.find(t => t.name === token.name);
14
+ if (overwriteToken) {
15
+ return false;
16
+ }
17
+ const match = this.tokens.find(t => t.name === token.name);
18
+ if (match) {
19
+ if (match !== token) {
20
+ throw new Error(`Token with name ${token.name} already exists. Implementation is different and no overwrite was provided.`);
21
+ }
22
+ return false;
23
+ }
24
+ return true;
25
+ });
26
+ this.tokens.push(...extraTokens);
27
+ return this;
28
+ }
29
+ add(...token) {
30
+ this.tokens.push(...token);
31
+ return this;
32
+ }
33
+ addBefore(before, ...token) {
34
+ const index = this.tokens.indexOf(before);
35
+ if (index === -1) {
36
+ throw new Error('Token not found');
37
+ }
38
+ this.tokens.splice(index, 0, ...token);
39
+ return this;
40
+ }
41
+ moveBeforeOrAfter(beforeOrAfter, before, ...tokens) {
42
+ const beforeIndex = this.tokens.indexOf(before) + (beforeOrAfter === 'before' ? 0 : 1);
43
+ if (beforeIndex === -1) {
44
+ throw new Error('BeforeToken not found');
45
+ }
46
+ for (const token of tokens) {
47
+ const tokenIndex = this.tokens.indexOf(token);
48
+ if (tokenIndex === -1) {
49
+ throw new Error('Token not found');
50
+ }
51
+ this.tokens.splice(tokenIndex, 1);
52
+ this.tokens.splice(beforeIndex, 0, token);
53
+ }
54
+ return this;
55
+ }
56
+ moveBefore(before, ...tokens) {
57
+ return this.moveBeforeOrAfter('before', before, ...tokens);
58
+ }
59
+ moveAfter(after, ...tokens) {
60
+ return this.moveBeforeOrAfter('after', after, ...tokens);
61
+ }
62
+ addAfter(after, ...token) {
63
+ const index = this.tokens.indexOf(after);
64
+ if (index === -1) {
65
+ throw new Error('Token not found');
66
+ }
67
+ this.tokens.splice(index + 1, 0, ...token);
68
+ return this;
69
+ }
70
+ delete(...token) {
71
+ for (const t of token) {
72
+ const index = this.tokens.indexOf(t);
73
+ if (index === -1) {
74
+ throw new Error('Token not found');
75
+ }
76
+ this.tokens.splice(index, 1);
77
+ }
78
+ return this;
79
+ }
80
+ build() {
81
+ return this.tokens;
82
+ }
83
+ }
84
+ //# sourceMappingURL=LexerBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LexerBuilder.js","sourceRoot":"","sources":["LexerBuilder.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,YAAY;IAGhB,MAAM,CAAC,MAAM,CAAmD,OAAW;QAChF,OAAW,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,YAAmB,O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AC;IAEM,SAAS,CACd,KAAwB,EACxB,GAAG,MAA4D;QAE/D,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,CAAC;IAC3D,CAAC;IAEM,QAAQ,CACb,KAAwB,EACxB,GAAG,KAA2D;QAE9D,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,MAAM,CAAqB,GAAG,KAAyB;QAC5D,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACtB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACrC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;YACrC,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK;QACV,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF","sourcesContent":["import type { TokenType } from 'chevrotain';\nimport type { CheckOverlap } from '../grammar-builder/builderTypes';\n\ntype NamedToken<Name extends string> = TokenType & { name: Name };\n\nexport class LexerBuilder<NAMES extends string = string> {\n private readonly tokens: TokenType[];\n\n public static create<U extends LexerBuilder<T>, T extends string = ''>(starter?: U): U {\n return <U> new LexerBuilder(starter);\n }\n\n public constructor(starter?: LexerBuilder<NAMES>) {\n this.tokens = starter?.tokens ? [ ...starter.tokens ] : [];\n }\n\n public get(index: number): TokenType {\n return this.tokens[index];\n }\n\n public merge<OtherNames extends string, OW extends string>(\n merge: LexerBuilder<OtherNames>,\n overwrite: NamedToken<OW>[] = [],\n ):\n LexerBuilder<NAMES | OtherNames> {\n const extraTokens = merge.tokens.filter((token) => {\n const overwriteToken = overwrite.find(t => t.name === token.name);\n if (overwriteToken) {\n return false;\n }\n const match = this.tokens.find(t => t.name === token.name);\n if (match) {\n if (match !== token) {\n throw new Error(`Token with name ${token.name} already exists. Implementation is different and no overwrite was provided.`);\n }\n return false;\n }\n return true;\n });\n this.tokens.push(...extraTokens);\n return this;\n }\n\n public add<Name extends string>(...token: CheckOverlap<Name, NAMES, NamedToken<Name>[]>):\n LexerBuilder<Name | NAMES> {\n this.tokens.push(...token);\n return this;\n }\n\n public addBefore<Name extends string>(\n before: NamedToken<NAMES>,\n ...token: CheckOverlap<Name, NAMES, NamedToken<Name>[]>\n ): LexerBuilder<NAMES | Name> {\n const index = this.tokens.indexOf(before);\n if (index === -1) {\n throw new Error('Token not found');\n }\n this.tokens.splice(index, 0, ...token);\n return this;\n }\n\n private moveBeforeOrAfter<Name extends string>(\n beforeOrAfter: 'before' | 'after',\n before: NamedToken<NAMES>,\n ...tokens: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>\n ): LexerBuilder<NAMES> {\n const beforeIndex = this.tokens.indexOf(before) + (beforeOrAfter === 'before' ? 0 : 1);\n if (beforeIndex === -1) {\n throw new Error('BeforeToken not found');\n }\n for (const token of tokens) {\n const tokenIndex = this.tokens.indexOf(token);\n if (tokenIndex === -1) {\n throw new Error('Token not found');\n }\n this.tokens.splice(tokenIndex, 1);\n this.tokens.splice(beforeIndex, 0, token);\n }\n return this;\n }\n\n public moveBefore<Name extends string>(\n before: NamedToken<NAMES>,\n ...tokens: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>\n ): LexerBuilder<NAMES> {\n return this.moveBeforeOrAfter('before', before, ...tokens);\n }\n\n public moveAfter<Name extends string>(\n after: NamedToken<NAMES>,\n ...tokens: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>\n ): LexerBuilder<NAMES> {\n return this.moveBeforeOrAfter('after', after, ...tokens);\n }\n\n public addAfter<Name extends string>(\n after: NamedToken<NAMES>,\n ...token: CheckOverlap<Name, NAMES, never, NamedToken<Name>[]>\n ): LexerBuilder<NAMES | Name> {\n const index = this.tokens.indexOf(after);\n if (index === -1) {\n throw new Error('Token not found');\n }\n this.tokens.splice(index + 1, 0, ...token);\n return this;\n }\n\n public delete<Name extends NAMES>(...token: NamedToken<Name>[]): LexerBuilder<Exclude<NAMES, Name>> {\n for (const t of token) {\n const index = this.tokens.indexOf(t);\n if (index === -1) {\n throw new Error('Token not found');\n }\n this.tokens.splice(index, 1);\n }\n return this;\n }\n\n public build(): TokenType[] {\n return this.tokens;\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { ITokenConfig, TokenType } from '@chevrotain/types';
2
+ export declare function createToken<U extends string>(config: ITokenConfig & {
3
+ name: U;
4
+ }): TokenType & {
5
+ name: U;
6
+ };
@@ -0,0 +1,5 @@
1
+ import { createToken as chevcT } from 'chevrotain';
2
+ export function createToken(config) {
3
+ return chevcT(config);
4
+ }
5
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,UAAU,WAAW,CAAmB,MAAkC;IAC9E,OAAiC,MAAM,CAAC,MAAM,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import type { ITokenConfig, TokenType } from '@chevrotain/types';\nimport { createToken as chevcT } from 'chevrotain';\n\nexport function createToken<U extends string>(config: ITokenConfig & { name: U }): TokenType & { name: U } {\n return <TokenType & { name: U }> chevcT(config);\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@traqula/core",
3
+ "version": "0.0.1-alpha.137+3a4c48f",
4
+ "description": "Core components of TRAQULA",
5
+ "lsd:module": true,
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/comunica/traqula.git",
10
+ "directory": "packages/core"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/comunica/traqula/issues"
14
+ },
15
+ "sideEffects": false,
16
+ "type": "module",
17
+ "main": "lib/index.js",
18
+ "exports": {
19
+ "import": "./lib/index.js",
20
+ "require": "./lib/index.cjs"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "files": [
26
+ "lib/**/*.d.ts",
27
+ "lib/**/*.js",
28
+ "lib/**/*.cjs",
29
+ "lib/**/*.js.map"
30
+ ],
31
+ "engines": {
32
+ "node": ">=18.0"
33
+ },
34
+ "typings": "lib/index",
35
+ "scripts": {
36
+ "build": "yarn build:ts && yarn build:transpile",
37
+ "build:ts": "node \"../../node_modules/typescript/bin/tsc\"",
38
+ "build:transpile": "node \"../../node_modules/esbuild/bin/esbuild\" --format=cjs --bundle --log-level=error --outfile=lib/index.cjs lib/index.ts"
39
+ },
40
+ "dependencies": {
41
+ "chevrotain": "^11.0.3",
42
+ "rdf-data-factory": "^2.0.1"
43
+ },
44
+ "gitHead": "3a4c48fd219306b10726fb018b5a1f0ac2abed81"
45
+ }