@nowline/core 0.8.5 → 0.9.0
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/README.md +9 -0
- package/dist/convert/printer.d.ts.map +1 -1
- package/dist/convert/printer.js +20 -9
- package/dist/convert/printer.js.map +1 -1
- package/dist/convert/schema.d.ts +7 -0
- package/dist/convert/schema.d.ts.map +1 -1
- package/dist/convert/schema.js +1 -1
- package/dist/convert/schema.js.map +1 -1
- package/dist/generated/ast.d.ts +251 -141
- package/dist/generated/ast.d.ts.map +1 -1
- package/dist/generated/ast.js +96 -4
- package/dist/generated/ast.js.map +1 -1
- package/dist/generated/grammar.d.ts +1 -1
- package/dist/generated/grammar.d.ts.map +1 -1
- package/dist/generated/grammar.js +435 -149
- package/dist/generated/grammar.js.map +1 -1
- package/dist/generated/module.d.ts +3 -3
- package/dist/generated/module.d.ts.map +1 -1
- package/dist/generated/module.js +1 -1
- package/dist/i18n/codes.d.ts +1 -1
- package/dist/i18n/codes.d.ts.map +1 -1
- package/dist/i18n/codes.js +44 -1
- package/dist/i18n/codes.js.map +1 -1
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/messages.en.d.ts +107 -0
- package/dist/i18n/messages.en.d.ts.map +1 -1
- package/dist/i18n/messages.en.js +220 -1
- package/dist/i18n/messages.en.js.map +1 -1
- package/dist/i18n/messages.fr.d.ts.map +1 -1
- package/dist/i18n/messages.fr.js +250 -1
- package/dist/i18n/messages.fr.js.map +1 -1
- package/dist/i18n/wave-message-types.d.ts +238 -0
- package/dist/i18n/wave-message-types.d.ts.map +1 -0
- package/dist/i18n/wave-message-types.js +11 -0
- package/dist/i18n/wave-message-types.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +6 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +9 -0
- package/dist/internal.js.map +1 -0
- package/dist/language/ast-walk.d.ts +31 -0
- package/dist/language/ast-walk.d.ts.map +1 -0
- package/dist/language/ast-walk.js +109 -0
- package/dist/language/ast-walk.js.map +1 -0
- package/dist/language/calendar-declarations.d.ts +31 -0
- package/dist/language/calendar-declarations.d.ts.map +1 -0
- package/dist/language/calendar-declarations.js +99 -0
- package/dist/language/calendar-declarations.js.map +1 -0
- package/dist/language/include-references.d.ts +11 -0
- package/dist/language/include-references.d.ts.map +1 -0
- package/dist/language/include-references.js +45 -0
- package/dist/language/include-references.js.map +1 -0
- package/dist/language/include-resolver.d.ts +78 -1
- package/dist/language/include-resolver.d.ts.map +1 -1
- package/dist/language/include-resolver.js +190 -12
- package/dist/language/include-resolver.js.map +1 -1
- package/dist/language/include-waves.d.ts +73 -0
- package/dist/language/include-waves.d.ts.map +1 -0
- package/dist/language/include-waves.js +319 -0
- package/dist/language/include-waves.js.map +1 -0
- package/dist/language/nowline-module.js.map +1 -1
- package/dist/language/nowline-validator.d.ts +6 -1
- package/dist/language/nowline-validator.d.ts.map +1 -1
- package/dist/language/nowline-validator.js +95 -1589
- package/dist/language/nowline-validator.js.map +1 -1
- package/dist/language/references.d.ts +14 -0
- package/dist/language/references.d.ts.map +1 -0
- package/dist/language/references.js +36 -0
- package/dist/language/references.js.map +1 -0
- package/dist/language/style-chain.d.ts +37 -0
- package/dist/language/style-chain.d.ts.map +1 -0
- package/dist/language/style-chain.js +55 -0
- package/dist/language/style-chain.js.map +1 -0
- package/dist/language/validator/calendar.d.ts +9 -0
- package/dist/language/validator/calendar.d.ts.map +1 -0
- package/dist/language/validator/calendar.js +250 -0
- package/dist/language/validator/calendar.js.map +1 -0
- package/dist/language/validator/entities.d.ts +23 -0
- package/dist/language/validator/entities.d.ts.map +1 -0
- package/dist/language/validator/entities.js +261 -0
- package/dist/language/validator/entities.js.map +1 -0
- package/dist/language/validator/properties.d.ts +18 -0
- package/dist/language/validator/properties.d.ts.map +1 -0
- package/dist/language/validator/properties.js +356 -0
- package/dist/language/validator/properties.js.map +1 -0
- package/dist/language/validator/references.d.ts +7 -0
- package/dist/language/validator/references.d.ts.map +1 -0
- package/dist/language/validator/references.js +261 -0
- package/dist/language/validator/references.js.map +1 -0
- package/dist/language/validator/structure.d.ts +16 -0
- package/dist/language/validator/structure.d.ts.map +1 -0
- package/dist/language/validator/structure.js +166 -0
- package/dist/language/validator/structure.js.map +1 -0
- package/dist/language/validator/style.d.ts +5 -0
- package/dist/language/validator/style.d.ts.map +1 -0
- package/dist/language/validator/style.js +126 -0
- package/dist/language/validator/style.js.map +1 -0
- package/dist/language/validator/support.d.ts +35 -0
- package/dist/language/validator/support.d.ts.map +1 -0
- package/dist/language/validator/support.js +49 -0
- package/dist/language/validator/support.js.map +1 -0
- package/dist/language/validator/symbols.d.ts +6 -0
- package/dist/language/validator/symbols.d.ts.map +1 -0
- package/dist/language/validator/symbols.js +131 -0
- package/dist/language/validator/symbols.js.map +1 -0
- package/dist/language/validator/tables.d.ts +34 -0
- package/dist/language/validator/tables.d.ts.map +1 -0
- package/dist/language/validator/tables.js +120 -0
- package/dist/language/validator/tables.js.map +1 -0
- package/dist/language/validator-utils.d.ts +32 -0
- package/dist/language/validator-utils.d.ts.map +1 -0
- package/dist/language/validator-utils.js +118 -0
- package/dist/language/validator-utils.js.map +1 -0
- package/dist/language/value-tables.d.ts +107 -0
- package/dist/language/value-tables.d.ts.map +1 -0
- package/dist/language/value-tables.js +240 -0
- package/dist/language/value-tables.js.map +1 -0
- package/dist/language/waves-order.d.ts +51 -0
- package/dist/language/waves-order.d.ts.map +1 -0
- package/dist/language/waves-order.js +787 -0
- package/dist/language/waves-order.js.map +1 -0
- package/dist/language/waves-plan.d.ts +45 -0
- package/dist/language/waves-plan.d.ts.map +1 -0
- package/dist/language/waves-plan.js +64 -0
- package/dist/language/waves-plan.js.map +1 -0
- package/dist/language/waves.d.ts +96 -0
- package/dist/language/waves.d.ts.map +1 -0
- package/dist/language/waves.js +575 -0
- package/dist/language/waves.js.map +1 -0
- package/dist/util/props.d.ts +27 -0
- package/dist/util/props.d.ts.map +1 -0
- package/dist/util/props.js +49 -0
- package/dist/util/props.js.map +1 -0
- package/dist/util/single-line.d.ts +14 -0
- package/dist/util/single-line.d.ts.map +1 -0
- package/dist/util/single-line.js +16 -0
- package/dist/util/single-line.js.map +1 -0
- package/package.json +10 -6
- package/src/convert/printer.ts +20 -10
- package/src/convert/schema.ts +8 -1
- package/src/generated/ast.ts +160 -28
- package/src/generated/grammar.ts +435 -149
- package/src/generated/module.ts +1 -1
- package/src/i18n/codes.ts +95 -2
- package/src/i18n/index.ts +1 -0
- package/src/i18n/messages.en.ts +300 -1
- package/src/i18n/messages.fr.ts +335 -1
- package/src/i18n/wave-message-types.ts +206 -0
- package/src/index.ts +33 -0
- package/src/internal.ts +9 -0
- package/src/language/ast-walk.ts +158 -0
- package/src/language/calendar-declarations.ts +141 -0
- package/src/language/include-references.ts +49 -0
- package/src/language/include-resolver.ts +284 -10
- package/src/language/include-waves.ts +419 -0
- package/src/language/nowline-validator.ts +98 -1835
- package/src/language/nowline.langium +56 -22
- package/src/language/references.ts +40 -0
- package/src/language/style-chain.ts +95 -0
- package/src/language/validator/calendar.ts +319 -0
- package/src/language/validator/entities.ts +366 -0
- package/src/language/validator/properties.ts +425 -0
- package/src/language/validator/references.ts +295 -0
- package/src/language/validator/structure.ts +206 -0
- package/src/language/validator/style.ts +149 -0
- package/src/language/validator/support.ts +84 -0
- package/src/language/validator/symbols.ts +141 -0
- package/src/language/validator/tables.ts +171 -0
- package/src/language/validator-utils.ts +123 -0
- package/src/language/value-tables.ts +260 -0
- package/src/language/waves-order.ts +879 -0
- package/src/language/waves-plan.ts +101 -0
- package/src/language/waves.ts +731 -0
- package/src/util/props.ts +59 -0
- package/src/util/single-line.ts +15 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Support code the validator's checks share: diagnostic emission and the
|
|
2
|
+
// roadmap start lookup (specs/core-ast-utilities.md §3.6). Moved out of
|
|
3
|
+
// nowline-validator.ts as-is.
|
|
4
|
+
|
|
5
|
+
import type { AstNode, Properties, ValidationAcceptor, ValidationSeverity } from 'langium';
|
|
6
|
+
import type { NowlineFile } from '../../generated/ast.js';
|
|
7
|
+
import type { MessageArgs, MessageCode } from '../../i18n/index.js';
|
|
8
|
+
import { tr } from '../../i18n/index.js';
|
|
9
|
+
import { isRealIsoDate, propKey } from '../../util/props.js';
|
|
10
|
+
import type { WaveFinding } from '../waves.js';
|
|
11
|
+
|
|
12
|
+
export type StartState =
|
|
13
|
+
| { kind: 'valid'; iso: string; date: Date }
|
|
14
|
+
| { kind: 'invalid' }
|
|
15
|
+
| { kind: 'missing' };
|
|
16
|
+
|
|
17
|
+
export function resolveLocalStart(file: NowlineFile | undefined): StartState {
|
|
18
|
+
const prop = file?.roadmapDecl?.properties.find((p) => propKey(p) === 'start');
|
|
19
|
+
if (!prop) return { kind: 'missing' };
|
|
20
|
+
const raw = prop.value;
|
|
21
|
+
if (!raw || !isRealIsoDate(raw)) return { kind: 'invalid' };
|
|
22
|
+
return { kind: 'valid', iso: raw, date: new Date(raw) };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Emit a localized validator diagnostic.
|
|
27
|
+
*
|
|
28
|
+
* Validator runs at parse time when only the file's locale is in scope.
|
|
29
|
+
* The CLI re-formats with the operator's locale before printing —
|
|
30
|
+
* see `specs/localization.md` for the two-chain model. We always
|
|
31
|
+
* format the en-US text now so non-CLI consumers (LSP, tests) still
|
|
32
|
+
* see usable copy, and stash `{ code, args }` in `data` so the CLI
|
|
33
|
+
* can swap in the operator-locale text downstream.
|
|
34
|
+
*/
|
|
35
|
+
export type DiagnosticInfo = {
|
|
36
|
+
node: AstNode;
|
|
37
|
+
property?: Properties<AstNode>;
|
|
38
|
+
keyword?: string;
|
|
39
|
+
index?: number;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export function acceptTr<K extends MessageCode>(
|
|
43
|
+
accept: ValidationAcceptor,
|
|
44
|
+
severity: ValidationSeverity,
|
|
45
|
+
info: DiagnosticInfo,
|
|
46
|
+
code: K,
|
|
47
|
+
...args: MessageArgs<K>
|
|
48
|
+
): void {
|
|
49
|
+
accept(severity, tr('en-US', code, ...args), {
|
|
50
|
+
...info,
|
|
51
|
+
data: { code, args },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Translate a wave-rule finding (`waves.ts`) into a diagnostic. Coded
|
|
56
|
+
// findings go through `acceptTr`; the one uncoded rule (WV8) keeps its
|
|
57
|
+
// fixed English text, like the rest of rule 23.
|
|
58
|
+
export function acceptWaveFinding(accept: ValidationAcceptor, finding: WaveFinding): void {
|
|
59
|
+
const info: DiagnosticInfo = {
|
|
60
|
+
node: finding.node,
|
|
61
|
+
...(finding.property === undefined
|
|
62
|
+
? {}
|
|
63
|
+
: { property: finding.property as Properties<AstNode> }),
|
|
64
|
+
};
|
|
65
|
+
if ('message' in finding) {
|
|
66
|
+
accept(finding.severity, finding.message, info);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// The finding's `args` is the code's argument object; the union of codes
|
|
70
|
+
// does not narrow through the generic, so widen it to one code here.
|
|
71
|
+
acceptTr(accept, finding.severity, info, finding.code as 'NL.E1100', finding.args as never);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function locationOf(node: AstNode): string {
|
|
75
|
+
const cst = node.$cstNode;
|
|
76
|
+
if (cst) {
|
|
77
|
+
return `line ${cst.range.start.line + 1}`;
|
|
78
|
+
}
|
|
79
|
+
return 'unknown location';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function isIdentifier(val: string): boolean {
|
|
83
|
+
return /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(val);
|
|
84
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Symbol declaration, duplicate symbol id and symbol reference checks
|
|
2
|
+
// (specs/core-ast-utilities.md §3.6). Moved out of nowline-validator.ts as-is; the class
|
|
3
|
+
// forwards one method per check.
|
|
4
|
+
|
|
5
|
+
import type { AstNode, ValidationAcceptor } from 'langium';
|
|
6
|
+
import type { NowlineFile, SymbolDeclaration } from '../../generated/ast.js';
|
|
7
|
+
import {
|
|
8
|
+
isDefaultDeclaration,
|
|
9
|
+
isStyleDeclaration,
|
|
10
|
+
isSymbolDeclaration,
|
|
11
|
+
} from '../../generated/ast.js';
|
|
12
|
+
import { propKey } from '../../util/props.js';
|
|
13
|
+
import { displayName } from '../validator-utils.js';
|
|
14
|
+
import { BUILTIN_CAPACITY_ICONS, BUILTIN_ICON_NAMES } from '../value-tables.js';
|
|
15
|
+
import { acceptTr, isIdentifier, locationOf } from './support.js';
|
|
16
|
+
import { ASCII_FALLBACK_RE, BUILTIN_CAPACITY_ICON_SET, BUILTIN_ICON_NAME_SET } from './tables.js';
|
|
17
|
+
|
|
18
|
+
// --- Rules 17f / 17g / 17h / 17i: per-declaration symbol checks ---
|
|
19
|
+
// Note: Langium's default ValueConverter strips surrounding quotes from STRING
|
|
20
|
+
// tokens before they reach the AST, so unicode:"💰" arrives here as just "💰"
|
|
21
|
+
// — we validate the *content* (length / ASCII range) rather than presence of
|
|
22
|
+
// quotes. The grammar already restricts `unicode:` and `ascii:` to PropertyAtom,
|
|
23
|
+
// so the only quoteless form an author can pass is a bare identifier like
|
|
24
|
+
// `unicode:foo`, which we treat permissively (it's a single-grapheme literal).
|
|
25
|
+
export function checkSymbolDeclaration(decl: SymbolDeclaration, accept: ValidationAcceptor): void {
|
|
26
|
+
if (decl.name && BUILTIN_ICON_NAME_SET.has(decl.name)) {
|
|
27
|
+
acceptTr(accept, 'error', { node: decl, property: 'name' }, 'NL.E0805', {
|
|
28
|
+
name: decl.name,
|
|
29
|
+
builtins: [...BUILTIN_ICON_NAMES].sort().join(', '),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const unicodeProp = decl.properties.find((p) => propKey(p) === 'unicode');
|
|
34
|
+
if (!unicodeProp) {
|
|
35
|
+
acceptTr(accept, 'error', { node: decl }, 'NL.E0806', { name: displayName(decl) });
|
|
36
|
+
} else if (!unicodeProp.value || unicodeProp.value.length === 0) {
|
|
37
|
+
acceptTr(accept, 'error', { node: unicodeProp, property: 'value' }, 'NL.E0807', {
|
|
38
|
+
name: displayName(decl),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const asciiProp = decl.properties.find((p) => propKey(p) === 'ascii');
|
|
43
|
+
if (asciiProp) {
|
|
44
|
+
const raw = asciiProp.value ?? '';
|
|
45
|
+
if (!ASCII_FALLBACK_RE.test(raw)) {
|
|
46
|
+
acceptTr(accept, 'error', { node: asciiProp, property: 'value' }, 'NL.E0808', {
|
|
47
|
+
name: displayName(decl),
|
|
48
|
+
length: raw.length,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const prop of decl.properties) {
|
|
54
|
+
const key = propKey(prop);
|
|
55
|
+
if (key !== 'unicode' && key !== 'ascii' && key !== 'link' && key !== 'description') {
|
|
56
|
+
acceptTr(accept, 'error', { node: prop, property: 'key' }, 'NL.E0809', { key });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// --- Rule 17j: duplicate symbol ids in the same file ---
|
|
62
|
+
export function checkDuplicateSymbolIds(file: NowlineFile, accept: ValidationAcceptor): void {
|
|
63
|
+
const seen = new Map<string, SymbolDeclaration>();
|
|
64
|
+
for (const entry of file.configEntries) {
|
|
65
|
+
if (isSymbolDeclaration(entry) && entry.name) {
|
|
66
|
+
const existing = seen.get(entry.name);
|
|
67
|
+
if (existing) {
|
|
68
|
+
acceptTr(accept, 'error', { node: entry, property: 'name' }, 'NL.E0810', {
|
|
69
|
+
name: entry.name,
|
|
70
|
+
location: locationOf(existing),
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
seen.set(entry.name, entry);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// --- Rule 17k: icon: / capacity-icon: references resolve to a built-in,
|
|
80
|
+
// a quoted Unicode literal, or an earlier symbol declaration. Forward
|
|
81
|
+
// references are an error. Walks both StyleDeclaration.properties and
|
|
82
|
+
// DefaultDeclaration.properties so style blocks and default <entity>
|
|
83
|
+
// lines share one path.
|
|
84
|
+
export function checkSymbolReferences(file: NowlineFile, accept: ValidationAcceptor): void {
|
|
85
|
+
const symbolOrder = new Map<string, number>();
|
|
86
|
+
for (let i = 0; i < file.configEntries.length; i++) {
|
|
87
|
+
const entry = file.configEntries[i];
|
|
88
|
+
if (isSymbolDeclaration(entry) && entry.name) {
|
|
89
|
+
if (!symbolOrder.has(entry.name)) symbolOrder.set(entry.name, i);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const checkRef = (
|
|
94
|
+
entryIdx: number,
|
|
95
|
+
key: string,
|
|
96
|
+
val: string | undefined,
|
|
97
|
+
propNode: AstNode,
|
|
98
|
+
) => {
|
|
99
|
+
if (key !== 'icon' && key !== 'capacity-icon') return;
|
|
100
|
+
if (!val) return;
|
|
101
|
+
// Inline Unicode literals (`capacity-icon:"💰"`) reach the AST as their
|
|
102
|
+
// unquoted content — the only way to tell them from an identifier
|
|
103
|
+
// reference is by checking the character set. Anything that doesn't
|
|
104
|
+
// look like an identifier is treated as a literal and
|
|
105
|
+
// accepted as-is. Authors who genuinely want to write a literal that
|
|
106
|
+
// happens to spell a real identifier should declare a symbol instead.
|
|
107
|
+
if (!isIdentifier(val)) return;
|
|
108
|
+
if (key === 'capacity-icon' && BUILTIN_CAPACITY_ICON_SET.has(val)) return;
|
|
109
|
+
if (key === 'icon' && BUILTIN_ICON_NAME_SET.has(val)) return;
|
|
110
|
+
const declIdx = symbolOrder.get(val);
|
|
111
|
+
if (declIdx === undefined) {
|
|
112
|
+
const builtins =
|
|
113
|
+
key === 'capacity-icon'
|
|
114
|
+
? [...BUILTIN_CAPACITY_ICONS].sort().join(', ')
|
|
115
|
+
: [...BUILTIN_ICON_NAMES].sort().join(', ');
|
|
116
|
+
acceptTr(accept, 'error', { node: propNode, property: 'value' }, 'NL.E0811', {
|
|
117
|
+
key,
|
|
118
|
+
value: val,
|
|
119
|
+
builtins,
|
|
120
|
+
});
|
|
121
|
+
} else if (declIdx >= entryIdx) {
|
|
122
|
+
acceptTr(accept, 'error', { node: propNode, property: 'value' }, 'NL.E0812', {
|
|
123
|
+
key,
|
|
124
|
+
value: val,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
for (let i = 0; i < file.configEntries.length; i++) {
|
|
130
|
+
const entry = file.configEntries[i];
|
|
131
|
+
if (isStyleDeclaration(entry)) {
|
|
132
|
+
for (const sp of entry.properties) {
|
|
133
|
+
checkRef(i, propKey(sp), sp.value, sp);
|
|
134
|
+
}
|
|
135
|
+
} else if (isDefaultDeclaration(entry)) {
|
|
136
|
+
for (const ep of entry.properties) {
|
|
137
|
+
checkRef(i, propKey(ep), ep.value, ep);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Constants, vocabularies and regexes the validator's checks share
|
|
2
|
+
// (specs/core-ast-utilities.md §3.6). Moved out of nowline-validator.ts as-is.
|
|
3
|
+
|
|
4
|
+
import type { DefaultEntityType } from '../../generated/ast.js';
|
|
5
|
+
import {
|
|
6
|
+
BUILTIN_CAPACITY_ICONS,
|
|
7
|
+
BUILTIN_ICON_NAMES,
|
|
8
|
+
BUILTIN_STATUSES,
|
|
9
|
+
CALENDAR_FIELDS as CALENDAR_FIELD_LIST,
|
|
10
|
+
CALENDAR_MODES as CALENDAR_MODE_LIST,
|
|
11
|
+
COLOR_NAMES as COLOR_NAME_LIST,
|
|
12
|
+
DEFAULT_ENTITY_TYPES as DEFAULT_ENTITY_TYPE_LIST,
|
|
13
|
+
DIRECTIVE_FIELDS as DIRECTIVE_FIELD_LIST,
|
|
14
|
+
ENTITY_KNOWN_PROPS as ENTITY_KNOWN_PROP_LISTS,
|
|
15
|
+
INCLUDE_MODES as INCLUDE_MODE_LIST,
|
|
16
|
+
NON_WORKING_DISPLAYS,
|
|
17
|
+
ROADMAP_ONLY_STYLE_KEYS as ROADMAP_ONLY_STYLE_KEY_LIST,
|
|
18
|
+
SCALE_FIELDS as SCALE_FIELD_LIST,
|
|
19
|
+
STYLE_PROP_ENUMS as STYLE_PROP_ENUM_LISTS,
|
|
20
|
+
STYLE_PROP_KEYS as STYLE_PROP_KEY_LIST,
|
|
21
|
+
UNIVERSAL_ENTITY_PROPS as UNIVERSAL_ENTITY_PROP_LIST,
|
|
22
|
+
} from '../value-tables.js';
|
|
23
|
+
|
|
24
|
+
export { UTILIZATION_NONE } from '../value-tables.js';
|
|
25
|
+
|
|
26
|
+
export const SUPPORTED_VERSION = 'v1';
|
|
27
|
+
|
|
28
|
+
// Built-in vocabularies come from value-tables.ts; the validator checks
|
|
29
|
+
// membership, so it holds them as sets.
|
|
30
|
+
export const BUILTIN_STATUS_SET: ReadonlySet<string> = new Set(BUILTIN_STATUSES);
|
|
31
|
+
export const BUILTIN_CAPACITY_ICON_SET: ReadonlySet<string> = new Set(BUILTIN_CAPACITY_ICONS);
|
|
32
|
+
export const BUILTIN_ICON_NAME_SET: ReadonlySet<string> = new Set(BUILTIN_ICON_NAMES);
|
|
33
|
+
|
|
34
|
+
// Key vocabularies come from value-tables.ts too, held here as sets.
|
|
35
|
+
export const STYLE_PROP_KEYS: ReadonlySet<string> = new Set(STYLE_PROP_KEY_LIST);
|
|
36
|
+
|
|
37
|
+
// `non-working:` values (specs/working-calendar.md §4.2). Kept out of
|
|
38
|
+
// `STYLE_PROP_ENUMS` on purpose: the key reports its own coded NL.E0800,
|
|
39
|
+
// and the generic enum check would add a second error (NL.E0802).
|
|
40
|
+
export const NON_WORKING_VALUES: ReadonlySet<string> = new Set(NON_WORKING_DISPLAYS);
|
|
41
|
+
|
|
42
|
+
export const ROADMAP_ONLY_STYLE_KEYS: ReadonlySet<string> = new Set(ROADMAP_ONLY_STYLE_KEY_LIST);
|
|
43
|
+
|
|
44
|
+
// Style enums, colour names and calendar modes come from value-tables.ts,
|
|
45
|
+
// held here as sets for the membership checks.
|
|
46
|
+
export const STYLE_PROP_ENUMS: Record<string, ReadonlySet<string>> = Object.fromEntries(
|
|
47
|
+
Object.entries(STYLE_PROP_ENUM_LISTS).map(([key, values]) => [key, new Set(values)]),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const COLOR_NAMES: ReadonlySet<string> = new Set(COLOR_NAME_LIST);
|
|
51
|
+
|
|
52
|
+
export const CALENDAR_MODES: ReadonlySet<string> = new Set(CALENDAR_MODE_LIST);
|
|
53
|
+
|
|
54
|
+
export const CALENDAR_FIELDS: ReadonlySet<string> = new Set(CALENDAR_FIELD_LIST);
|
|
55
|
+
|
|
56
|
+
export const SCALE_FIELDS: ReadonlySet<string> = new Set(SCALE_FIELD_LIST);
|
|
57
|
+
|
|
58
|
+
export const DEFAULT_ENTITY_TYPES: ReadonlySet<string> = new Set(DEFAULT_ENTITY_TYPE_LIST);
|
|
59
|
+
|
|
60
|
+
// Banned properties per entity type on `default <entity>` lines.
|
|
61
|
+
// `capacity` on `default swimlane` is banned because each lane's budget must be
|
|
62
|
+
// explicit at its declaration site (per dsl.md). `capacity` on `default item` is
|
|
63
|
+
// allowed (and a useful "every item consumes 1 unit by default" lever).
|
|
64
|
+
export const DEFAULT_BANNED: Record<DefaultEntityType, Set<string>> = {
|
|
65
|
+
item: new Set([
|
|
66
|
+
'size',
|
|
67
|
+
'duration',
|
|
68
|
+
'after',
|
|
69
|
+
'before',
|
|
70
|
+
'remaining',
|
|
71
|
+
'link',
|
|
72
|
+
'description',
|
|
73
|
+
'owner',
|
|
74
|
+
]),
|
|
75
|
+
milestone: new Set(['date', 'after', 'link', 'description']),
|
|
76
|
+
anchor: new Set(['date', 'link', 'description']),
|
|
77
|
+
footnote: new Set(['on', 'link', 'description']),
|
|
78
|
+
label: new Set(['link', 'description']),
|
|
79
|
+
swimlane: new Set(['capacity']),
|
|
80
|
+
roadmap: new Set(),
|
|
81
|
+
parallel: new Set(),
|
|
82
|
+
group: new Set(),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const UNIVERSAL_ENTITY_PROPS: ReadonlySet<string> = new Set(UNIVERSAL_ENTITY_PROP_LIST);
|
|
86
|
+
|
|
87
|
+
export const ENTITY_KNOWN_PROPS: Record<string, ReadonlySet<string>> = Object.fromEntries(
|
|
88
|
+
Object.entries(ENTITY_KNOWN_PROP_LISTS).map(([type, keys]) => [type, new Set(keys)]),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
// Conceptual mistakes that aren't typos of a real key — e.g. `progress:60` is a
|
|
92
|
+
// reasonable guess for "60% done", but Nowline models completion as
|
|
93
|
+
// `status:` + `remaining:` (work *left*). Levenshtein can't bridge that gap, so
|
|
94
|
+
// we map the concept directly. `requires` names a key the entity must support,
|
|
95
|
+
// so the hint only fires where it's actionable (e.g. on an `item`, which has
|
|
96
|
+
// `remaining`, not on a `roadmap` line). `entities`, when set, narrows it
|
|
97
|
+
// further to the declarations where the suggested form is valid.
|
|
98
|
+
const CONCEPT_ALIASES: ReadonlyArray<{
|
|
99
|
+
keys: ReadonlySet<string>;
|
|
100
|
+
requires: string;
|
|
101
|
+
entities?: ReadonlySet<string>;
|
|
102
|
+
suggest: string;
|
|
103
|
+
}> = [
|
|
104
|
+
{
|
|
105
|
+
keys: new Set(['progress', 'percent', 'percentage', 'pct', 'complete', 'completion']),
|
|
106
|
+
requires: 'remaining',
|
|
107
|
+
suggest: 'status: + remaining:',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
// A fixed start date is not supported on work (`specs/dsl.md` §
|
|
111
|
+
// Item Properties); `after:<date>` is "not before". An inline date
|
|
112
|
+
// in `after:` is valid on an item, parallel and group only
|
|
113
|
+
// (Validation Rule 24a), so a swimlane gets no hint.
|
|
114
|
+
keys: new Set(['date', 'start']),
|
|
115
|
+
requires: 'after',
|
|
116
|
+
entities: new Set(['ItemDeclaration', 'ParallelBlock', 'GroupBlock']),
|
|
117
|
+
suggest: 'after:<date>',
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
// Suggest the canonical property (or combination) for a known conceptual
|
|
122
|
+
// mistake, gated to entities that actually support the target key. Returns
|
|
123
|
+
// undefined when no concept matches so callers fall back to `suggestKey`.
|
|
124
|
+
export function suggestConcept(
|
|
125
|
+
key: string,
|
|
126
|
+
known: ReadonlySet<string>,
|
|
127
|
+
entityType?: string,
|
|
128
|
+
): string | undefined {
|
|
129
|
+
const lower = key.toLowerCase();
|
|
130
|
+
for (const alias of CONCEPT_ALIASES) {
|
|
131
|
+
if (!alias.keys.has(lower) || !known.has(alias.requires)) continue;
|
|
132
|
+
if (alias.entities && (entityType === undefined || !alias.entities.has(entityType))) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
return alias.suggest;
|
|
136
|
+
}
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Matches duration literals including decimals, e.g. `2w`, `0.5d`, `1.5m`.
|
|
141
|
+
export const DURATION_RE = /^\d+(?:\.\d+)?[dwmqy]$/;
|
|
142
|
+
export const PERCENTAGE_RE = /^\d+%$/;
|
|
143
|
+
export const HEX_COLOR_RE = /^#[0-9a-fA-F]{3,8}$/;
|
|
144
|
+
export const VERSION_RE = /^v\d+$/;
|
|
145
|
+
export const INTEGER_RE = /^\d+$/;
|
|
146
|
+
export const BARE_DURATION_SUFFIX_RE = /^[dwmqy]$/;
|
|
147
|
+
// Capacity numeric forms — the grammar already separates DECIMAL/INTEGER/PERCENTAGE
|
|
148
|
+
// terminals, but the validator needs to enforce the spec's "positive number" rule
|
|
149
|
+
// and to differentiate where percent is allowed (item) vs. banned (swimlane).
|
|
150
|
+
export const POSITIVE_NUMBER_RE = /^\d+(\.\d+)?$/;
|
|
151
|
+
export const POSITIVE_PERCENT_RE = /^\d+(\.\d+)?%$/;
|
|
152
|
+
// Disambiguated forms used by `utilization-warn-at:` / `utilization-over-at:`.
|
|
153
|
+
// A decimal-fraction MUST include the dot so its meaning is unambiguous; a
|
|
154
|
+
// bare integer matches the integer regex and is rejected by the validator
|
|
155
|
+
// with a hint to switch to either the percent or decimal-fraction form.
|
|
156
|
+
export const POSITIVE_DECIMAL_FRACTION_RE = /^\d+\.\d+$/;
|
|
157
|
+
export const POSITIVE_INTEGER_RE = /^\d+$/;
|
|
158
|
+
// ASCII printable, length 1-3 — used by the glyph declaration validator for the
|
|
159
|
+
// `ascii:"..."` fallback property after Langium has stripped the surrounding quotes.
|
|
160
|
+
export const ASCII_FALLBACK_RE = /^[\x20-\x7E]{1,3}$/;
|
|
161
|
+
|
|
162
|
+
// BCP-47 language tag, simplified to the subset Nowline cares about: a 2- or 3-letter
|
|
163
|
+
// primary language subtag followed by an optional region subtag (2 letters or 3 digits).
|
|
164
|
+
// Permissive enough for `fr`, `fr-CA`, `zh-CN`, `es-419` while rejecting obvious typos.
|
|
165
|
+
// The runtime resolver does the actual fallback work; this regex just gates input shape.
|
|
166
|
+
export const BCP47_RE = /^[a-zA-Z]{2,3}(-[a-zA-Z]{2}|-\d{3})?$/;
|
|
167
|
+
|
|
168
|
+
// From value-tables.ts, held as a set for the membership check.
|
|
169
|
+
export const INCLUDE_MODES: ReadonlySet<string> = new Set(INCLUDE_MODE_LIST);
|
|
170
|
+
|
|
171
|
+
export const DIRECTIVE_FIELDS: ReadonlySet<string> = new Set(DIRECTIVE_FIELD_LIST);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Small helpers shared by the validator (`nowline-validator.ts`) and the
|
|
2
|
+
// wave rules (`waves.ts`). Kept free of Langium services so both the
|
|
3
|
+
// validator and the include resolver can call the wave rules as pure
|
|
4
|
+
// functions.
|
|
5
|
+
|
|
6
|
+
import type { AstNode } from 'langium';
|
|
7
|
+
import { singleLine } from '../util/single-line.js';
|
|
8
|
+
|
|
9
|
+
// Levenshtein distance with an early-exit cap: returns `cap + 1` once the running
|
|
10
|
+
// minimum exceeds the cap so we can short-circuit the matcher in the common case
|
|
11
|
+
// where the typo is much further than 2 edits from any valid key. Used for the
|
|
12
|
+
// "did you mean?" suggestions on unknown property keys and wave ids.
|
|
13
|
+
export function levenshteinCapped(a: string, b: string, cap: number): number {
|
|
14
|
+
if (a === b) return 0;
|
|
15
|
+
const an = a.length;
|
|
16
|
+
const bn = b.length;
|
|
17
|
+
if (Math.abs(an - bn) > cap) return cap + 1;
|
|
18
|
+
if (an === 0) return bn;
|
|
19
|
+
if (bn === 0) return an;
|
|
20
|
+
let prev = new Array<number>(bn + 1);
|
|
21
|
+
let curr = new Array<number>(bn + 1);
|
|
22
|
+
for (let j = 0; j <= bn; j++) prev[j] = j;
|
|
23
|
+
for (let i = 1; i <= an; i++) {
|
|
24
|
+
curr[0] = i;
|
|
25
|
+
let rowMin = i;
|
|
26
|
+
for (let j = 1; j <= bn; j++) {
|
|
27
|
+
const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1;
|
|
28
|
+
curr[j] = Math.min(
|
|
29
|
+
prev[j] + 1, // deletion
|
|
30
|
+
curr[j - 1] + 1, // insertion
|
|
31
|
+
prev[j - 1] + cost, // substitution
|
|
32
|
+
);
|
|
33
|
+
if (curr[j] < rowMin) rowMin = curr[j];
|
|
34
|
+
}
|
|
35
|
+
if (rowMin > cap) return cap + 1;
|
|
36
|
+
const tmp = prev;
|
|
37
|
+
prev = curr;
|
|
38
|
+
curr = tmp;
|
|
39
|
+
}
|
|
40
|
+
return prev[bn];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Pick the closest known key within `cap` edits of `key`, or undefined. Ties are
|
|
44
|
+
// broken by the order of `candidates`, so callers should pass entity-specific keys
|
|
45
|
+
// first when both lists are searched.
|
|
46
|
+
export function suggestKey(key: string, candidates: Iterable<string>, cap = 2): string | undefined {
|
|
47
|
+
let best: string | undefined;
|
|
48
|
+
let bestDist = cap + 1;
|
|
49
|
+
for (const c of candidates) {
|
|
50
|
+
const d = levenshteinCapped(key, c, cap);
|
|
51
|
+
if (d < bestDist) {
|
|
52
|
+
best = c;
|
|
53
|
+
bestDist = d;
|
|
54
|
+
if (d === 0) break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return best;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Like `suggestKey`, but returns undefined when the best distance is shared by
|
|
61
|
+
// more than one candidate, so a suggestion is only made when it is unambiguous.
|
|
62
|
+
export function suggestUniqueKey(
|
|
63
|
+
key: string,
|
|
64
|
+
candidates: Iterable<string>,
|
|
65
|
+
cap = 2,
|
|
66
|
+
): string | undefined {
|
|
67
|
+
let best: string | undefined;
|
|
68
|
+
let bestDist = cap + 1;
|
|
69
|
+
let tied = false;
|
|
70
|
+
for (const c of candidates) {
|
|
71
|
+
const d = levenshteinCapped(key, c, cap);
|
|
72
|
+
if (d < bestDist) {
|
|
73
|
+
best = c;
|
|
74
|
+
bestDist = d;
|
|
75
|
+
tied = false;
|
|
76
|
+
} else if (d === bestDist && d <= cap && c !== best) {
|
|
77
|
+
tied = true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return tied ? undefined : best;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The name a diagnostic echoes for an entity: its id, else its title. A
|
|
85
|
+
* title can carry explicit line breaks, but a diagnostic is one line of
|
|
86
|
+
* text, so breaks collapse to a single space (`singleLine`).
|
|
87
|
+
*/
|
|
88
|
+
export function displayName(node: { name?: string; title?: string }): string {
|
|
89
|
+
return node.name ?? (node.title === undefined ? '<unnamed>' : singleLine(node.title));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Returns the lowercase entity-type label for an AST node, suitable for
|
|
94
|
+
* embedding inside a validator message (e.g. `"item"`, `"milestone"`,
|
|
95
|
+
* `"swimlane"`). Mirrors `describeNode`'s normalization (strip
|
|
96
|
+
* `Declaration` / `Block` suffix, lowercase) but returns just the type so
|
|
97
|
+
* callers can compose their own message.
|
|
98
|
+
*/
|
|
99
|
+
export function entityTypeLabel(node: { $type: string }): string {
|
|
100
|
+
// `NonWorkingDeclaration` would lowercase to `nonworking`; the keyword is hyphenated.
|
|
101
|
+
if (node.$type === 'NonWorkingDeclaration') return 'non-working';
|
|
102
|
+
return node.$type.replace(/Declaration$|Block$/, '').toLowerCase();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function describeNode(node: { $type: string; name?: string; title?: string }): string {
|
|
106
|
+
const kind = entityTypeLabel(node);
|
|
107
|
+
const label = node.name ?? (node.title === undefined ? undefined : singleLine(node.title));
|
|
108
|
+
return label ? `${kind} "${label}"` : kind;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** 1-based source line of a node, or 0 when it has no CST node. */
|
|
112
|
+
export function lineOf(node: AstNode): number {
|
|
113
|
+
const cst = node.$cstNode;
|
|
114
|
+
return cst ? cst.range.start.line + 1 : 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Defaults rule 23: the message for a property that cannot be set on a
|
|
118
|
+
// `default <entity>` line. Shared by `checkDefaultDeclaration` (static
|
|
119
|
+
// `DEFAULT_BANNED` table) and the wave rules (`wave` on a default line in a
|
|
120
|
+
// roadmap with waves), so both read the same.
|
|
121
|
+
export function defaultBannedMessage(key: string, entityType: string): string {
|
|
122
|
+
return `"${key}" cannot be set on "default ${entityType}". Identity-defining, sizing, sequencing, reference, and prose properties must be explicit on each entity.`;
|
|
123
|
+
}
|