parsley icon indicating copy to clipboard operation
parsley copied to clipboard

Simple zero-or-more (*) example fails

Open malcolmsparks opened this issue 12 years ago • 4 comments

I'm not sure why this works :-

((parser
   {:main :name}
   :nameStartChar #"[\w]"
   :nameChar #"[\w]*"
   :name [:nameStartChar :nameChar]
   )
 "foo")

returning

#net.cgrand.parsley.Node{:tag :net.cgrand.parsley/root, :content [#net.cgrand.parsley.Node{:tag :name, :content [#net.cgrand.parsley.Node{:tag :nameStartChar, :content ["f"]} #net.cgrand.parsley.Node{:tag :nameChar, :content ["oo"]}]}]}

whereas this produces an error :-

((parser
   {:main :name}
   :nameStartChar #"[\w]"
   :nameChar #"[\w]"
   :name [:nameStartChar :nameChar*]
   )
 "foo")

at state #{[:name_repeat+_4476 1 [:nameChar]] [:name 1 nil] [:nameChar 1 [#"[\w]"]] [:name_repeat+_4476 2 (:name_repeat+_4476 :nameChar)] [:name 2 (:name_repeat+_4476)]}
 shift/reduce conflict {#"[\w]" #{[:nameChar 1 nil]}}
#{[:name 1 nil]}
  [Thrown class java.lang.Exception]

Backtrace:
  0:      lrplus.clj:220 net.cgrand.parsley.lrplus/transitions

Is this a bug? If not, would you be able to explain why I'm getting this error?

btw. Thanks for parsley and regex, they are wonderful.

malcolmsparks avatar Jul 04 '12 09:07 malcolmsparks

I am also running into this same issue. It looks like in paraedit, Laurent, had an eof function to give the parse tree an ending node to match. However, it looks like you made lr+ throw a run time exception when you add you own matcher function.

ckirkendall avatar Jul 05 '12 03:07 ckirkendall

I would love to understand this, too. An even smaller example:

Fails: ((p/parser :thing [:name*] :name #"[a-z]" ) "foo")

Works: ((p/parser :thing [:name] :name #"[a-z]*" ) "foo")

Regards, Stefan

ska2342 avatar Feb 14 '13 14:02 ska2342

Ok it's #1 on my todo list for parsley but since is a sizeable update...

Parsley is slightly more expressive than LR(0) but it is not LR(1) so many common cases such as repetitions can't be handled without end delimiters (the end delimiter explicitly marking the end of the separated repetition). "Historically," parsley has been built to prove this incremental parsing approach and act as a parser for CCW and LR(0) is enough for a lisp (where every repetition has an end delimiter (the top-level repetition being ended by EOF.

On Thu, Feb 14, 2013 at 3:19 PM, Stefan Kamphausen <[email protected]

wrote:

I would love to understand this, too. An even smaller example:

Fails: ((p/parser :thing [:name*] :name #"[a-z]" ) "foo")

Works: ((p/parser :thing [:name] :name #"[a-z]*" ) "foo")

Regards, Stefan

— Reply to this email directly or view it on GitHubhttps://github.com/cgrand/parsley/issues/6#issuecomment-13551119.

On Clojure http://clj-me.cgrand.net/ Clojure Programming http://clojurebook.com Training, Consulting & Contracting http://lambdanext.eu/

cgrand avatar Feb 14 '13 14:02 cgrand

Salut,

no need to hurry, I am just exploring ways how to parse a rather complicated format. Seems like Parsley won't fit. No problem. Thanks for taking the time to answer anyway.

Best, Stefan

ska2342 avatar Feb 14 '13 20:02 ska2342