@stackables/bridge-compiler 0.0.1
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/LICENSE +21 -0
- package/build/bridge-format.d.ts +8 -0
- package/build/bridge-format.d.ts.map +1 -0
- package/build/bridge-format.js +1334 -0
- package/build/bridge-lint.d.ts +3 -0
- package/build/bridge-lint.d.ts.map +1 -0
- package/build/bridge-lint.js +73 -0
- package/build/index.d.ts +13 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +13 -0
- package/build/language-service.d.ts +50 -0
- package/build/language-service.d.ts.map +1 -0
- package/build/language-service.js +243 -0
- package/build/parser/index.d.ts +9 -0
- package/build/parser/index.d.ts.map +1 -0
- package/build/parser/index.js +7 -0
- package/build/parser/lexer.d.ts +68 -0
- package/build/parser/lexer.d.ts.map +1 -0
- package/build/parser/lexer.js +160 -0
- package/build/parser/parser.d.ts +29 -0
- package/build/parser/parser.d.ts.map +1 -0
- package/build/parser/parser.js +4538 -0
- package/package.json +39 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chevrotain Lexer for the Bridge DSL.
|
|
3
|
+
*
|
|
4
|
+
* Tokenizes .bridge source text into a stream consumed by the CstParser.
|
|
5
|
+
* Comments and whitespace are automatically skipped (placed on hidden channels).
|
|
6
|
+
*/
|
|
7
|
+
import { createToken, Lexer } from "chevrotain";
|
|
8
|
+
// ── Whitespace & comments ──────────────────────────────────────────────────
|
|
9
|
+
export const Newline = createToken({
|
|
10
|
+
name: "Newline",
|
|
11
|
+
pattern: /\r?\n/,
|
|
12
|
+
group: Lexer.SKIPPED,
|
|
13
|
+
});
|
|
14
|
+
export const WS = createToken({
|
|
15
|
+
name: "WS",
|
|
16
|
+
pattern: /[ \t]+/,
|
|
17
|
+
group: Lexer.SKIPPED,
|
|
18
|
+
});
|
|
19
|
+
export const Comment = createToken({
|
|
20
|
+
name: "Comment",
|
|
21
|
+
pattern: /#[^\r\n]*/,
|
|
22
|
+
group: Lexer.SKIPPED,
|
|
23
|
+
});
|
|
24
|
+
// ── Identifiers (defined first — keywords reference via longer_alt) ────────
|
|
25
|
+
export const Identifier = createToken({
|
|
26
|
+
name: "Identifier",
|
|
27
|
+
pattern: /[a-zA-Z_][\w-]*/,
|
|
28
|
+
});
|
|
29
|
+
// ── Keywords ───────────────────────────────────────────────────────────────
|
|
30
|
+
export const VersionKw = createToken({ name: "VersionKw", pattern: /version/i, longer_alt: Identifier });
|
|
31
|
+
export const ToolKw = createToken({ name: "ToolKw", pattern: /tool/i, longer_alt: Identifier });
|
|
32
|
+
export const BridgeKw = createToken({ name: "BridgeKw", pattern: /bridge/i, longer_alt: Identifier });
|
|
33
|
+
export const DefineKw = createToken({ name: "DefineKw", pattern: /define/i, longer_alt: Identifier });
|
|
34
|
+
export const ConstKw = createToken({ name: "ConstKw", pattern: /const/i, longer_alt: Identifier });
|
|
35
|
+
export const WithKw = createToken({ name: "WithKw", pattern: /with/i, longer_alt: Identifier });
|
|
36
|
+
export const AsKw = createToken({ name: "AsKw", pattern: /as/i, longer_alt: Identifier });
|
|
37
|
+
export const FromKw = createToken({ name: "FromKw", pattern: /from/i, longer_alt: Identifier });
|
|
38
|
+
export const InputKw = createToken({ name: "InputKw", pattern: /input/i, longer_alt: Identifier });
|
|
39
|
+
export const OutputKw = createToken({ name: "OutputKw", pattern: /output/i, longer_alt: Identifier });
|
|
40
|
+
export const ContextKw = createToken({ name: "ContextKw", pattern: /context/i, longer_alt: Identifier });
|
|
41
|
+
export const OnKw = createToken({ name: "OnKw", pattern: /on/i, longer_alt: Identifier });
|
|
42
|
+
export const ErrorKw = createToken({ name: "ErrorKw", pattern: /error/i, longer_alt: Identifier });
|
|
43
|
+
export const ForceKw = createToken({ name: "ForceKw", pattern: /force/i, longer_alt: Identifier });
|
|
44
|
+
export const AliasKw = createToken({ name: "AliasKw", pattern: /alias/i, longer_alt: Identifier });
|
|
45
|
+
export const CatchKw = createToken({ name: "CatchKw", pattern: /catch/i, longer_alt: Identifier });
|
|
46
|
+
export const AndKw = createToken({ name: "AndKw", pattern: /and/, longer_alt: Identifier });
|
|
47
|
+
export const OrKw = createToken({ name: "OrKw", pattern: /or/, longer_alt: Identifier });
|
|
48
|
+
export const NotKw = createToken({ name: "NotKw", pattern: /not/, longer_alt: Identifier });
|
|
49
|
+
export const ThrowKw = createToken({ name: "ThrowKw", pattern: /throw/, longer_alt: Identifier });
|
|
50
|
+
export const PanicKw = createToken({ name: "PanicKw", pattern: /panic/, longer_alt: Identifier });
|
|
51
|
+
export const ContinueKw = createToken({ name: "ContinueKw", pattern: /continue/, longer_alt: Identifier });
|
|
52
|
+
export const BreakKw = createToken({ name: "BreakKw", pattern: /break/, longer_alt: Identifier });
|
|
53
|
+
// ── Operators & punctuation ────────────────────────────────────────────────
|
|
54
|
+
export const Arrow = createToken({ name: "Arrow", pattern: /<-/ });
|
|
55
|
+
export const NullCoalesce = createToken({ name: "NullCoalesce", pattern: /\|\|/ });
|
|
56
|
+
export const ErrorCoalesce = createToken({ name: "ErrorCoalesce", pattern: /\?\?/ });
|
|
57
|
+
export const SafeNav = createToken({ name: "SafeNav", pattern: /\?\./ });
|
|
58
|
+
export const QuestionMark = createToken({ name: "QuestionMark", pattern: /\?/ });
|
|
59
|
+
export const GreaterEqual = createToken({ name: "GreaterEqual", pattern: />=/ });
|
|
60
|
+
export const LessEqual = createToken({ name: "LessEqual", pattern: /<=/ });
|
|
61
|
+
export const DoubleEquals = createToken({ name: "DoubleEquals", pattern: /==/ });
|
|
62
|
+
export const NotEquals = createToken({ name: "NotEquals", pattern: /!=/ });
|
|
63
|
+
export const GreaterThan = createToken({ name: "GreaterThan", pattern: />/ });
|
|
64
|
+
export const LessThan = createToken({ name: "LessThan", pattern: /</ });
|
|
65
|
+
export const Star = createToken({ name: "Star", pattern: /\*/ });
|
|
66
|
+
export const Plus = createToken({ name: "Plus", pattern: /\+/ });
|
|
67
|
+
export const LParen = createToken({ name: "LParen", pattern: /\(/ });
|
|
68
|
+
export const RParen = createToken({ name: "RParen", pattern: /\)/ });
|
|
69
|
+
export const LCurly = createToken({ name: "LCurly", pattern: /\{/ });
|
|
70
|
+
export const RCurly = createToken({ name: "RCurly", pattern: /\}/ });
|
|
71
|
+
export const LSquare = createToken({ name: "LSquare", pattern: /\[/ });
|
|
72
|
+
export const RSquare = createToken({ name: "RSquare", pattern: /\]/ });
|
|
73
|
+
export const Equals = createToken({ name: "Equals", pattern: /=/ });
|
|
74
|
+
export const Dot = createToken({ name: "Dot", pattern: /\./ });
|
|
75
|
+
export const Colon = createToken({ name: "Colon", pattern: /:/ });
|
|
76
|
+
export const Comma = createToken({ name: "Comma", pattern: /,/ });
|
|
77
|
+
// ── Literals ───────────────────────────────────────────────────────────────
|
|
78
|
+
export const StringLiteral = createToken({
|
|
79
|
+
name: "StringLiteral",
|
|
80
|
+
pattern: /"(?:[^"\\]|\\.)*"/,
|
|
81
|
+
});
|
|
82
|
+
export const NumberLiteral = createToken({
|
|
83
|
+
name: "NumberLiteral",
|
|
84
|
+
pattern: /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/,
|
|
85
|
+
});
|
|
86
|
+
export const TrueLiteral = createToken({ name: "TrueLiteral", pattern: /true/, longer_alt: Identifier });
|
|
87
|
+
export const FalseLiteral = createToken({ name: "FalseLiteral", pattern: /false/, longer_alt: Identifier });
|
|
88
|
+
export const NullLiteral = createToken({ name: "NullLiteral", pattern: /null/, longer_alt: Identifier });
|
|
89
|
+
export const PathToken = createToken({
|
|
90
|
+
name: "PathToken",
|
|
91
|
+
pattern: /\/[\w./-]+/,
|
|
92
|
+
});
|
|
93
|
+
export const Slash = createToken({ name: "Slash", pattern: /\// });
|
|
94
|
+
export const Minus = createToken({ name: "Minus", pattern: /-/ });
|
|
95
|
+
// ── Token ordering ─────────────────────────────────────────────────────────
|
|
96
|
+
export const allTokens = [
|
|
97
|
+
WS,
|
|
98
|
+
Comment,
|
|
99
|
+
Newline,
|
|
100
|
+
Arrow,
|
|
101
|
+
NullCoalesce,
|
|
102
|
+
ErrorCoalesce,
|
|
103
|
+
SafeNav,
|
|
104
|
+
QuestionMark,
|
|
105
|
+
GreaterEqual,
|
|
106
|
+
LessEqual,
|
|
107
|
+
DoubleEquals,
|
|
108
|
+
NotEquals,
|
|
109
|
+
GreaterThan,
|
|
110
|
+
LessThan,
|
|
111
|
+
Star,
|
|
112
|
+
Plus,
|
|
113
|
+
LParen,
|
|
114
|
+
RParen,
|
|
115
|
+
LCurly,
|
|
116
|
+
RCurly,
|
|
117
|
+
LSquare,
|
|
118
|
+
RSquare,
|
|
119
|
+
Equals,
|
|
120
|
+
Dot,
|
|
121
|
+
Colon,
|
|
122
|
+
Comma,
|
|
123
|
+
StringLiteral,
|
|
124
|
+
// Keywords before Identifier (longer_alt prevents prefix stealing)
|
|
125
|
+
VersionKw,
|
|
126
|
+
ToolKw,
|
|
127
|
+
BridgeKw,
|
|
128
|
+
DefineKw,
|
|
129
|
+
ConstKw,
|
|
130
|
+
WithKw,
|
|
131
|
+
AsKw,
|
|
132
|
+
FromKw,
|
|
133
|
+
InputKw,
|
|
134
|
+
OutputKw,
|
|
135
|
+
ContextKw,
|
|
136
|
+
OnKw,
|
|
137
|
+
ErrorKw,
|
|
138
|
+
ForceKw,
|
|
139
|
+
AliasKw,
|
|
140
|
+
CatchKw,
|
|
141
|
+
AndKw,
|
|
142
|
+
OrKw,
|
|
143
|
+
NotKw,
|
|
144
|
+
ThrowKw,
|
|
145
|
+
PanicKw,
|
|
146
|
+
ContinueKw,
|
|
147
|
+
BreakKw,
|
|
148
|
+
TrueLiteral,
|
|
149
|
+
FalseLiteral,
|
|
150
|
+
NullLiteral,
|
|
151
|
+
PathToken,
|
|
152
|
+
Slash,
|
|
153
|
+
NumberLiteral,
|
|
154
|
+
Minus,
|
|
155
|
+
Identifier,
|
|
156
|
+
];
|
|
157
|
+
export const BridgeLexer = new Lexer(allTokens, {
|
|
158
|
+
ensureOptimizations: true,
|
|
159
|
+
positionTracking: "full",
|
|
160
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Instruction } from "@stackables/bridge-core";
|
|
2
|
+
export declare function parseBridgeChevrotain(text: string): Instruction[];
|
|
3
|
+
export type BridgeDiagnostic = {
|
|
4
|
+
message: string;
|
|
5
|
+
severity: "error" | "warning";
|
|
6
|
+
range: {
|
|
7
|
+
start: {
|
|
8
|
+
line: number;
|
|
9
|
+
character: number;
|
|
10
|
+
};
|
|
11
|
+
end: {
|
|
12
|
+
line: number;
|
|
13
|
+
character: number;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export type BridgeParseResult = {
|
|
18
|
+
instructions: Instruction[];
|
|
19
|
+
diagnostics: BridgeDiagnostic[];
|
|
20
|
+
/** 1-based start line for each top-level instruction */
|
|
21
|
+
startLines: Map<Instruction, number>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Parse a Bridge DSL text and return both the AST and all diagnostics.
|
|
25
|
+
* Uses Chevrotain's error recovery — always returns a (possibly partial) AST
|
|
26
|
+
* even when the file has errors. Designed for LSP/IDE use.
|
|
27
|
+
*/
|
|
28
|
+
export declare function parseBridgeDiagnostics(text: string): BridgeParseResult;
|
|
29
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser/parser.ts"],"names":[],"mappings":"AAmEA,OAAO,KAAK,EAMV,WAAW,EAMZ,MAAM,yBAAyB,CAAC;AAimCjC,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CAEjE;AAID,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,KAAK,EAAE;QACL,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAC;QAC3C,GAAG,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAC;KAC1C,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC,wDAAwD;IACxD,UAAU,EAAE,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CA8DtE"}
|