Skip to content

Flow-style mapping within a block sequence item fails to parse. #40

Open

Description

@KawaTurbo

Thanks for developing this useful parser!
I've encountered an issue where flow-style mappings, when nested as items within a block sequence, are not parsed successfully by tinyyaml.

To reproduce the issue, I used the following YAML data in a file (e.g., NG_example.yaml)

# NG Example (flow mapping in block sequence)
foo: 
- {a: 1, b: 2, c: 3}
- {d: 4, e: 5, f: 6}

Here is the Lua code I used for parsing:

local tinyyaml = require("tinyyaml")
local filepath = "/path/to/NG_example.yaml"
local inputfile = io.open(filepath, "r")
local str = inputfile:read("*a")
local filecontent = tinyyaml.parse(str)
inputfile:close()

I expected tinyyaml to successfully parse the YAML and generate a Lua table with the following structure:
{ foo = { {a = 1, b = 2, c = 3}, {d = 4, e = 5, f = 6} } }

However, it resulted in the following error:

C:\Lua\LuaJIT-build\luajit.exe: ...\AppData\Roaming\luarocks\share\lua\5.1\tinyyaml.lua:730: failed to classify line:   {a: 1, b: 2, c: 3}
stack traceback:
	[C]: in function 'error'
	...\AppData\Roaming\luarocks\share\lua\5.1\tinyyaml.lua:730: in function 'parsemap'
	...\AppData\Roaming\luarocks\share\lua\5.1\tinyyaml.lua:582: in function 'parseseq'
	...\AppData\Roaming\luarocks\share\lua\5.1\tinyyaml.lua:756: in function 'parsemap'
	...\AppData\Roaming\luarocks\share\lua\5.1\tinyyaml.lua:816: in function 'parsedocuments'
	...\AppData\Roaming\luarocks\share\lua\5.1\tinyyaml.lua:841: in function 'parse'
	c:\Lua\LuaJIT-build\works\test.lua:5: in main chunk
	[C]: at 0x00253200

Additional Information

The following YAML, which uses a flow sequence, is parsed successfully:

# OK Example (flow mapping in flow sequence)
foo: [
  {a: 1, b: 2, c: 3}, 
  {d: 4, e: 5, f: 6}]

Environment

  • OS: Windows 11
  • Lua version: LuaJIT 2.1
  • Tinyyaml version: api7-lua-tinyyaml 0.4.4-0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions