@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,158 @@
|
|
|
1
|
+
// One walk over a roadmap's declarations (specs/core-ast-utilities.md §3.1).
|
|
2
|
+
//
|
|
3
|
+
// The declarations form a fixed tree (nowline.langium): roadmap entries;
|
|
4
|
+
// swimlane, group and parallel content (items, groups, parallels, with
|
|
5
|
+
// `description` lines to skip); teams nested in teams. This module is the only
|
|
6
|
+
// place that says what a child is, so a new container keyword is added here
|
|
7
|
+
// once. It is a leaf module: it imports only the generated AST and Langium
|
|
8
|
+
// types.
|
|
9
|
+
|
|
10
|
+
import type { AstNode } from 'langium';
|
|
11
|
+
import {
|
|
12
|
+
type ConfigEntry,
|
|
13
|
+
type EntityProperty,
|
|
14
|
+
type GroupBlock,
|
|
15
|
+
type ItemDeclaration,
|
|
16
|
+
isDescriptionDirective,
|
|
17
|
+
isGroupBlock,
|
|
18
|
+
isParallelBlock,
|
|
19
|
+
isSwimlaneDeclaration,
|
|
20
|
+
isTeamDeclaration,
|
|
21
|
+
type NowlineFile,
|
|
22
|
+
type ParallelBlock,
|
|
23
|
+
type RoadmapDeclaration,
|
|
24
|
+
type RoadmapEntry,
|
|
25
|
+
type SwimlaneDeclaration,
|
|
26
|
+
type TeamDeclaration,
|
|
27
|
+
} from '../generated/ast.js';
|
|
28
|
+
|
|
29
|
+
/** A node that sits on a swimlane track. */
|
|
30
|
+
export type TrackNode = ItemDeclaration | GroupBlock | ParallelBlock;
|
|
31
|
+
|
|
32
|
+
/** Any declaration the walk visits. */
|
|
33
|
+
export type DeclarationNode =
|
|
34
|
+
| RoadmapDeclaration
|
|
35
|
+
| RoadmapEntry
|
|
36
|
+
| TrackNode
|
|
37
|
+
| TeamDeclaration
|
|
38
|
+
| ConfigEntry;
|
|
39
|
+
|
|
40
|
+
export interface WalkOptions {
|
|
41
|
+
/** Visit `roadmapDecl` first. Default false. */
|
|
42
|
+
roadmap?: boolean;
|
|
43
|
+
/** Visit `configEntries` before the roadmap. Default false. */
|
|
44
|
+
config?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A container's track children in source order, `description` lines skipped. */
|
|
48
|
+
export function trackChildren(node: SwimlaneDeclaration | GroupBlock | ParallelBlock): TrackNode[] {
|
|
49
|
+
const out: TrackNode[] = [];
|
|
50
|
+
for (const child of node.content) {
|
|
51
|
+
if (!isDescriptionDirective(child)) out.push(child);
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Every track node under `lanes`, pre-order, in source order. */
|
|
57
|
+
export function* trackNodes(lanes: Iterable<SwimlaneDeclaration>): Generator<TrackNode> {
|
|
58
|
+
for (const lane of lanes) yield* trackDescendants(lane);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Track nodes under a swimlane, group or parallel, pre-order.
|
|
62
|
+
function* trackDescendants(
|
|
63
|
+
container: SwimlaneDeclaration | GroupBlock | ParallelBlock,
|
|
64
|
+
): Generator<TrackNode> {
|
|
65
|
+
for (const child of trackChildren(container)) {
|
|
66
|
+
yield child;
|
|
67
|
+
if (isGroupBlock(child) || isParallelBlock(child)) yield* trackDescendants(child);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Teams nested in `team`, pre-order. `PersonMemberRef` lines are references and
|
|
72
|
+
// `description` lines are prose, so neither is a declaration.
|
|
73
|
+
function* nestedTeams(team: TeamDeclaration): Generator<TeamDeclaration> {
|
|
74
|
+
for (const member of team.content) {
|
|
75
|
+
if (isTeamDeclaration(member)) {
|
|
76
|
+
yield member;
|
|
77
|
+
yield* nestedTeams(member);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// What sits under a node: a swimlane's, group's or parallel's track content, a
|
|
83
|
+
// team's nested teams, nothing for every other node.
|
|
84
|
+
function* nestedDeclarations(node: AstNode): Generator<TrackNode | TeamDeclaration> {
|
|
85
|
+
if (isSwimlaneDeclaration(node) || isGroupBlock(node) || isParallelBlock(node)) {
|
|
86
|
+
yield* trackDescendants(node);
|
|
87
|
+
} else if (isTeamDeclaration(node)) {
|
|
88
|
+
yield* nestedTeams(node);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Every declaration in the file, pre-order, in source order: optionally the
|
|
94
|
+
* config entries and the roadmap line, then each roadmap entry followed by
|
|
95
|
+
* its track content (swimlanes) or nested teams (teams).
|
|
96
|
+
*/
|
|
97
|
+
export function* declarations(
|
|
98
|
+
file: NowlineFile,
|
|
99
|
+
options: WalkOptions = {},
|
|
100
|
+
): Generator<DeclarationNode> {
|
|
101
|
+
if (options.config) yield* file.configEntries;
|
|
102
|
+
if (options.roadmap && file.roadmapDecl) yield file.roadmapDecl;
|
|
103
|
+
for (const entry of file.roadmapEntries) {
|
|
104
|
+
yield entry;
|
|
105
|
+
yield* nestedDeclarations(entry);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Every property on `node` and on the declarations nested under it, with its owner. */
|
|
110
|
+
export function visitProperties(
|
|
111
|
+
node: AstNode,
|
|
112
|
+
visit: (prop: EntityProperty, owner: AstNode) => void,
|
|
113
|
+
): void {
|
|
114
|
+
visitOwnProperties(node, visit);
|
|
115
|
+
for (const nested of nestedDeclarations(node)) visitOwnProperties(nested, visit);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function visitOwnProperties(
|
|
119
|
+
node: AstNode,
|
|
120
|
+
visit: (prop: EntityProperty, owner: AstNode) => void,
|
|
121
|
+
): void {
|
|
122
|
+
const props = (node as { properties?: EntityProperty[] }).properties;
|
|
123
|
+
if (!Array.isArray(props)) return;
|
|
124
|
+
for (const prop of props) visit(prop, node);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Each explicit id a roadmap entry declares, in source order (rule 2, WV2). */
|
|
128
|
+
export function forEachDeclaredId(
|
|
129
|
+
entry: RoadmapEntry,
|
|
130
|
+
register: (name: string | undefined, node: AstNode) => void,
|
|
131
|
+
): void {
|
|
132
|
+
register(entry.name, entry);
|
|
133
|
+
for (const child of nestedDeclarations(entry)) register(child.name, child);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function nameOf(node: AstNode): string | undefined {
|
|
137
|
+
return (node as { name?: string }).name;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Ids `after:`, `before:` and `on:` can name: the roadmap's id plus every declared id. */
|
|
141
|
+
export function referenceableIds(file: NowlineFile): Set<string> {
|
|
142
|
+
const ids = new Set<string>();
|
|
143
|
+
for (const node of declarations(file, { roadmap: true })) {
|
|
144
|
+
const name = nameOf(node);
|
|
145
|
+
if (name) ids.add(name);
|
|
146
|
+
}
|
|
147
|
+
return ids;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Id to its first declaration (roadmap line and roadmap entries). */
|
|
151
|
+
export function firstDeclarations(file: NowlineFile): Map<string, AstNode> {
|
|
152
|
+
const ids = new Map<string, AstNode>();
|
|
153
|
+
for (const node of declarations(file, { roadmap: true })) {
|
|
154
|
+
const name = nameOf(node);
|
|
155
|
+
if (name && !ids.has(name)) ids.set(name, node);
|
|
156
|
+
}
|
|
157
|
+
return ids;
|
|
158
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// What a `non-working` or `working` declaration says, read once
|
|
2
|
+
// (specs/core-ast-utilities.md §3.4, specs/working-calendar.md §4.1): its
|
|
3
|
+
// shape (a dated list, a range, or a weekly recurrence, bounded or not),
|
|
4
|
+
// its real dates and known weekdays, and whether the calendar resolver can
|
|
5
|
+
// use it. The validator picks its codes from these facts, layout maps them to
|
|
6
|
+
// a `CalendarRule`, and LSP hover reads the shape. Exported only through
|
|
7
|
+
// `@nowline/core/internal`. A leaf module: it imports nothing but the
|
|
8
|
+
// generated AST types and `util/props.ts`.
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
EntityProperty,
|
|
12
|
+
NonWorkingDeclaration,
|
|
13
|
+
WorkingDeclaration,
|
|
14
|
+
} from '../generated/ast.js';
|
|
15
|
+
import { isRealIsoDate, propKey } from '../util/props.js';
|
|
16
|
+
|
|
17
|
+
/** The weekday names `every:` takes, Sunday first (the order of `Date#getUTCDay`). */
|
|
18
|
+
export const WEEKDAYS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'] as const;
|
|
19
|
+
export type Weekday = (typeof WEEKDAYS)[number];
|
|
20
|
+
|
|
21
|
+
/** UTC weekday number (Sunday is 0), the numbering of `CalendarRule.every`. */
|
|
22
|
+
export const WEEKDAY_INDEX: Readonly<Record<Weekday, number>> = {
|
|
23
|
+
sun: 0,
|
|
24
|
+
mon: 1,
|
|
25
|
+
tue: 2,
|
|
26
|
+
wed: 3,
|
|
27
|
+
thu: 4,
|
|
28
|
+
fri: 5,
|
|
29
|
+
sat: 6,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** True for one of the seven weekday names (not an inherited key such as `constructor`). */
|
|
33
|
+
export function isWeekday(name: string): name is Weekday {
|
|
34
|
+
return Object.hasOwn(WEEKDAY_INDEX, name);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type CalendarShape =
|
|
38
|
+
| 'dated' // date: alone
|
|
39
|
+
| 'range' // start: + end:, no every:
|
|
40
|
+
| 'open-recurrence' // every: alone
|
|
41
|
+
| 'half-bounded-recurrence' // every: + exactly one of start: / end:
|
|
42
|
+
| 'bounded-recurrence' // every: + start: + end:
|
|
43
|
+
| 'malformed'; // any other combination
|
|
44
|
+
|
|
45
|
+
export type CalendarDeclarationKey = 'date' | 'start' | 'end' | 'every';
|
|
46
|
+
|
|
47
|
+
export interface CalendarDeclarationFacts {
|
|
48
|
+
/** First occurrence of each of `date`, `start`, `end`, `every`; other keys are NL.E0901's. */
|
|
49
|
+
own: ReadonlyMap<CalendarDeclarationKey, EntityProperty>;
|
|
50
|
+
shape: CalendarShape;
|
|
51
|
+
/** Real dates of `date:`, or undefined when any is not a real day. */
|
|
52
|
+
dates?: string[];
|
|
53
|
+
/** The single real date of `start:` / `end:`, or undefined. */
|
|
54
|
+
start?: string;
|
|
55
|
+
end?: string;
|
|
56
|
+
/** Weekday numbers of `every:`, or undefined when any name is unknown. */
|
|
57
|
+
weekdays?: number[];
|
|
58
|
+
/** The resolver uses it: not malformed, every value real or known, and end not before start. */
|
|
59
|
+
wellFormed: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The keys a declaration takes; any other is NL.E0901. */
|
|
63
|
+
export const CALENDAR_DECLARATION_KEYS: ReadonlySet<string> = new Set<CalendarDeclarationKey>([
|
|
64
|
+
'date',
|
|
65
|
+
'start',
|
|
66
|
+
'end',
|
|
67
|
+
'every',
|
|
68
|
+
]);
|
|
69
|
+
|
|
70
|
+
/** Everything the validator, layout and hover need to know about one declaration. */
|
|
71
|
+
export function classifyCalendarDeclaration(
|
|
72
|
+
decl: NonWorkingDeclaration | WorkingDeclaration,
|
|
73
|
+
): CalendarDeclarationFacts {
|
|
74
|
+
const own = new Map<CalendarDeclarationKey, EntityProperty>();
|
|
75
|
+
for (const prop of decl.properties) {
|
|
76
|
+
const key = propKey(prop);
|
|
77
|
+
if (CALENDAR_DECLARATION_KEYS.has(key) && !own.has(key as CalendarDeclarationKey)) {
|
|
78
|
+
own.set(key as CalendarDeclarationKey, prop);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const shape = shapeOf(own);
|
|
83
|
+
const facts: CalendarDeclarationFacts = { own, shape, wellFormed: false };
|
|
84
|
+
|
|
85
|
+
const date = own.get('date');
|
|
86
|
+
if (date) {
|
|
87
|
+
const values = valuesOf(date);
|
|
88
|
+
if (values.every(isRealIsoDate)) facts.dates = values;
|
|
89
|
+
}
|
|
90
|
+
const start = singleDate(own.get('start'));
|
|
91
|
+
if (start !== undefined) facts.start = start;
|
|
92
|
+
const end = singleDate(own.get('end'));
|
|
93
|
+
if (end !== undefined) facts.end = end;
|
|
94
|
+
const every = own.get('every');
|
|
95
|
+
if (every) {
|
|
96
|
+
const names = valuesOf(every);
|
|
97
|
+
if (names.every(isWeekday)) facts.weekdays = names.map((name) => WEEKDAY_INDEX[name]);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
facts.wellFormed =
|
|
101
|
+
shape !== 'malformed' &&
|
|
102
|
+
(!date || (facts.dates !== undefined && facts.dates.length > 0)) &&
|
|
103
|
+
(!own.has('start') || facts.start !== undefined) &&
|
|
104
|
+
(!own.has('end') || facts.end !== undefined) &&
|
|
105
|
+
!(facts.start !== undefined && facts.end !== undefined && facts.end < facts.start) &&
|
|
106
|
+
(!every || (facts.weekdays !== undefined && facts.weekdays.length > 0));
|
|
107
|
+
return facts;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A preset weekend applies unless a `non-working` declaration is named `weekend`. */
|
|
111
|
+
export function replacesPresetWeekend(
|
|
112
|
+
declarations: ReadonlyArray<NonWorkingDeclaration | WorkingDeclaration>,
|
|
113
|
+
): boolean {
|
|
114
|
+
return declarations.some(
|
|
115
|
+
(decl) => decl.$type === 'NonWorkingDeclaration' && decl.name === 'weekend',
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Exactly one of: `date:` alone; `start:` + `end:`; `every:` with optional `start:` / `end:`. */
|
|
120
|
+
function shapeOf(own: ReadonlyMap<CalendarDeclarationKey, EntityProperty>): CalendarShape {
|
|
121
|
+
const hasStart = own.has('start');
|
|
122
|
+
const hasEnd = own.has('end');
|
|
123
|
+
if (own.has('date')) return own.has('every') || hasStart || hasEnd ? 'malformed' : 'dated';
|
|
124
|
+
if (own.has('every')) {
|
|
125
|
+
if (hasStart && hasEnd) return 'bounded-recurrence';
|
|
126
|
+
return hasStart || hasEnd ? 'half-bounded-recurrence' : 'open-recurrence';
|
|
127
|
+
}
|
|
128
|
+
return hasStart && hasEnd ? 'range' : 'malformed';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** A scalar as one value, or a bracket list. */
|
|
132
|
+
function valuesOf(prop: EntityProperty): string[] {
|
|
133
|
+
return prop.value !== undefined ? [prop.value] : [...prop.values];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The one real date a `start:` / `end:` names; a one-element bracket is that date. */
|
|
137
|
+
function singleDate(prop: EntityProperty | undefined): string | undefined {
|
|
138
|
+
if (!prop) return undefined;
|
|
139
|
+
const values = valuesOf(prop);
|
|
140
|
+
return values.length === 1 && isRealIsoDate(values[0]) ? values[0] : undefined;
|
|
141
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// References across includes (specs/dsl.md, Reference rule 1). A file's
|
|
2
|
+
// `after:`, `before:` and `on:` resolve against its own ids only, in every
|
|
3
|
+
// include mode, but an included file is parsed with `validation:false`, so
|
|
4
|
+
// the validator never sees it. The include resolver calls
|
|
5
|
+
// `checkIncludedReferences` once per root pipeline to report each included
|
|
6
|
+
// file's unresolved references in that file, as its own validation would.
|
|
7
|
+
|
|
8
|
+
import { tr } from '../i18n/index.js';
|
|
9
|
+
import type { ResolveDiagnostic } from './include-resolver.js';
|
|
10
|
+
import { hasParseErrors, nodeLocation, type WaveIncludeEdge } from './include-waves.js';
|
|
11
|
+
import { unresolvedReferences } from './references.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* NL.E0302 for every file reachable from the root through `merge` and
|
|
15
|
+
* `isolate` edges, each file once, at the reference's property in that file.
|
|
16
|
+
* A `roadmap:ignore` child's content is dropped, so it is not checked
|
|
17
|
+
* (unless another edge reaches it). A child that failed to parse is skipped:
|
|
18
|
+
* a partial AST would report references to ids the parser lost.
|
|
19
|
+
*/
|
|
20
|
+
export function checkIncludedReferences(
|
|
21
|
+
rootAbs: string,
|
|
22
|
+
edges: ReadonlyMap<string, readonly WaveIncludeEdge[]>,
|
|
23
|
+
): ResolveDiagnostic[] {
|
|
24
|
+
const out: ResolveDiagnostic[] = [];
|
|
25
|
+
const seen = new Set<string>([rootAbs]);
|
|
26
|
+
const walk = (abs: string): void => {
|
|
27
|
+
for (const edge of edges.get(abs) ?? []) {
|
|
28
|
+
if (edge.mode === 'ignore' || seen.has(edge.childAbs)) continue;
|
|
29
|
+
seen.add(edge.childAbs);
|
|
30
|
+
if (!hasParseErrors(edge.childFile)) {
|
|
31
|
+
for (const { prop, key, value } of unresolvedReferences(edge.childFile)) {
|
|
32
|
+
const args: [{ key: string; value: string }] = [{ key, value }];
|
|
33
|
+
out.push({
|
|
34
|
+
severity: 'error',
|
|
35
|
+
message: tr('en-US', 'NL.E0302', ...args),
|
|
36
|
+
sourcePath: edge.childAbs,
|
|
37
|
+
// The validator reports NL.E0302 on the whole property.
|
|
38
|
+
...nodeLocation(prop),
|
|
39
|
+
code: 'NL.E0302',
|
|
40
|
+
args,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
walk(edge.childAbs);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
walk(rootAbs);
|
|
48
|
+
return out;
|
|
49
|
+
}
|