Skip to content

feat(parser): multi-line object/array literals with comments#794

Merged
theoephraim merged 5 commits into
mainfrom
multiline-array-object-literals
Jun 17, 2026
Merged

feat(parser): multi-line object/array literals with comments#794
theoephraim merged 5 commits into
mainfrom
multiline-array-object-literals

Conversation

@theoephraim

@theoephraim theoephraim commented Jun 16, 2026

Copy link
Copy Markdown
Member

Follow-up to the object/array literals work: literals can now span multiple lines, so long key lists (e.g. a big @import(..., pick=[...])) don't have to live on one line.

What changed

  • Multi-line literals in both contexts, mirroring how function-call args already work:
    • Inside decorators (which live in # comments), each continuation line is prefixed with #.
    • Literals nested in item-value function calls use plain newlines.
  • Comments inside multi-line literals and function calls# starts a comment to end-of-line, so individual entries can be commented out (# # OLD_KEY,) or annotated (# KEY, # note).
  • VSCode extension syntax highlighting updated to match — object/array literals (single- and multi-line) and these inline comments are now properly scoped (previously literals were highlighted as plain strings).
# @import(./.env.shared, pick=[
#   DATABASE_URL,
#   # REDIS_URL,        ← commented out, skipped
#   STRIPE_KEY, # primary payment key
# ])
DATABASE_URL=

Safety

Continuation across a newline still requires the leading # in decorator context, so a missing # can never silently swallow following config items — a malformed bracket falls back to a plain string and the lines below stay independent config items.

Implementation

  • Parser: split the literal grammar into value-context (_valWs) and decorator-context (_decWs) rule sets, matching the existing FunctionArgs / DecoratorFunctionArgs split, and taught both whitespace rules to skip # comments.
  • TextMate grammar: added bracket-literal rules (object/array, multi-line via begin/end, comment-aware) wired into every arg context; key-value-pair and the literal-scoped unquoted/numeric rules now terminate at }/] so closing brackets aren't swallowed.

Tests

  • Parser: multi-line arrays/objects, nesting, import pick=[...], comments/post-comments, trailing-comma handling, and the no-swallow safety property; plus an end-to-end @setValuesBulk pick=[...] test.
  • VSCode grammar: scope assertions in grammar.test.txt (CI-checked) for single- and multi-line literals + inline comments, plus a new .env.literals snapshot fixture.

Docs updated in env-spec/reference.

Object and array literals can now span multiple lines. In decorator
comments each continuation line is prefixed with `#` (mirroring multi-line
function calls); literals nested in item-value function calls use plain
newlines. Inside either form, `#` starts a comment to end-of-line, so
entries can be commented out or annotated.

Continuation across a newline still requires the leading `#` in decorator
context, so a missing `#` can never silently swallow following config items.
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

bumpy-frog

The changes in this PR will be included in the next version bump.

patch Patch releases

  • @env-spec/parser 0.4.0 → 0.4.1
  • env-spec-language 0.2.2 → 0.2.3
  • varlock 1.7.0 → 1.7.1

Bump files in this PR

Click here if you want to add another bump file to this PR


This comment is maintained by bumpy.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
varlock-website 155f5e7 Commit Preview URL

Branch Preview URL
Jun 16 2026, 11:50 PM

@pkg-pr-new

pkg-pr-new Bot commented Jun 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@env-spec/parser@794
npm i https://pkg.pr.new/varlock@794

commit: 368aa28

…ments

The TextMate grammar now recognizes object `{...}` and array `[...]`
literals (previously highlighted as plain strings), in both decorator and
item-value contexts, including multi-line forms. Inline `#` comments inside
multi-line literals and function calls (commented-out entries and trailing
notes) are now scoped as comments.
Adds item-value-context coverage (plain-newline continuation) for comments
inside multi-line literals and function calls — commented-out entries and
trailing post-comments — across arrays, objects, and fn-call args, matching
the existing decorator-context coverage.

Also tightens the TextMate grammar's literal continuation marker to a
column-0 `#` so indented item-value comment lines are scoped as full
comments instead of being split into a marker + unquoted string.
@theoephraim theoephraim merged commit eb288c5 into main Jun 17, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant