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

Simple zero-or-more (*) example fails #6

Open
malcolmsparks opened this issue Jul 4, 2012 · 4 comments
Open

Simple zero-or-more (*) example fails #6

malcolmsparks opened this issue Jul 4, 2012 · 4 comments

Comments

@malcolmsparks
Copy link

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.

@ckirkendall
Copy link

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.

@ska2342
Copy link

ska2342 commented Feb 14, 2013

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

@cgrand
Copy link
Owner

cgrand commented Feb 14, 2013

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//issues/6#issuecomment-13551119.

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

@ska2342
Copy link

ska2342 commented Feb 14, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants