#8 Found issue with example that may point to the cause of the problems I've been having

Open
opened 6 months ago by Jason · 1 comments
Jason commented 6 months ago
Collaborator

Consider example 2.2.3 from the docs https://fdik.org/pyPEG2/grammar_elements.html#list

Works

import pypeg2 as pp

class Instruction(str): pass

class Block(pp.List):
    grammar = "{", pp.maybe_some(Instruction), "}"

    def __repr__(self):
        return " ".join(self)
        
b = pp.parse(r"{ hello world }", Block)
print(b)

prints "hello world"

Does not work, raises SyntaxError

import pypeg2 as pp

class Instruction(str): pass

class Block(pp.List):
    grammar = "{", pp.maybe_some(Instruction), "}"

    def __repr__(self):
        return " ".join(self)
        
b = pp.parse(r"{ $hello world }", Block)
print(b)

The only difference being the dollar in "$hello world"
It appears all symbol characters are not considered str

Consider example 2.2.3 from the docs https://fdik.org/pyPEG2/grammar_elements.html#list Works ```Python import pypeg2 as pp class Instruction(str): pass class Block(pp.List): grammar = "{", pp.maybe_some(Instruction), "}" def __repr__(self): return " ".join(self) b = pp.parse(r"{ hello world }", Block) print(b) ``` prints "hello world" Does not work, raises SyntaxError ```Python import pypeg2 as pp class Instruction(str): pass class Block(pp.List): grammar = "{", pp.maybe_some(Instruction), "}" def __repr__(self): return " ".join(self) b = pp.parse(r"{ $hello world }", Block) print(b) ``` The only difference being the dollar in "$hello world" It appears all symbol characters are not considered str
Jason commented 6 months ago
Poster
Collaborator

Ahh the definition of word is regex \w which disallows any non (0-9|A-Z|a-z) it needs to be more like ([`#$])?([\w.])+

Which would allow tick, hash or dollar to preceed words and class.member to be possible.

This should be mentioned in the online docs.

Ahh the definition of word is regex \w which disallows any non (0-9|A-Z|a-z) it needs to be more like ([`#$])?([\w\.])+ Which would allow tick, hash or dollar to preceed words and class.member to be possible. This should be mentioned in the online docs.
Sign in to join this conversation.
No Label
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.