dashbitco/nimble_parsec

Fail to create combinator of consecutive repeats

jackalcooper opened this issue · 2 comments

  • this fails to compile
defmodule Kinda.Parser do
  import NimbleParsec

  defcombinatorp(
    :container_doc_comment,
    string("//!") |> repeat(ascii_char([?\n])) |> repeat([?\s, ?\n]) |> times(min: 1)
  )
end

err msg:

== Compilation error in file lib/parser.ex ==
** (FunctionClauseError) no function clause matching in NimbleParsec.Compiler.compile_unbound_combinator/4    
    
    The following arguments were given to NimbleParsec.Compiler.compile_unbound_combinator/4:
    
        # 1
        10
    
        # 2
        :container_doc_comment__5
    
        # 3
        6
    
        # 4
        %{acc_depth: 0, catch_all: :container_doc_comment__4, labels: [], name: :container_doc_comment, replace: false}
    
    Attempted function clauses (showing 7 out of 7):
    
        defp compile_unbound_combinator({:parsec, parsec}, current, step, config)
        defp compile_unbound_combinator({:lookahead, combinators, kind}, current, step, config)
        defp compile_unbound_combinator({:traverse, combinators, kind, traversal}, current, step, config)
        defp compile_unbound_combinator({:times, combinators, count}, current, step, config)
        defp compile_unbound_combinator({:repeat, combinators, while, _gen}, current, step, config)
        defp compile_unbound_combinator({:eventually, combinators}, current, step, config)
        defp compile_unbound_combinator({:choice, choices, _} = combinator, current, step, config)
    
    (nimble_parsec 1.2.3) lib/nimble_parsec/compiler.ex:142: NimbleParsec.Compiler.compile_unbound_combinator/4
    (nimble_parsec 1.2.3) lib/nimble_parsec/compiler.ex:122: NimbleParsec.Compiler.compile/6
    (nimble_parsec 1.2.3) lib/nimble_parsec/compiler.ex:510: NimbleParsec.Compiler.compile_unbound_repeat/6
    (nimble_parsec 1.2.3) lib/nimble_parsec/compiler.ex:122: NimbleParsec.Compiler.compile/6
    (nimble_parsec 1.2.3) lib/nimble_parsec/compiler.ex:95: NimbleParsec.Compiler.compile/2
    (nimble_parsec 1.2.3) lib/nimble_parsec/compiler.ex:72: NimbleParsec.Compiler.compile/3
    lib/parser.ex:18: (module)
  • while this works
  defcombinatorp(
    :container_doc_comment,
    string("//!") |> repeat(ascii_char([?\n])) 
  )

I assume you meant:

string("//!") |> repeat(ascii_char([?\n])) |> repeat(ascii_char(?\s, ?\n)) |> times(min: 1)

But the error message could be better here.

I will push a new error message soon. :)