Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOML Parser cannot parse inline arrays of inline tables #6394

Closed
mythmon opened this issue Jun 20, 2020 · 12 comments · Fixed by #7902
Closed

TOML Parser cannot parse inline arrays of inline tables #6394

mythmon opened this issue Jun 20, 2020 · 12 comments · Fixed by #7902
Labels
bug Something isn't working correctly good first issue Good for newcomers

Comments

@mythmon
Copy link

mythmon commented Jun 20, 2020

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.

@ry ry added bug Something isn't working correctly good first issue Good for newcomers std labels Jun 20, 2020
@wongjiahau
Copy link
Contributor

wongjiahau commented Jun 20, 2020

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 } ]
  `))

@rfaulhaber
Copy link

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

@wongjiahau
Copy link
Contributor

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

@rfaulhaber
Copy link

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?

@wongjiahau
Copy link
Contributor

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

@rfaulhaber
Copy link

@wongjiahau I just might!

@JayHelton
Copy link
Contributor

@rfaulhaber are you working on this?

@rfaulhaber
Copy link

Unfortunately no not so much, been busy.

@JayHelton
Copy link
Contributor

Unfortunately no not so much, been busy.

Are you cool with me grabbing it?

@rfaulhaber
Copy link

Go for it!

@DilanR
Copy link

DilanR commented Sep 4, 2020

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!

@JayHelton
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants