@chikx/compiler 0.0.0-stage → 0.1.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/README.md +40 -2
- package/dist/emitter/index.d.ts +96 -0
- package/dist/emitter/index.d.ts.map +1 -0
- package/dist/emitter/index.js +415 -0
- package/dist/emitter/index.js.map +1 -0
- package/dist/formatter/index.d.ts +53 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +464 -0
- package/dist/formatter/index.js.map +1 -0
- package/dist/host/node.d.ts +34 -0
- package/dist/host/node.d.ts.map +1 -0
- package/dist/host/node.js +80 -0
- package/dist/host/node.js.map +1 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +792 -0
- package/dist/index.js.map +1 -0
- package/dist/ir/factories.d.ts +35 -0
- package/dist/ir/factories.d.ts.map +1 -0
- package/dist/ir/factories.js +47 -0
- package/dist/ir/factories.js.map +1 -0
- package/dist/ir/index.d.ts +13 -0
- package/dist/ir/index.d.ts.map +1 -0
- package/dist/ir/index.js +2 -0
- package/dist/ir/index.js.map +1 -0
- package/dist/ir/types.d.ts +139 -0
- package/dist/ir/types.d.ts.map +1 -0
- package/dist/ir/types.js +2 -0
- package/dist/ir/types.js.map +1 -0
- package/dist/lexer/at-keywords.d.ts +27 -0
- package/dist/lexer/at-keywords.d.ts.map +1 -0
- package/dist/lexer/at-keywords.js +35 -0
- package/dist/lexer/at-keywords.js.map +1 -0
- package/dist/lexer/characters.d.ts +38 -0
- package/dist/lexer/characters.d.ts.map +1 -0
- package/dist/lexer/characters.js +74 -0
- package/dist/lexer/characters.js.map +1 -0
- package/dist/lexer/comments.d.ts +22 -0
- package/dist/lexer/comments.d.ts.map +1 -0
- package/dist/lexer/comments.js +20 -0
- package/dist/lexer/comments.js.map +1 -0
- package/dist/lexer/diagnostics.d.ts +24 -0
- package/dist/lexer/diagnostics.d.ts.map +1 -0
- package/dist/lexer/diagnostics.js +29 -0
- package/dist/lexer/diagnostics.js.map +1 -0
- package/dist/lexer/dollar-refs.d.ts +13 -0
- package/dist/lexer/dollar-refs.d.ts.map +1 -0
- package/dist/lexer/dollar-refs.js +22 -0
- package/dist/lexer/dollar-refs.js.map +1 -0
- package/dist/lexer/index.d.ts +32 -0
- package/dist/lexer/index.d.ts.map +1 -0
- package/dist/lexer/index.js +26 -0
- package/dist/lexer/index.js.map +1 -0
- package/dist/lexer/names.d.ts +23 -0
- package/dist/lexer/names.d.ts.map +1 -0
- package/dist/lexer/names.js +48 -0
- package/dist/lexer/names.js.map +1 -0
- package/dist/lexer/numbers.d.ts +22 -0
- package/dist/lexer/numbers.d.ts.map +1 -0
- package/dist/lexer/numbers.js +60 -0
- package/dist/lexer/numbers.js.map +1 -0
- package/dist/lexer/scanner.d.ts +30 -0
- package/dist/lexer/scanner.d.ts.map +1 -0
- package/dist/lexer/scanner.js +158 -0
- package/dist/lexer/scanner.js.map +1 -0
- package/dist/lexer/strings.d.ts +25 -0
- package/dist/lexer/strings.d.ts.map +1 -0
- package/dist/lexer/strings.js +41 -0
- package/dist/lexer/strings.js.map +1 -0
- package/dist/lexer/urls.d.ts +28 -0
- package/dist/lexer/urls.d.ts.map +1 -0
- package/dist/lexer/urls.js +54 -0
- package/dist/lexer/urls.js.map +1 -0
- package/dist/lowering/expand-groups.d.ts +61 -0
- package/dist/lowering/expand-groups.d.ts.map +1 -0
- package/dist/lowering/expand-groups.js +117 -0
- package/dist/lowering/expand-groups.js.map +1 -0
- package/dist/lowering/group.d.ts +30 -0
- package/dist/lowering/group.d.ts.map +1 -0
- package/dist/lowering/group.js +109 -0
- package/dist/lowering/group.js.map +1 -0
- package/dist/lowering/index.d.ts +26 -0
- package/dist/lowering/index.d.ts.map +1 -0
- package/dist/lowering/index.js +23 -0
- package/dist/lowering/index.js.map +1 -0
- package/dist/lowering/lower.d.ts +21 -0
- package/dist/lowering/lower.d.ts.map +1 -0
- package/dist/lowering/lower.js +296 -0
- package/dist/lowering/lower.js.map +1 -0
- package/dist/lowering/media.d.ts +63 -0
- package/dist/lowering/media.d.ts.map +1 -0
- package/dist/lowering/media.js +237 -0
- package/dist/lowering/media.js.map +1 -0
- package/dist/lowering/merge.d.ts +35 -0
- package/dist/lowering/merge.d.ts.map +1 -0
- package/dist/lowering/merge.js +146 -0
- package/dist/lowering/merge.js.map +1 -0
- package/dist/lowering/property-families.d.ts +50 -0
- package/dist/lowering/property-families.d.ts.map +1 -0
- package/dist/lowering/property-families.js +175 -0
- package/dist/lowering/property-families.js.map +1 -0
- package/dist/lowering/spans.d.ts +36 -0
- package/dist/lowering/spans.d.ts.map +1 -0
- package/dist/lowering/spans.js +100 -0
- package/dist/lowering/spans.js.map +1 -0
- package/dist/naming/index.d.ts +37 -0
- package/dist/naming/index.d.ts.map +1 -0
- package/dist/naming/index.js +34 -0
- package/dist/naming/index.js.map +1 -0
- package/dist/naming/mapgen.d.ts +70 -0
- package/dist/naming/mapgen.d.ts.map +1 -0
- package/dist/naming/mapgen.js +153 -0
- package/dist/naming/mapgen.js.map +1 -0
- package/dist/naming/merge.d.ts +62 -0
- package/dist/naming/merge.d.ts.map +1 -0
- package/dist/naming/merge.js +77 -0
- package/dist/naming/merge.js.map +1 -0
- package/dist/naming/rewrite.d.ts +14 -0
- package/dist/naming/rewrite.d.ts.map +1 -0
- package/dist/naming/rewrite.js +191 -0
- package/dist/naming/rewrite.js.map +1 -0
- package/dist/naming/scan.d.ts +80 -0
- package/dist/naming/scan.d.ts.map +1 -0
- package/dist/naming/scan.js +193 -0
- package/dist/naming/scan.js.map +1 -0
- package/dist/naming/table.d.ts +68 -0
- package/dist/naming/table.d.ts.map +1 -0
- package/dist/naming/table.js +132 -0
- package/dist/naming/table.js.map +1 -0
- package/dist/naming/types.d.ts +94 -0
- package/dist/naming/types.d.ts.map +1 -0
- package/dist/naming/types.js +2 -0
- package/dist/naming/types.js.map +1 -0
- package/dist/output/import-path.d.ts +24 -0
- package/dist/output/import-path.d.ts.map +1 -0
- package/dist/output/import-path.js +30 -0
- package/dist/output/import-path.js.map +1 -0
- package/dist/output/index.d.ts +40 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +138 -0
- package/dist/output/index.js.map +1 -0
- package/dist/output/manifest.d.ts +17 -0
- package/dist/output/manifest.d.ts.map +1 -0
- package/dist/output/manifest.js +22 -0
- package/dist/output/manifest.js.map +1 -0
- package/dist/output/paths.d.ts +54 -0
- package/dist/output/paths.d.ts.map +1 -0
- package/dist/output/paths.js +183 -0
- package/dist/output/paths.js.map +1 -0
- package/dist/output/resolve.d.ts +100 -0
- package/dist/output/resolve.d.ts.map +1 -0
- package/dist/output/resolve.js +313 -0
- package/dist/output/resolve.js.map +1 -0
- package/dist/output/validate.d.ts +82 -0
- package/dist/output/validate.d.ts.map +1 -0
- package/dist/output/validate.js +128 -0
- package/dist/output/validate.js.map +1 -0
- package/dist/parser/cursor.d.ts +55 -0
- package/dist/parser/cursor.d.ts.map +1 -0
- package/dist/parser/cursor.js +120 -0
- package/dist/parser/cursor.js.map +1 -0
- package/dist/parser/declaration.d.ts +21 -0
- package/dist/parser/declaration.d.ts.map +1 -0
- package/dist/parser/declaration.js +201 -0
- package/dist/parser/declaration.js.map +1 -0
- package/dist/parser/diagnostics.d.ts +52 -0
- package/dist/parser/diagnostics.d.ts.map +1 -0
- package/dist/parser/diagnostics.js +55 -0
- package/dist/parser/diagnostics.js.map +1 -0
- package/dist/parser/group.d.ts +26 -0
- package/dist/parser/group.d.ts.map +1 -0
- package/dist/parser/group.js +219 -0
- package/dist/parser/group.js.map +1 -0
- package/dist/parser/index.d.ts +30 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +48 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/modifier.d.ts +25 -0
- package/dist/parser/modifier.d.ts.map +1 -0
- package/dist/parser/modifier.js +41 -0
- package/dist/parser/modifier.js.map +1 -0
- package/dist/parser/recovery.d.ts +23 -0
- package/dist/parser/recovery.d.ts.map +1 -0
- package/dist/parser/recovery.js +80 -0
- package/dist/parser/recovery.js.map +1 -0
- package/dist/parser/rule.d.ts +39 -0
- package/dist/parser/rule.d.ts.map +1 -0
- package/dist/parser/rule.js +337 -0
- package/dist/parser/rule.js.map +1 -0
- package/dist/parser/statement.d.ts +21 -0
- package/dist/parser/statement.d.ts.map +1 -0
- package/dist/parser/statement.js +48 -0
- package/dist/parser/statement.js.map +1 -0
- package/dist/parser/statements.d.ts +33 -0
- package/dist/parser/statements.d.ts.map +1 -0
- package/dist/parser/statements.js +605 -0
- package/dist/parser/statements.js.map +1 -0
- package/dist/parser/value.d.ts +57 -0
- package/dist/parser/value.d.ts.map +1 -0
- package/dist/parser/value.js +226 -0
- package/dist/parser/value.js.map +1 -0
- package/dist/resolver/graph.d.ts +20 -0
- package/dist/resolver/graph.d.ts.map +1 -0
- package/dist/resolver/graph.js +382 -0
- package/dist/resolver/graph.js.map +1 -0
- package/dist/resolver/groups.d.ts +70 -0
- package/dist/resolver/groups.d.ts.map +1 -0
- package/dist/resolver/groups.js +143 -0
- package/dist/resolver/groups.js.map +1 -0
- package/dist/resolver/index.d.ts +46 -0
- package/dist/resolver/index.d.ts.map +1 -0
- package/dist/resolver/index.js +46 -0
- package/dist/resolver/index.js.map +1 -0
- package/dist/resolver/keyframes.d.ts +56 -0
- package/dist/resolver/keyframes.d.ts.map +1 -0
- package/dist/resolver/keyframes.js +102 -0
- package/dist/resolver/keyframes.js.map +1 -0
- package/dist/resolver/paths.d.ts +37 -0
- package/dist/resolver/paths.d.ts.map +1 -0
- package/dist/resolver/paths.js +135 -0
- package/dist/resolver/paths.js.map +1 -0
- package/dist/resolver/rules.d.ts +34 -0
- package/dist/resolver/rules.d.ts.map +1 -0
- package/dist/resolver/rules.js +52 -0
- package/dist/resolver/rules.js.map +1 -0
- package/dist/resolver/scopes.d.ts +44 -0
- package/dist/resolver/scopes.d.ts.map +1 -0
- package/dist/resolver/scopes.js +213 -0
- package/dist/resolver/scopes.js.map +1 -0
- package/dist/resolver/types.d.ts +238 -0
- package/dist/resolver/types.d.ts.map +1 -0
- package/dist/resolver/types.js +11 -0
- package/dist/resolver/types.js.map +1 -0
- package/dist/selectors/flatten.d.ts +95 -0
- package/dist/selectors/flatten.d.ts.map +1 -0
- package/dist/selectors/flatten.js +384 -0
- package/dist/selectors/flatten.js.map +1 -0
- package/dist/selectors/index.d.ts +15 -0
- package/dist/selectors/index.d.ts.map +1 -0
- package/dist/selectors/index.js +14 -0
- package/dist/selectors/index.js.map +1 -0
- package/dist/selectors/scan.d.ts +54 -0
- package/dist/selectors/scan.d.ts.map +1 -0
- package/dist/selectors/scan.js +191 -0
- package/dist/selectors/scan.js.map +1 -0
- package/dist/selectors/specificity.d.ts +28 -0
- package/dist/selectors/specificity.d.ts.map +1 -0
- package/dist/selectors/specificity.js +297 -0
- package/dist/selectors/specificity.js.map +1 -0
- package/dist/setup-list.d.ts +41 -0
- package/dist/setup-list.d.ts.map +1 -0
- package/dist/setup-list.js +122 -0
- package/dist/setup-list.js.map +1 -0
- package/dist/sourcemaps/index.d.ts +14 -0
- package/dist/sourcemaps/index.d.ts.map +1 -0
- package/dist/sourcemaps/index.js +13 -0
- package/dist/sourcemaps/index.js.map +1 -0
- package/dist/sourcemaps/mappings.d.ts +77 -0
- package/dist/sourcemaps/mappings.d.ts.map +1 -0
- package/dist/sourcemaps/mappings.js +124 -0
- package/dist/sourcemaps/mappings.js.map +1 -0
- package/dist/sourcemaps/vlq.d.ts +12 -0
- package/dist/sourcemaps/vlq.d.ts.map +1 -0
- package/dist/sourcemaps/vlq.js +29 -0
- package/dist/sourcemaps/vlq.js.map +1 -0
- package/dist/types/ast.d.ts +291 -0
- package/dist/types/ast.d.ts.map +1 -0
- package/dist/types/ast.js +2 -0
- package/dist/types/ast.js.map +1 -0
- package/dist/types/diagnostics.d.ts +55 -0
- package/dist/types/diagnostics.d.ts.map +1 -0
- package/dist/types/diagnostics.js +61 -0
- package/dist/types/diagnostics.js.map +1 -0
- package/dist/types/options.d.ts +274 -0
- package/dist/types/options.d.ts.map +1 -0
- package/dist/types/options.js +11 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/result.d.ts +112 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +2 -0
- package/dist/types/result.js.map +1 -0
- package/dist/types/span.d.ts +19 -0
- package/dist/types/span.d.ts.map +1 -0
- package/dist/types/span.js +2 -0
- package/dist/types/span.js.map +1 -0
- package/dist/types/token.d.ts +68 -0
- package/dist/types/token.d.ts.map +1 -0
- package/dist/types/token.js +2 -0
- package/dist/types/token.js.map +1 -0
- package/dist/variables/ast.d.ts +56 -0
- package/dist/variables/ast.d.ts.map +1 -0
- package/dist/variables/ast.js +167 -0
- package/dist/variables/ast.js.map +1 -0
- package/dist/variables/expand.d.ts +109 -0
- package/dist/variables/expand.d.ts.map +1 -0
- package/dist/variables/expand.js +213 -0
- package/dist/variables/expand.js.map +1 -0
- package/dist/variables/index.d.ts +36 -0
- package/dist/variables/index.d.ts.map +1 -0
- package/dist/variables/index.js +33 -0
- package/dist/variables/index.js.map +1 -0
- package/dist/variables/naming.d.ts +39 -0
- package/dist/variables/naming.d.ts.map +1 -0
- package/dist/variables/naming.js +14 -0
- package/dist/variables/naming.js.map +1 -0
- package/dist/variables/runtime.d.ts +81 -0
- package/dist/variables/runtime.d.ts.map +1 -0
- package/dist/variables/runtime.js +228 -0
- package/dist/variables/runtime.js.map +1 -0
- package/dist/variables/substitute.d.ts +65 -0
- package/dist/variables/substitute.d.ts.map +1 -0
- package/dist/variables/substitute.js +73 -0
- package/dist/variables/substitute.js.map +1 -0
- package/dist/variables/walk.d.ts +37 -0
- package/dist/variables/walk.d.ts.map +1 -0
- package/dist/variables/walk.js +113 -0
- package/dist/variables/walk.js.map +1 -0
- package/package.json +35 -4
- package/src/emitter/index.ts +658 -0
- package/src/formatter/index.ts +544 -0
- package/src/host/node.ts +85 -0
- package/src/index.ts +1021 -0
- package/src/ir/factories.ts +85 -0
- package/src/ir/index.ts +28 -0
- package/src/ir/types.ts +145 -0
- package/src/lexer/at-keywords.ts +35 -0
- package/src/lexer/characters.ts +82 -0
- package/src/lexer/comments.ts +27 -0
- package/src/lexer/diagnostics.ts +42 -0
- package/src/lexer/dollar-refs.ts +23 -0
- package/src/lexer/index.ts +37 -0
- package/src/lexer/names.ts +49 -0
- package/src/lexer/numbers.ts +59 -0
- package/src/lexer/scanner.ts +199 -0
- package/src/lexer/strings.ts +52 -0
- package/src/lexer/urls.ts +63 -0
- package/src/lowering/expand-groups.ts +206 -0
- package/src/lowering/group.ts +119 -0
- package/src/lowering/index.ts +43 -0
- package/src/lowering/lower.ts +441 -0
- package/src/lowering/media.ts +314 -0
- package/src/lowering/merge.ts +163 -0
- package/src/lowering/property-families.ts +194 -0
- package/src/lowering/spans.ts +118 -0
- package/src/naming/index.ts +44 -0
- package/src/naming/mapgen.ts +252 -0
- package/src/naming/merge.ts +114 -0
- package/src/naming/rewrite.ts +333 -0
- package/src/naming/scan.ts +267 -0
- package/src/naming/table.ts +153 -0
- package/src/naming/types.ts +100 -0
- package/src/output/import-path.ts +30 -0
- package/src/output/index.ts +213 -0
- package/src/output/manifest.ts +28 -0
- package/src/output/paths.ts +200 -0
- package/src/output/resolve.ts +401 -0
- package/src/output/validate.ts +251 -0
- package/src/parser/cursor.ts +138 -0
- package/src/parser/declaration.ts +247 -0
- package/src/parser/diagnostics.ts +75 -0
- package/src/parser/group.ts +303 -0
- package/src/parser/index.ts +50 -0
- package/src/parser/modifier.ts +60 -0
- package/src/parser/recovery.ts +88 -0
- package/src/parser/rule.ts +370 -0
- package/src/parser/statement.ts +47 -0
- package/src/parser/statements.ts +667 -0
- package/src/parser/value.ts +265 -0
- package/src/resolver/graph.ts +467 -0
- package/src/resolver/groups.ts +177 -0
- package/src/resolver/index.ts +68 -0
- package/src/resolver/keyframes.ts +131 -0
- package/src/resolver/paths.ts +142 -0
- package/src/resolver/rules.ts +54 -0
- package/src/resolver/scopes.ts +342 -0
- package/src/resolver/types.ts +259 -0
- package/src/selectors/flatten.ts +448 -0
- package/src/selectors/index.ts +14 -0
- package/src/selectors/scan.ts +227 -0
- package/src/selectors/specificity.ts +319 -0
- package/src/setup-list.ts +172 -0
- package/src/sourcemaps/index.ts +25 -0
- package/src/sourcemaps/mappings.ts +190 -0
- package/src/sourcemaps/vlq.ts +29 -0
- package/src/types/ast.ts +318 -0
- package/src/types/diagnostics.ts +124 -0
- package/src/types/options.ts +286 -0
- package/src/types/result.ts +121 -0
- package/src/types/span.ts +18 -0
- package/src/types/token.ts +77 -0
- package/src/variables/ast.ts +182 -0
- package/src/variables/expand.ts +319 -0
- package/src/variables/index.ts +38 -0
- package/src/variables/naming.ts +46 -0
- package/src/variables/runtime.ts +336 -0
- package/src/variables/substitute.ts +148 -0
- package/src/variables/walk.ts +147 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lexical diagnostics.
|
|
3
|
+
*
|
|
4
|
+
* Every lexical failure uses the `CHIKX1001` syntax anchor with `error`
|
|
5
|
+
* severity, which the frozen registry defines as covering "a lexer-level
|
|
6
|
+
* recovery". Spans cover the offending construct itself (the unterminated
|
|
7
|
+
* string, comment or URL, or the single illegal character) so an editor can
|
|
8
|
+
* point at its start and end. The tokenizer never throws: callers always
|
|
9
|
+
* receive tokens plus these diagnostics.
|
|
10
|
+
*/
|
|
11
|
+
import { error } from "../types/diagnostics.js";
|
|
12
|
+
const LEXICAL_CODE = "CHIKX1001";
|
|
13
|
+
/** User-facing wording for each lexical failure the tokenizer can report. */
|
|
14
|
+
export const LEXICAL_MESSAGES = {
|
|
15
|
+
unterminatedString: "Unterminated string literal; the closing quote is missing before the end of the line.",
|
|
16
|
+
unterminatedComment: "Unterminated comment; the closing star-slash sequence is missing.",
|
|
17
|
+
unterminatedUrl: "Unterminated url() construct; the closing parenthesis is missing.",
|
|
18
|
+
malformedUrl: "Malformed url() construct; only whitespace and a closing parenthesis may follow a quoted path.",
|
|
19
|
+
invalidEscape: "Invalid escape sequence; a backslash must be followed by a character other than a line break.",
|
|
20
|
+
};
|
|
21
|
+
/** Build one error diagnostic with a span in `file`. */
|
|
22
|
+
export function lexicalError(message, start, end, file) {
|
|
23
|
+
return error(LEXICAL_CODE, message, { start, end, file });
|
|
24
|
+
}
|
|
25
|
+
/** Message for an illegal control character, naming its code point. */
|
|
26
|
+
export function illegalCharacterMessage(code) {
|
|
27
|
+
return `Illegal control character U+${code.toString(16).toUpperCase().padStart(4, "0")} in source.`;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/lexer/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,MAAM,YAAY,GAAG,WAAoB,CAAC;AAE1C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,kBAAkB,EAChB,uFAAuF;IACzF,mBAAmB,EAAE,mEAAmE;IACxF,eAAe,EAAE,mEAAmE;IACpF,YAAY,EACV,gGAAgG;IAClG,aAAa,EACX,+FAA+F;CACzF,CAAC;AAEX,wDAAwD;AACxD,MAAM,UAAU,YAAY,CAC1B,OAAe,EACf,KAAa,EACb,GAAW,EACX,IAAY;IAEZ,OAAO,KAAK,CAAC,YAAY,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,OAAO,+BAA+B,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,aAAa,CAAC;AACtG,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `$` reference scanning.
|
|
3
|
+
*
|
|
4
|
+
* The frozen `dollar-ref` JSDoc lists exactly two forms, `$name` and
|
|
5
|
+
* `$name.member`, so at most one `.` member joins a reference. A malformed or
|
|
6
|
+
* bare `$` stays a `delim` and the parser reports it; the lexer never guesses.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* End offset of the `dollar-ref` starting at `start`, or `null` when `$` is not
|
|
10
|
+
* followed by a name.
|
|
11
|
+
*/
|
|
12
|
+
export declare function scanDollarRef(source: string, start: number): number | null;
|
|
13
|
+
//# sourceMappingURL=dollar-refs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dollar-refs.d.ts","sourceRoot":"","sources":["../../src/lexer/dollar-refs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQ1E"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `$` reference scanning.
|
|
3
|
+
*
|
|
4
|
+
* The frozen `dollar-ref` JSDoc lists exactly two forms, `$name` and
|
|
5
|
+
* `$name.member`, so at most one `.` member joins a reference. A malformed or
|
|
6
|
+
* bare `$` stays a `delim` and the parser reports it; the lexer never guesses.
|
|
7
|
+
*/
|
|
8
|
+
import { isIdentStartAt, nameEnd } from "./names.js";
|
|
9
|
+
/**
|
|
10
|
+
* End offset of the `dollar-ref` starting at `start`, or `null` when `$` is not
|
|
11
|
+
* followed by a name.
|
|
12
|
+
*/
|
|
13
|
+
export function scanDollarRef(source, start) {
|
|
14
|
+
if (!isIdentStartAt(source, start + 1))
|
|
15
|
+
return null;
|
|
16
|
+
let index = nameEnd(source, start + 1);
|
|
17
|
+
if (source.charCodeAt(index) === 0x2e && isIdentStartAt(source, index + 1)) {
|
|
18
|
+
index = nameEnd(source, index + 1);
|
|
19
|
+
}
|
|
20
|
+
return index;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=dollar-refs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dollar-refs.js","sourceRoot":"","sources":["../../src/lexer/dollar-refs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,KAAa;IACzD,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAEpD,IAAI,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IACvC,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI,cAAc,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;QAC3E,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lexer facade for `@chikx/compiler`.
|
|
3
|
+
*
|
|
4
|
+
* `tokenize` is the only entry point the parser needs: it turns source text into
|
|
5
|
+
* a lossless token stream that always ends with exactly one `eof` token, plus
|
|
6
|
+
* the lexical diagnostics collected on the way. It is a pure function — no
|
|
7
|
+
* filesystem, no ambient state, no dependencies — and it never throws.
|
|
8
|
+
*
|
|
9
|
+
* `modifier` is deliberately absent from the output: the frozen `Token` JSDoc
|
|
10
|
+
* makes the parser promote a recognised `at-keyword` to `modifier` only at
|
|
11
|
+
* top-level value depth or in block-condition position, so alias tables stay in
|
|
12
|
+
* configuration where they belong.
|
|
13
|
+
*/
|
|
14
|
+
import type { Diagnostic } from "../types/diagnostics.js";
|
|
15
|
+
import type { Token } from "../types/token.js";
|
|
16
|
+
/** Result of tokenizing one source string. */
|
|
17
|
+
export interface TokenizeResult {
|
|
18
|
+
/** Tokens in source order, always ending with exactly one zero-width `eof`. */
|
|
19
|
+
readonly tokens: readonly Token[];
|
|
20
|
+
/** Lexical errors in source order; empty when the source tokenizes cleanly. */
|
|
21
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Tokenize Chikx source.
|
|
25
|
+
*
|
|
26
|
+
* `file` is copied into every diagnostic {@link Span}; token spans are half-open
|
|
27
|
+
* UTF-16 offsets into `source`, and concatenating `source.slice(start, end)` for
|
|
28
|
+
* every token reproduces `source` exactly (the single `function` token's `value`
|
|
29
|
+
* omits its `(`, but its span still covers only the name).
|
|
30
|
+
*/
|
|
31
|
+
export declare function tokenize(source: string, file: string): TokenizeResult;
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lexer/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,8CAA8C;AAC9C,MAAM,WAAW,cAAc;IAC7B,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,+EAA+E;IAC/E,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,CAErE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lexer facade for `@chikx/compiler`.
|
|
3
|
+
*
|
|
4
|
+
* `tokenize` is the only entry point the parser needs: it turns source text into
|
|
5
|
+
* a lossless token stream that always ends with exactly one `eof` token, plus
|
|
6
|
+
* the lexical diagnostics collected on the way. It is a pure function — no
|
|
7
|
+
* filesystem, no ambient state, no dependencies — and it never throws.
|
|
8
|
+
*
|
|
9
|
+
* `modifier` is deliberately absent from the output: the frozen `Token` JSDoc
|
|
10
|
+
* makes the parser promote a recognised `at-keyword` to `modifier` only at
|
|
11
|
+
* top-level value depth or in block-condition position, so alias tables stay in
|
|
12
|
+
* configuration where they belong.
|
|
13
|
+
*/
|
|
14
|
+
import { scan } from "./scanner.js";
|
|
15
|
+
/**
|
|
16
|
+
* Tokenize Chikx source.
|
|
17
|
+
*
|
|
18
|
+
* `file` is copied into every diagnostic {@link Span}; token spans are half-open
|
|
19
|
+
* UTF-16 offsets into `source`, and concatenating `source.slice(start, end)` for
|
|
20
|
+
* every token reproduces `source` exactly (the single `function` token's `value`
|
|
21
|
+
* omits its `(`, but its span still covers only the name).
|
|
22
|
+
*/
|
|
23
|
+
export function tokenize(source, file) {
|
|
24
|
+
return scan(source, file);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lexer/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAUpC;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAc,EAAE,IAAY;IACnD,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifier and name scanning shared by idents, function names, dimension
|
|
3
|
+
* units, hashes and `@`/`$` references.
|
|
4
|
+
*
|
|
5
|
+
* `nameEnd` consumes CSS name characters and valid escapes; `identEnd` only
|
|
6
|
+
* starts a name where the identifier grammar allows one. Escapes stay exactly
|
|
7
|
+
* as authored, matching the frozen `ident` JSDoc examples (`\31 23`,
|
|
8
|
+
* `status\:active`).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Offset just past the run of name characters and valid escapes starting at
|
|
12
|
+
* `from`, or `from` itself when nothing name-like starts there.
|
|
13
|
+
*/
|
|
14
|
+
export declare function nameEnd(source: string, from: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* Whether a CSS identifier can start at `index`: a name-start character, a
|
|
17
|
+
* hyphen followed by a name-start/hyphen/escape (`--label`, `-webkit-calc`), or
|
|
18
|
+
* a valid escape.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isIdentStartAt(source: string, index: number): boolean;
|
|
21
|
+
/** End offset of the identifier starting at `from`, or `from` when none starts. */
|
|
22
|
+
export declare function identEnd(source: string, from: number): number;
|
|
23
|
+
//# sourceMappingURL=names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../../src/lexer/names.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;;GAGG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAY5D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAQrE;AAED,mFAAmF;AACnF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7D"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifier and name scanning shared by idents, function names, dimension
|
|
3
|
+
* units, hashes and `@`/`$` references.
|
|
4
|
+
*
|
|
5
|
+
* `nameEnd` consumes CSS name characters and valid escapes; `identEnd` only
|
|
6
|
+
* starts a name where the identifier grammar allows one. Escapes stay exactly
|
|
7
|
+
* as authored, matching the frozen `ident` JSDoc examples (`\31 23`,
|
|
8
|
+
* `status\:active`).
|
|
9
|
+
*/
|
|
10
|
+
import { escapeEnd, isNameCode, isNameStartCode } from "./characters.js";
|
|
11
|
+
/**
|
|
12
|
+
* Offset just past the run of name characters and valid escapes starting at
|
|
13
|
+
* `from`, or `from` itself when nothing name-like starts there.
|
|
14
|
+
*/
|
|
15
|
+
export function nameEnd(source, from) {
|
|
16
|
+
let index = from;
|
|
17
|
+
while (index < source.length) {
|
|
18
|
+
if (isNameCode(source.charCodeAt(index))) {
|
|
19
|
+
index += 1;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const escaped = escapeEnd(source, index);
|
|
23
|
+
if (escaped <= index)
|
|
24
|
+
break;
|
|
25
|
+
index = escaped;
|
|
26
|
+
}
|
|
27
|
+
return index;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether a CSS identifier can start at `index`: a name-start character, a
|
|
31
|
+
* hyphen followed by a name-start/hyphen/escape (`--label`, `-webkit-calc`), or
|
|
32
|
+
* a valid escape.
|
|
33
|
+
*/
|
|
34
|
+
export function isIdentStartAt(source, index) {
|
|
35
|
+
const code = source.charCodeAt(index);
|
|
36
|
+
if (isNameStartCode(code))
|
|
37
|
+
return true;
|
|
38
|
+
if (code === 0x2d) {
|
|
39
|
+
const next = source.charCodeAt(index + 1);
|
|
40
|
+
return isNameStartCode(next) || next === 0x2d || escapeEnd(source, index + 1) > index + 1;
|
|
41
|
+
}
|
|
42
|
+
return escapeEnd(source, index) > index;
|
|
43
|
+
}
|
|
44
|
+
/** End offset of the identifier starting at `from`, or `from` when none starts. */
|
|
45
|
+
export function identEnd(source, from) {
|
|
46
|
+
return isIdentStartAt(source, from) ? nameEnd(source, from) : from;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=names.js.map
|
|
@@ -0,0 +1 @@
|
|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,EAAE,IAAY;IACnD,OAAO,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Numeric token scanning.
|
|
3
|
+
*
|
|
4
|
+
* The frozen `number` JSDoc keeps a numeric token "as authored" (`12`, `0.5`,
|
|
5
|
+
* `10px`), so a number, its dimension unit and a trailing `%` all stay in one
|
|
6
|
+
* token with the unit text preserved. There is no separate percentage or
|
|
7
|
+
* dimension kind.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Whether a numeric token can start at `index`: a digit, `.` followed by a
|
|
11
|
+
* digit, or a sign followed by either.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isNumberStartAt(source: string, index: number): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* End offset of the numeric token starting at `from`.
|
|
16
|
+
*
|
|
17
|
+
* Grammar: optional sign, integer and/or fraction, optional exponent, then a
|
|
18
|
+
* `%` suffix or an identifier unit. A `%` wins over a unit, matching CSS
|
|
19
|
+
* tokenization; anything that is not a name character ends the token.
|
|
20
|
+
*/
|
|
21
|
+
export declare function numberEnd(source: string, from: number): number;
|
|
22
|
+
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../src/lexer/numbers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAQtE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAyB9D"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Numeric token scanning.
|
|
3
|
+
*
|
|
4
|
+
* The frozen `number` JSDoc keeps a numeric token "as authored" (`12`, `0.5`,
|
|
5
|
+
* `10px`), so a number, its dimension unit and a trailing `%` all stay in one
|
|
6
|
+
* token with the unit text preserved. There is no separate percentage or
|
|
7
|
+
* dimension kind.
|
|
8
|
+
*/
|
|
9
|
+
import { isDigitCode } from "./characters.js";
|
|
10
|
+
import { nameEnd } from "./names.js";
|
|
11
|
+
/**
|
|
12
|
+
* Whether a numeric token can start at `index`: a digit, `.` followed by a
|
|
13
|
+
* digit, or a sign followed by either.
|
|
14
|
+
*/
|
|
15
|
+
export function isNumberStartAt(source, index) {
|
|
16
|
+
const code = source.charCodeAt(index);
|
|
17
|
+
if (isDigitCode(code))
|
|
18
|
+
return true;
|
|
19
|
+
if (code === 0x2d || code === 0x2b) {
|
|
20
|
+
const next = source.charCodeAt(index + 1);
|
|
21
|
+
return isDigitCode(next) || (next === 0x2e && isDigitCode(source.charCodeAt(index + 2)));
|
|
22
|
+
}
|
|
23
|
+
return code === 0x2e && isDigitCode(source.charCodeAt(index + 1));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* End offset of the numeric token starting at `from`.
|
|
27
|
+
*
|
|
28
|
+
* Grammar: optional sign, integer and/or fraction, optional exponent, then a
|
|
29
|
+
* `%` suffix or an identifier unit. A `%` wins over a unit, matching CSS
|
|
30
|
+
* tokenization; anything that is not a name character ends the token.
|
|
31
|
+
*/
|
|
32
|
+
export function numberEnd(source, from) {
|
|
33
|
+
let index = from;
|
|
34
|
+
const first = source.charCodeAt(index);
|
|
35
|
+
if (first === 0x2d || first === 0x2b)
|
|
36
|
+
index += 1;
|
|
37
|
+
while (isDigitCode(source.charCodeAt(index)))
|
|
38
|
+
index += 1;
|
|
39
|
+
if (source.charCodeAt(index) === 0x2e && isDigitCode(source.charCodeAt(index + 1))) {
|
|
40
|
+
index += 1;
|
|
41
|
+
while (isDigitCode(source.charCodeAt(index)))
|
|
42
|
+
index += 1;
|
|
43
|
+
}
|
|
44
|
+
const exponent = source.charCodeAt(index);
|
|
45
|
+
if (exponent === 0x65 || exponent === 0x45) {
|
|
46
|
+
let probe = index + 1;
|
|
47
|
+
const sign = source.charCodeAt(probe);
|
|
48
|
+
if (sign === 0x2d || sign === 0x2b)
|
|
49
|
+
probe += 1;
|
|
50
|
+
if (isDigitCode(source.charCodeAt(probe))) {
|
|
51
|
+
index = probe;
|
|
52
|
+
while (isDigitCode(source.charCodeAt(index)))
|
|
53
|
+
index += 1;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (source.charCodeAt(index) === 0x25)
|
|
57
|
+
return index + 1;
|
|
58
|
+
return nameEnd(source, index);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=numbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../src/lexer/numbers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,KAAa;IAC3D,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,WAAW,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACnC,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAC1C,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3F,CAAC;IACD,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,CAAC,KAAK,CAAC,CAAC;gBAAE,KAAK,IAAI,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,IAAI;QAAE,OAAO,KAAK,GAAG,CAAC,CAAC;IACxD,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateful single-pass scanner: source text to tokens plus lexical diagnostics.
|
|
3
|
+
*
|
|
4
|
+
* The loop advances by whole tokens, and every token covers at least one source
|
|
5
|
+
* code unit, so the scan terminates in at most `source.length + 1` iterations
|
|
6
|
+
* for any input. There is no backtracking and no regular expression, and the
|
|
7
|
+
* tokenizer never throws: malformed input produces recovered tokens plus
|
|
8
|
+
* `CHIKX1001` diagnostics and always ends with a single `eof` token.
|
|
9
|
+
*
|
|
10
|
+
* Whitespace runs and block comments become their own tokens so the stream
|
|
11
|
+
* reproduces the source exactly. `@` classification is intentionally absent —
|
|
12
|
+
* see `at-keywords.ts` and the frozen `modifier` JSDoc.
|
|
13
|
+
*/
|
|
14
|
+
import type { Diagnostic } from "../types/diagnostics.js";
|
|
15
|
+
import type { Token } from "../types/token.js";
|
|
16
|
+
/** Tokens and diagnostics produced by one scan. */
|
|
17
|
+
export interface ScanResult {
|
|
18
|
+
/** Tokens in source order, always ending with exactly one zero-width `eof`. */
|
|
19
|
+
readonly tokens: readonly Token[];
|
|
20
|
+
/** Lexical errors in source order; empty for valid source. */
|
|
21
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Scan `source` in one pass.
|
|
25
|
+
*
|
|
26
|
+
* `file` is copied into every diagnostic span; token spans stay plain offsets,
|
|
27
|
+
* as the frozen `Span` contract requires.
|
|
28
|
+
*/
|
|
29
|
+
export declare function scan(source: string, file: string): ScanResult;
|
|
30
|
+
//# sourceMappingURL=scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../../src/lexer/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAa,MAAM,mBAAmB,CAAC;AAW1D,mDAAmD;AACnD,MAAM,WAAW,UAAU;IACzB,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,8DAA8D;IAC9D,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAkCD;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CA8H7D"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateful single-pass scanner: source text to tokens plus lexical diagnostics.
|
|
3
|
+
*
|
|
4
|
+
* The loop advances by whole tokens, and every token covers at least one source
|
|
5
|
+
* code unit, so the scan terminates in at most `source.length + 1` iterations
|
|
6
|
+
* for any input. There is no backtracking and no regular expression, and the
|
|
7
|
+
* tokenizer never throws: malformed input produces recovered tokens plus
|
|
8
|
+
* `CHIKX1001` diagnostics and always ends with a single `eof` token.
|
|
9
|
+
*
|
|
10
|
+
* Whitespace runs and block comments become their own tokens so the stream
|
|
11
|
+
* reproduces the source exactly. `@` classification is intentionally absent —
|
|
12
|
+
* see `at-keywords.ts` and the frozen `modifier` JSDoc.
|
|
13
|
+
*/
|
|
14
|
+
import { scanAtKeyword } from "./at-keywords.js";
|
|
15
|
+
import { escapeEnd, isIllegalCode, isNameCode, isWhitespaceCode } from "./characters.js";
|
|
16
|
+
import { scanComment } from "./comments.js";
|
|
17
|
+
import { LEXICAL_MESSAGES, illegalCharacterMessage, lexicalError } from "./diagnostics.js";
|
|
18
|
+
import { scanDollarRef } from "./dollar-refs.js";
|
|
19
|
+
import { identEnd, isIdentStartAt, nameEnd } from "./names.js";
|
|
20
|
+
import { isNumberStartAt, numberEnd } from "./numbers.js";
|
|
21
|
+
import { scanString } from "./strings.js";
|
|
22
|
+
import { isUrlName, scanUrl } from "./urls.js";
|
|
23
|
+
const PUNCTUATION = {
|
|
24
|
+
":": "colon",
|
|
25
|
+
";": "semicolon",
|
|
26
|
+
",": "comma",
|
|
27
|
+
"{": "lbrace",
|
|
28
|
+
"}": "rbrace",
|
|
29
|
+
"(": "lparen",
|
|
30
|
+
")": "rparen",
|
|
31
|
+
"[": "lbracket",
|
|
32
|
+
"]": "rbracket",
|
|
33
|
+
};
|
|
34
|
+
const QUOTE_DOUBLE = 0x22;
|
|
35
|
+
const QUOTE_SINGLE = 0x27;
|
|
36
|
+
const BACKSLASH = 0x5c;
|
|
37
|
+
const SLASH = 0x2f;
|
|
38
|
+
const STAR = 0x2a;
|
|
39
|
+
const AT = 0x40;
|
|
40
|
+
const DOLLAR = 0x24;
|
|
41
|
+
const HASH = 0x23;
|
|
42
|
+
const OPEN_PAREN = 0x28;
|
|
43
|
+
function makeToken(kind, source, start, end, value) {
|
|
44
|
+
return { kind, value: value ?? source.slice(start, end), start, end };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Scan `source` in one pass.
|
|
48
|
+
*
|
|
49
|
+
* `file` is copied into every diagnostic span; token spans stay plain offsets,
|
|
50
|
+
* as the frozen `Span` contract requires.
|
|
51
|
+
*/
|
|
52
|
+
export function scan(source, file) {
|
|
53
|
+
const tokens = [];
|
|
54
|
+
const diagnostics = [];
|
|
55
|
+
const length = source.length;
|
|
56
|
+
let index = 0;
|
|
57
|
+
while (index < length) {
|
|
58
|
+
const code = source.charCodeAt(index);
|
|
59
|
+
if (isWhitespaceCode(code)) {
|
|
60
|
+
let end = index + 1;
|
|
61
|
+
while (end < length && isWhitespaceCode(source.charCodeAt(end)))
|
|
62
|
+
end += 1;
|
|
63
|
+
tokens.push(makeToken("whitespace", source, index, end));
|
|
64
|
+
index = end;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (code === SLASH && source.charCodeAt(index + 1) === STAR) {
|
|
68
|
+
const comment = scanComment(source, index);
|
|
69
|
+
tokens.push(makeToken("comment", source, index, comment.end));
|
|
70
|
+
if (!comment.closed) {
|
|
71
|
+
diagnostics.push(lexicalError(LEXICAL_MESSAGES.unterminatedComment, index, comment.end, file));
|
|
72
|
+
}
|
|
73
|
+
index = comment.end;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (code === QUOTE_DOUBLE || code === QUOTE_SINGLE) {
|
|
77
|
+
const literal = scanString(source, index);
|
|
78
|
+
tokens.push(makeToken("string", source, index, literal.end));
|
|
79
|
+
if (!literal.closed) {
|
|
80
|
+
diagnostics.push(lexicalError(LEXICAL_MESSAGES.unterminatedString, index, literal.end, file));
|
|
81
|
+
}
|
|
82
|
+
index = literal.end;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (code === AT) {
|
|
86
|
+
const end = scanAtKeyword(source, index);
|
|
87
|
+
tokens.push(makeToken(end > index + 1 ? "at-keyword" : "delim", source, index, end));
|
|
88
|
+
index = end;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (code === DOLLAR) {
|
|
92
|
+
const end = scanDollarRef(source, index);
|
|
93
|
+
if (end === null) {
|
|
94
|
+
tokens.push(makeToken("delim", source, index, index + 1));
|
|
95
|
+
index += 1;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
tokens.push(makeToken("dollar-ref", source, index, end));
|
|
99
|
+
index = end;
|
|
100
|
+
}
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (code === HASH) {
|
|
104
|
+
const nameStart = index + 1;
|
|
105
|
+
const named = isNameCode(source.charCodeAt(nameStart)) || escapeEnd(source, nameStart) > nameStart;
|
|
106
|
+
const end = named ? nameEnd(source, nameStart) : index + 1;
|
|
107
|
+
tokens.push(makeToken(named ? "hash" : "delim", source, index, end));
|
|
108
|
+
index = end;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (isNumberStartAt(source, index)) {
|
|
112
|
+
const end = numberEnd(source, index);
|
|
113
|
+
tokens.push(makeToken("number", source, index, end));
|
|
114
|
+
index = end;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (isIdentStartAt(source, index)) {
|
|
118
|
+
const end = identEnd(source, index);
|
|
119
|
+
if (source.charCodeAt(end) === OPEN_PAREN) {
|
|
120
|
+
const name = source.slice(index, end);
|
|
121
|
+
if (isUrlName(source, index, end)) {
|
|
122
|
+
const url = scanUrl(source, end);
|
|
123
|
+
tokens.push(makeToken("url", source, index, url.end));
|
|
124
|
+
if (url.problem !== null) {
|
|
125
|
+
diagnostics.push(lexicalError(url.problem === "malformed"
|
|
126
|
+
? LEXICAL_MESSAGES.malformedUrl
|
|
127
|
+
: LEXICAL_MESSAGES.unterminatedUrl, index, url.end, file));
|
|
128
|
+
}
|
|
129
|
+
index = url.end;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
tokens.push(makeToken("function", source, index, end, name));
|
|
133
|
+
index = end;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
tokens.push(makeToken("ident", source, index, end));
|
|
137
|
+
index = end;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const punctuation = PUNCTUATION[source.charAt(index)];
|
|
141
|
+
if (punctuation !== undefined) {
|
|
142
|
+
tokens.push(makeToken(punctuation, source, index, index + 1));
|
|
143
|
+
index += 1;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (code === BACKSLASH) {
|
|
147
|
+
diagnostics.push(lexicalError(LEXICAL_MESSAGES.invalidEscape, index, index + 1, file));
|
|
148
|
+
}
|
|
149
|
+
else if (isIllegalCode(code)) {
|
|
150
|
+
diagnostics.push(lexicalError(illegalCharacterMessage(code), index, index + 1, file));
|
|
151
|
+
}
|
|
152
|
+
tokens.push(makeToken("delim", source, index, index + 1));
|
|
153
|
+
index += 1;
|
|
154
|
+
}
|
|
155
|
+
tokens.push({ kind: "eof", value: "", start: length, end: length });
|
|
156
|
+
return { tokens, diagnostics };
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../src/lexer/scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAU/C,MAAM,WAAW,GAAwC;IACvD,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,UAAU;CAChB,CAAC;AAEF,MAAM,YAAY,GAAG,IAAI,CAAC;A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E,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quoted string scanning.
|
|
3
|
+
*
|
|
4
|
+
* A string token covers the quote characters and every byte between them,
|
|
5
|
+
* escapes included and never decoded, because `Token.value` is the authored
|
|
6
|
+
* slice. `@`, `$`, `{`, `}` and `;` inside stay inert by construction: the
|
|
7
|
+
* scanner never leaves the string until it closes.
|
|
8
|
+
*/
|
|
9
|
+
/** Result of scanning one quoted string: where it ends and whether it closed. */
|
|
10
|
+
export interface StringScan {
|
|
11
|
+
/** Offset just past the closing quote, or where scanning stopped. */
|
|
12
|
+
readonly end: number;
|
|
13
|
+
/** False for an unterminated string (end of file or an unescaped line break). */
|
|
14
|
+
readonly closed: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Scan the string whose opening quote is at `start`.
|
|
18
|
+
*
|
|
19
|
+
* A backslash escapes the next character and a backslash before a line
|
|
20
|
+
* terminator continues the string, as in CSS. An unescaped line terminator ends
|
|
21
|
+
* the string as unterminated without consuming the break, so the caller can
|
|
22
|
+
* resume at a safe boundary; end of file does the same.
|
|
23
|
+
*/
|
|
24
|
+
export declare function scanString(source: string, start: number): StringScan;
|
|
25
|
+
//# sourceMappingURL=strings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/lexer/strings.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACzB,qEAAqE;IACrE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,iFAAiF;IACjF,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAwBpE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quoted string scanning.
|
|
3
|
+
*
|
|
4
|
+
* A string token covers the quote characters and every byte between them,
|
|
5
|
+
* escapes included and never decoded, because `Token.value` is the authored
|
|
6
|
+
* slice. `@`, `$`, `{`, `}` and `;` inside stay inert by construction: the
|
|
7
|
+
* scanner never leaves the string until it closes.
|
|
8
|
+
*/
|
|
9
|
+
import { escapeEnd, isNewlineCode } from "./characters.js";
|
|
10
|
+
/**
|
|
11
|
+
* Scan the string whose opening quote is at `start`.
|
|
12
|
+
*
|
|
13
|
+
* A backslash escapes the next character and a backslash before a line
|
|
14
|
+
* terminator continues the string, as in CSS. An unescaped line terminator ends
|
|
15
|
+
* the string as unterminated without consuming the break, so the caller can
|
|
16
|
+
* resume at a safe boundary; end of file does the same.
|
|
17
|
+
*/
|
|
18
|
+
export function scanString(source, start) {
|
|
19
|
+
const quote = source.charCodeAt(start);
|
|
20
|
+
let index = start + 1;
|
|
21
|
+
while (index < source.length) {
|
|
22
|
+
const code = source.charCodeAt(index);
|
|
23
|
+
if (code === quote)
|
|
24
|
+
return { end: index + 1, closed: true };
|
|
25
|
+
if (isNewlineCode(code))
|
|
26
|
+
return { end: index, closed: false };
|
|
27
|
+
if (code === 0x5c) {
|
|
28
|
+
const next = source.charCodeAt(index + 1);
|
|
29
|
+
if (isNewlineCode(next)) {
|
|
30
|
+
index += next === 0x0d && source.charCodeAt(index + 2) === 0x0a ? 3 : 2;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const escaped = escapeEnd(source, index);
|
|
34
|
+
index = escaped > index ? escaped : index + 1;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
index += 1;
|
|
38
|
+
}
|
|
39
|
+
return { end: source.length, closed: false };
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=strings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strings.js","sourceRoot":"","sources":["../../src/lexer/strings.ts"],"names":[],"mappings":"AA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MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `url(...)` scanning.
|
|
3
|
+
*
|
|
4
|
+
* The frozen `url` JSDoc makes one token out of the whole construct, including
|
|
5
|
+
* its parentheses, quotes and any `@` or `$` inside. That also means interior
|
|
6
|
+
* brackets never contribute to parser depth: the parser only sees one token.
|
|
7
|
+
* Both authored forms (`url("x@2x.png")` and `url(x@2x.png)`) are supported, as
|
|
8
|
+
* is the empty `url()`.
|
|
9
|
+
*/
|
|
10
|
+
/** Result of scanning one `url(...)` construct. */
|
|
11
|
+
export interface UrlScan {
|
|
12
|
+
/** Offset just past the closing parenthesis, or where scanning stopped. */
|
|
13
|
+
readonly end: number;
|
|
14
|
+
/** `null` when the construct closed properly, else which rule it broke. */
|
|
15
|
+
readonly problem: "unterminated" | "malformed" | null;
|
|
16
|
+
}
|
|
17
|
+
/** Whether the name at `[start, end)` is `url` in any ASCII casing. */
|
|
18
|
+
export declare function isUrlName(source: string, start: number, end: number): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Scan the construct whose opening parenthesis is at `parenIndex`.
|
|
21
|
+
*
|
|
22
|
+
* A quoted path is followed by optional whitespace and a required `)`; an
|
|
23
|
+
* unquoted path ends at the first unescaped `)`, so `url(a\)b.png)` stays one
|
|
24
|
+
* token. On failure the returned `end` is a resumable boundary: the caller
|
|
25
|
+
* reports the diagnostic and continues lexing there.
|
|
26
|
+
*/
|
|
27
|
+
export declare function scanUrl(source: string, parenIndex: number): UrlScan;
|
|
28
|
+
//# sourceMappingURL=urls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urls.d.ts","sourceRoot":"","sources":["../../src/lexer/urls.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,mDAAmD;AACnD,MAAM,WAAW,OAAO;IACtB,2EAA2E;IAC3E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,WAAW,GAAG,IAAI,CAAC;CACvD;AAED,uEAAuE;AACvE,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAE7E;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CA4BnE"}
|