Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .changeset/array-scope-fix.md

This file was deleted.

14 changes: 0 additions & 14 deletions .changeset/ast-driven-formatter.md

This file was deleted.

10 changes: 0 additions & 10 deletions .changeset/builtin-position-check.md

This file was deleted.

9 changes: 0 additions & 9 deletions .changeset/compile-error-type.md

This file was deleted.

11 changes: 0 additions & 11 deletions .changeset/declaration-discriminated-union.md

This file was deleted.

8 changes: 0 additions & 8 deletions .changeset/drop-deep-compare-dep.md

This file was deleted.

9 changes: 0 additions & 9 deletions .changeset/explicit-commonjs-type.md

This file was deleted.

13 changes: 0 additions & 13 deletions .changeset/formatter-spacing-fix.md

This file was deleted.

10 changes: 0 additions & 10 deletions .changeset/parser-statement-locations.md

This file was deleted.

16 changes: 0 additions & 16 deletions .changeset/token-source-positions.md

This file was deleted.

49 changes: 49 additions & 0 deletions packages/code-formatter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# pascal-code-formatter

## 0.1.0

### Minor Changes

- 00944ab: Add `formatPascalSource(code, options?)`: an AST-driven formatter that parses the
source and pretty-prints the parser's AST into clean, consistently indented Pascal
text (a string). Because structure comes from the AST rather than string-matching the
token stream, classification is exact and parentheses are precedence-aware (`a + b * c`,
not `(a + (b * c))`). Verified to round-trip (output re-parses), be idempotent, and
preserve semantics (the formatted source compiles to identical JS) across the golden
fixtures. Also exports `AstFormatter` and the `AstFormatOptions` type.

The existing token-stream `formatPascalCode` is unchanged. This adds a dependency on
`pascal-parser`.

### Patch Changes

- 3035567: Drop the `objects-deep-compare` dependency and simplify the indentation tracker. The
begin/end/var nesting is now an explicit local marker stack instead of a general-purpose
counterweight structure plus per-token deep-equality — clearer, testable without an
external dependency, and one fewer package to install. Output is unchanged.
- f5e4ec8: Fix `formatPascalCode` producing output that its own parser would reject. `needWhiteSpace`
had an ad-hoc allow-list with no rule to separate two adjacent word tokens, so control
keywords glued to their neighbours (`for`+`i`, `to`+`5`, `do`+`writeln`, `then`+the body).
Spacing is now driven by a general rule — a space between any two word-like tokens
(keyword/identifier/number/boolean/string, which also covers the `div`/`mod`/`and`/`or`/`not`
word operators) plus a leading space before control keywords after `)`/`]`. Trailing
whitespace is no longer emitted on a token that ends its line. Added a round-trip test
harness that renders the formatted lines and re-parses them, covering for/while/if-then/case
bodies on the same line as their header.
- 1965329: Track source positions through the toolchain.

- **pascal-tokenizer**: every emitted token now carries `line` (1-based), `column`
(1-based) and `offset` (0-based) marking where it starts in the source. Positions
are computed with a forward-only cursor, so tokenizing stays O(n).
- **pascal-parser**: `ParseError` now reports where the input went wrong — its
message is suffixed with `at line L, column C` and its `location` points at the
offending token, instead of a bare, position-less message.
- **pascal-code-formatter**: tolerates the new token fields (indentation matching now
compares tokens by structural identity, not deep object equality).

- Updated dependencies [14fe8d3]
- Updated dependencies [a3f86d6]
- Updated dependencies [d8861ac]
- Updated dependencies [1965329]
- pascal-parser@0.3.0
- pascal-tokenizer@0.1.0
6 changes: 3 additions & 3 deletions packages/code-formatter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pascal-code-formatter",
"version": "0.0.4",
"version": "0.1.0",
"description": "A Pascal code formatter written in TypeScript",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -46,8 +46,8 @@
},
"dependencies": {
"counterweight-stack": "0.0.1",
"pascal-parser": "^0.2.1",
"pascal-tokenizer": "^0.0.3"
"pascal-parser": "^0.3.0",
"pascal-tokenizer": "^0.1.0"
},
"directories": {
"doc": "docs",
Expand Down
33 changes: 33 additions & 0 deletions packages/compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# pascal-js-compiler

## 0.4.0

### Minor Changes

- c043a37: Export a typed `CompileError`. Unsupported-Pascal errors — `var` (by-reference)
parameters, bitwise `and`/`or`/`not` over integers, and wrong-arity builtin calls —
now throw `CompileError` instead of a bare `Error`, so a consumer can `catch` and tell
"this program uses an unsupported feature" apart from an internal compiler bug (which
stays a plain `Error`). Mirrors `ParseError` in `pascal-parser`.

### Patch Changes

- 9020b19: Fix silent codegen corruption when two arrays in different scopes share a name. Array
low-bounds were tracked in a single flat map keyed only by name, so a local `array[1..n]`
inside a subprogram overwrote the low-bound of a same-named outer array, making the outer
array's 1-based index offset wrong (writes/reads landed outside the allocated array). Array
scope is now snapshotted and restored around each subprogram body, so a homonym array in one
scope no longer changes the meaning of the same identifier in a sibling or outer scope.
- 7855f89: Reject builtins used in the wrong position with a `CompileError` instead of emitting a
call to a nonexistent JS function. A value-returning builtin used as a statement
(`abs(x);`) and a statement-only builtin used in an expression (`x := writeln(1)`) used to
compile to `abs(x);` / `writeln(1)`, which throw `ReferenceError` at runtime. They now fail
at compile time, consistent with how the compiler already rejects `var` parameters and
wrong arity. A user subprogram sharing a builtin's name still shadows it in either position.
- a3f86d6: Declare `"type": "commonjs"` explicitly in package.json. The packages already ship
CommonJS; stating it removes Node's module-type detection step for consumers (as flagged
by publint) and brings these three in line with `pascal-code-formatter`.
- Updated dependencies [14fe8d3]
- Updated dependencies [a3f86d6]
- Updated dependencies [d8861ac]
- Updated dependencies [1965329]
- pascal-parser@0.3.0

## 0.3.0

### Minor Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pascal-js-compiler",
"version": "0.3.0",
"version": "0.4.0",
"description": "Compiles Pascal source code to JavaScript from the pascal-toolchain parser AST.",
"type": "commonjs",
"main": "dist/index.js",
Expand Down Expand Up @@ -42,7 +42,7 @@
"author": "Damian Sire",
"license": "MIT",
"dependencies": {
"pascal-parser": "^0.2.0"
"pascal-parser": "^0.3.0"
},
"devDependencies": {
"typescript": "^5.6.3"
Expand Down
37 changes: 37 additions & 0 deletions packages/parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# pascal-parser

## 0.3.0

### Minor Changes

- 14fe8d3: `Declaration` is now a discriminated union (`VariableDeclaration | FunctionDeclaration
| ProcedureDeclaration | ConstantDeclaration`) instead of one wide interface where every
field was optional. Each variant is exported and carries exactly the fields it has, so a
`switch (decl.type)` narrows to the concrete node with no cast — matching how `Statement`
and `Expression` already work. Consumers that switch on `decl.type` gain precise field
types; code that read fields like `decl.parameters` off a bare `Declaration` without
narrowing must now narrow first.
- d8861ac: Statement AST nodes now carry their real source location (`location.start` = the
line/column/offset of their first token), stamped in `parseStatement`. Previously
every node location was zeroed. This enables consumers to map a statement back to
its source line — the playground step-debugger being the first such consumer.
Expression and declaration nodes remain zeroed until they too have a position
consumer.
- 1965329: Track source positions through the toolchain.

- **pascal-tokenizer**: every emitted token now carries `line` (1-based), `column`
(1-based) and `offset` (0-based) marking where it starts in the source. Positions
are computed with a forward-only cursor, so tokenizing stays O(n).
- **pascal-parser**: `ParseError` now reports where the input went wrong — its
message is suffixed with `at line L, column C` and its `location` points at the
offending token, instead of a bare, position-less message.
- **pascal-code-formatter**: tolerates the new token fields (indentation matching now
compares tokens by structural identity, not deep object equality).

### Patch Changes

- a3f86d6: Declare `"type": "commonjs"` explicitly in package.json. The packages already ship
CommonJS; stating it removes Node's module-type detection step for consumers (as flagged
by publint) and brings these three in line with `pascal-code-formatter`.
- Updated dependencies [a3f86d6]
- Updated dependencies [1965329]
- pascal-tokenizer@0.1.0

## 0.2.1

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pascal-parser",
"version": "0.2.1",
"version": "0.3.0",
"description": "A Pascal language parser library",
"type": "commonjs",
"main": "dist/index.js",
Expand Down Expand Up @@ -58,6 +58,6 @@
"typescript": "^5.3.3"
},
"dependencies": {
"pascal-tokenizer": "^0.0.3"
"pascal-tokenizer": "^0.1.0"
}
}
22 changes: 22 additions & 0 deletions packages/tokenizer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# pascal-tokenizer

## 0.1.0

### Minor Changes

- 1965329: Track source positions through the toolchain.

- **pascal-tokenizer**: every emitted token now carries `line` (1-based), `column`
(1-based) and `offset` (0-based) marking where it starts in the source. Positions
are computed with a forward-only cursor, so tokenizing stays O(n).
- **pascal-parser**: `ParseError` now reports where the input went wrong — its
message is suffixed with `at line L, column C` and its `location` points at the
offending token, instead of a bare, position-less message.
- **pascal-code-formatter**: tolerates the new token fields (indentation matching now
compares tokens by structural identity, not deep object equality).

### Patch Changes

- a3f86d6: Declare `"type": "commonjs"` explicitly in package.json. The packages already ship
CommonJS; stating it removes Node's module-type detection step for consumers (as flagged
by publint) and brings these three in line with `pascal-code-formatter`.
2 changes: 1 addition & 1 deletion packages/tokenizer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pascal-tokenizer",
"version": "0.0.3",
"version": "0.1.0",
"description": "A tokenizer for Pascal programming language",
"type": "commonjs",
"main": "dist/index.js",
Expand Down