kschiess / parslet

A small PEG based parser library. See the Hacking page in the Wiki as well.
kschiess.github.com/parslet
MIT License
805 stars 95 forks source link

`.repeat(1, 1).repeat(1, 1)` doesn't nest arrays #221

Open dorianmariecom opened 2 years ago

dorianmariecom commented 2 years ago
require "parslet"

class Parser < Parslet::Parser
  rule(:a) do
    str("a").as(:a).repeat(1, 1).repeat(1, 1)
  end
  root(:a)
end

p Parser.new.parse("a")

Actual:

[{:a=>"a"@0}]

Expected:

[[{:a=>"a"@0}]]
kschiess commented 1 year ago

While I agree that formally it should, I believe there is quite some code to ensure it does not; this simplifies output structures at the cost of formal correctness, a design choice made early on to cater to the pedagogical character this library has.

I might be open to accepting a PR that would change 'mode' into 'formal output' mode - but that's quite an undertaking; one would have to define formal output in the first place. Up for it?