Deno: TOML Parser cannot parse inline arrays of inline tables

Created on 20 Jun 2020  路  12Comments  路  Source: denoland/deno

In the TOML spec, there is an example of an inline-defined array of inline-defined tables at the end of the "Array of Tables" section:

You may also use inline tables where appropriate:

points = [ { x = 1, y = 2, z = 3 },
           { x = 7, y = 8, z = 9 },
           { x = 2, y = 4, z = 8 } ]

However this example cannot be parsed with the TOML parser in the stdlib:

import { parse } from "https://deno.land/std/encoding/toml.ts"

console.log(parse(`
points = [ { x = 1, y = 2, z = 3 },
  { x = 7, y = 8, z = 9 },
  { x = 2, y = 4, z = 8 } ]
`))
$ deno run test.ts 
Compile file:///workspaces/flags/test.ts
error: Uncaught SyntaxError: Unexpected token '='
    at Parser._parseData (https://deno.land/std/encoding/toml.ts:261:17)
    at Parser._processDeclaration (https://deno.land/std/encoding/toml.ts:190:24)
    at Parser._parseLines (https://deno.land/std/encoding/toml.ts:340:25)
    at Parser.parse (https://deno.land/std/encoding/toml.ts:389:10)
    at parse (https://deno.land/std/encoding/toml.ts:569:33)
    at file:///workspaces/flags/test.ts:3:13

This example works on other TOML parsers, such as this online one.

I am using Deno 1.1.1.

bug good first issue std

All 12 comments

Hi @mythmon , the current implementation of Deno std TOML parser is actually quite un-recursive, so you can expect to hit more errors especially with recursive values, such as a=[{x=[{y=2}]}]. That being said, a major revamp is probably unavoidable in order to fix this issue.

However if you are looking for a workaround, you can import this TOML parser from jsmp.io:

import toml from "https://dev.jspm.io/toml"
console.log(toml.parse(`
points = [ { x = 1, y = 2, z = 3 },
           { x = 7, y = 8, z = 9 },
           { x = 2, y = 4, z = 8 } ]
  `))

I'd be interested in taking a stab at this issue!

@rfaulhaber I'll recommend porting https://github.com/BinaryMuse/toml-node to deno/std instead of rewriting the same parser again.

Actually I had a question with regards to porting that library. The parser in that library is generated through PEG.js. Should the PEG setup should also be ported? i.e. have some kind of build step to generate the resulting parser from the grammar? Or should I look for another solution?

@rfaulhaber perhaps you can try rolling out a custom lexer and parser.

@wongjiahau I just might!

@rfaulhaber are you working on this?

Unfortunately no not so much, been busy.

Unfortunately no not so much, been busy.

Are you cool with me grabbing it?

Go for it!

Unfortunately no not so much, been busy.

Are you cool with me grabbing it?

@JayHelton are you actively working on this issue? If not, me and 2 other uni students have an assignment that require us to contribute to an open source project. We would gladly give it a go!

Unfortunately no not so much, been busy.

Are you cool with me grabbing it?

@JayHelton are you actively working on this issue? If not, me and 2 other uni students have an assignment that require us to contribute to an open source project. We would gladly give it a go!

You can grab it! I have not made anything substantial

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JosephAkayesi picture JosephAkayesi  路  3Comments

doutchnugget picture doutchnugget  路  3Comments

CruxCv picture CruxCv  路  3Comments

justjavac picture justjavac  路  3Comments

benjamingr picture benjamingr  路  3Comments