Jun-05-2022, 10:06 AM
(Jun-05-2022, 05:46 AM)Gribouillis Wrote:I called it not useful because there's no documentation on the syntax tree, which makes it hard to understand sometimes, and I wouldn't say its designed so that it's easy for to use outside of the re module. Having an object or classes over lists of tuples is just easier for working with the syntax tree, for example:(Jun-04-2022, 11:37 PM)DreamingInsanity Wrote: but it's not in a very useful format for doing other stuff with.Why is this not useful enough and what do you want to do with it? It looks like a regular syntax tree (by the way on my system it issre_parse.parse()
)
class SubPattern: pat: Any class Repetition: pat: Any greedy: bool class WordBoundary: pass # (\w+) becomes: SubPattern(Repetition(WordBoundary, True)) # instead of [(SUBPATTERN, (1, 0, 0, [(MAX_REPEAT, (1, MAXREPEAT, [(IN, [(CATEGORY, CATEGORY_WORD)])]))]))]
Gribouillis Wrote: what do you want to do with itI want to be able to generate a "priority" for a regex. For example
(abc)
has a higher priority than ([a-c]+)
as the former is more explicit and will only match abc
versus 1 or more of the a, b, or c
characters as the latter would match. And (a|bc)
would have a priority higher than ([a-c]+)
but lower than (abc)
, as its shortest match is a
which is shorter than abc
as the longer regex is prioritised more.