Python Forum
Recursive evaluation in parsley parser
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursive evaluation in parsley parser
#1
Hi! I have been fiddling around with parsley and it seems to be a great tool. I just don't get recursive evaluation to work.

Example:

grammar = parsley.makeGrammar("""
number = digit:n -> 'Number' + n
char = letter:l -> 'Letter' + l
sequence = <(number | letter)*>
""", {})
print(grammar("R").char())
print(grammar("2").number())
print(grammar("R2D2").sequence())
The output is:

Number2
LetterR
R2D2
The first two things are cool but I want to have

LetterRNumber2LetterDNumber2

as output for the third line. What am I doing wrong?
Any help appreciated!

OK I found it. <> ignores the inner rules.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  UndefinedEnvironmentName: 'extra' does not exist in evaluation environment EarthAndMoon 3 1,621 Oct-09-2023, 05:38 PM
Last Post: snippsat
  Conditional evaluation stsxbel 7 3,420 Jun-13-2021, 08:27 PM
Last Post: Gribouillis
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 7,195 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  Evaluation of two different list in python? go127a 8 3,547 Apr-22-2019, 12:49 PM
Last Post: snippsat
  list evaluation go127a 2 2,431 Apr-12-2019, 11:13 AM
Last Post: DeaD_EyE
  operand evaluation order? insearchofanswers87 2 2,791 Sep-26-2018, 07:51 PM
Last Post: insearchofanswers87
  Learning Python, newbie question about strings and evaluation new_learner_999 13 5,861 Feb-18-2018, 03:01 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020