@knowvah/dot-engine 2.6.5 → 2.6.6

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.
@@ -10,19 +10,29 @@
10
10
 
11
11
  // ── Top-level rule ───────────────────────────────────────────────────────────
12
12
  // grammar.y: graph : hdr body | error | /* empty */
13
+ // `end` is the offset just past the graph's closing brace: the last input the
14
+ // C scanner lexes (see GraphEof). The empty graph lexes everything.
13
15
 
14
16
  Graph
15
- = _ s:OptStrict _ t:GraphType _ id:OptGraphName _ "{" _ stmts:StmtList _ "}" _
17
+ = _ s:OptStrict _ t:GraphType _ id:OptGraphName _ "{" _ stmts:StmtList _ "}" end:GraphEof
16
18
  {
17
19
  return {
18
20
  type: "graph",
19
21
  strict: s,
20
22
  directed: t,
21
23
  id: id,
22
- stmts: stmts
24
+ stmts: stmts,
25
+ end: end
23
26
  };
24
27
  }
25
- / _ "" { return { type: "graph", strict: false, directed: false, id: null, stmts: [] }; }
28
+ / _ "" { return { type: "graph", strict: false, directed: false, id: null, stmts: [], end: text().length }; }
29
+
30
+ // grammar.y: graph : hdr body {freestack(); endgraph();} — endgraph calls
31
+ // scan.l:aglexeof, which unputs GRAPH_EOF_TOKEN ('@'), so the next token is
32
+ // EOF and nothing after the closing brace is ever lexed: agmemread reads one
33
+ // graph and ignores the rest, junk or a second graph alike.
34
+ GraphEof
35
+ = .* { return offset(); }
26
36
 
27
37
  // grammar.y: hdr : optstrict graphtype optgraphname
28
38
  // grammar.y: optstrict : T_strict | /* empty */
@@ -272,8 +272,11 @@ export function parse(src: string): Graph {
272
272
  }
273
273
  throw err;
274
274
  }
275
+ // Only the graph's own text was lexed; what follows its closing brace is
276
+ // never read (grammar.y:endgraph -> scan.l:aglexeof).
277
+ const lexed = src.slice(0, ast.end);
275
278
  try {
276
- validateEdgeOperators(src, ast.directed);
279
+ validateEdgeOperators(lexed, ast.directed);
277
280
  } catch (err: unknown) {
278
281
  // C's lexer hands the wrong operator to bison as '-': a syntax error there.
279
282
  const offset = err instanceof ParseError ? err.location.offset : undefined;
@@ -283,7 +286,7 @@ export function parse(src: string): Graph {
283
286
  }
284
287
  throw err;
285
288
  }
286
- warnNumberAmbiguities(src, src.length);
289
+ warnNumberAmbiguities(lexed, lexed.length);
287
290
  return buildFromAst(ast);
288
291
  }
289
292