|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import { ValueNode } from "./grammarRuleParser.js"; |
| 5 | + |
| 6 | +/** |
| 7 | + * In memory types |
| 8 | + */ |
| 9 | +export type StringPart = { |
| 10 | + type: "string"; |
| 11 | + |
| 12 | + value: string[]; |
| 13 | + |
| 14 | + /* TODO: cache the regexp? |
| 15 | + regexp?: RegExp; |
| 16 | + regexpWithPendingWildcards?: RegExp; |
| 17 | + */ |
| 18 | +}; |
| 19 | + |
| 20 | +export type VarStringPart = { |
| 21 | + type: "wildcard"; |
| 22 | + variable: string; |
| 23 | + typeName: string; // Not needed at runtime? |
| 24 | +}; |
| 25 | + |
| 26 | +export type VarNumberPart = { |
| 27 | + type: "number"; |
| 28 | + variable: string; |
| 29 | +}; |
| 30 | + |
| 31 | +export type RulesPart = { |
| 32 | + type: "rules"; |
| 33 | + |
| 34 | + rules: GrammarRule[]; |
| 35 | + name?: string | undefined; // For debugging |
| 36 | + |
| 37 | + variable?: string | undefined; |
| 38 | + optional?: boolean | undefined; |
| 39 | +}; |
| 40 | + |
| 41 | +export type GrammarPart = |
| 42 | + | StringPart |
| 43 | + | VarStringPart |
| 44 | + | VarNumberPart |
| 45 | + | RulesPart; |
| 46 | +export type GrammarRule = { |
| 47 | + parts: GrammarPart[]; |
| 48 | + value?: ValueNode | undefined; |
| 49 | +}; |
| 50 | + |
| 51 | +export type Grammar = { |
| 52 | + rules: GrammarRule[]; |
| 53 | +}; |
| 54 | + |
| 55 | +/** |
| 56 | + * Serialized types |
| 57 | + */ |
| 58 | +export type StringPartJson = { |
| 59 | + type: "string"; |
| 60 | + value: string[]; |
| 61 | +}; |
| 62 | + |
| 63 | +export type VarStringPartJson = { |
| 64 | + type: "wildcard"; |
| 65 | + variable: string; |
| 66 | + typeName: string; |
| 67 | +}; |
| 68 | + |
| 69 | +export type VarNumberPartJson = { |
| 70 | + type: "number"; |
| 71 | + variable: string; |
| 72 | +}; |
| 73 | + |
| 74 | +export type RulePartJson = { |
| 75 | + type: "rules"; |
| 76 | + name?: string | undefined; |
| 77 | + index: number; |
| 78 | + variable?: string | undefined; |
| 79 | + optional?: boolean | undefined; |
| 80 | +}; |
| 81 | + |
| 82 | +export type GrammarPartJson = |
| 83 | + | StringPartJson |
| 84 | + | VarStringPartJson |
| 85 | + | VarNumberPartJson |
| 86 | + | RulePartJson; |
| 87 | + |
| 88 | +export type GrammarRuleJson = { |
| 89 | + parts: GrammarPartJson[]; |
| 90 | + value?: ValueNode | undefined; |
| 91 | +}; |
| 92 | +export type GrammarRules = GrammarRuleJson[]; |
| 93 | +export type GrammarJson = GrammarRules[]; |
0 commit comments