Skip to content

feat: add toml-ast — TypeScript TOML parser and deparser#92

Merged
pyramation merged 1 commit into
mainfrom
feat/toml-ast
Jun 28, 2026
Merged

feat: add toml-ast — TypeScript TOML parser and deparser#92
pyramation merged 1 commit into
mainfrom
feat/toml-ast

Conversation

@pyramation

Copy link
Copy Markdown
Contributor

Summary

New toml-ast package — parse TOML config files into a typed AST and deparse back to TOML strings. Follows the same architecture as nginx-ast, bash-ast, and docker-parser.

Architecture: LexerParser → typed AST → Deparser

import { parse, deparse, cleanTree } from 'toml-ast';

// Parse
const ast = parse(`[server]\nhost = "localhost"\nport = 8080`);

// Build programmatically
const doc: TomlDocument = {
  type: 'TomlDocument',
  body: [{ type: 'Table', key: ..., body: [...] }],
};

// Deparse
const toml = deparse(doc);

// Round-trip compare
expect(cleanTree(parse(toml))).toEqual(cleanTree(ast));

AST node types: TomlDocument, Table, ArrayOfTables, KeyValue, Key/KeyPart (bare/basic/literal styles), StringValue (basic/literal/multiline), IntegerValue (decimal/hex/octal/binary), FloatValue (incl. inf/nan), BooleanValue, DateTimeValue (offset/local-datetime/date/time), ArrayValue, InlineTable, Comment.

Lexer handles: [[/]] disambiguation (array-of-tables headers vs nested arrays), all TOML string types, escape sequences (\n, \uXXXX, \UXXXXXXXX, line-ending backslash), underscored numbers, datetime patterns.

Utilities: cleanTree (strip ranges for comparison), astEqual, printAst.

60 tests (parser, deparser, round-trip) all passing. Use case: programmatic generation of Traefik TOML configs for SSL/Let's Encrypt setups.

Link to Devin session: https://app.devin.ai/sessions/8bc9f253cf9845ef8053f22f92a1b4d8
Requested by: @pyramation

@pyramation pyramation self-assigned this Jun 28, 2026
@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@pyramation pyramation merged commit 18346e9 into main Jun 28, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant