Process text like never before.
Parse.py is Python module that will let you process strings and generate structured output.
word(chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
- Will match a word that contains these characters.liter(lit)
- Will match a piece of input that exactly match argument, doesn't require whitespaces around.key(k)
- Will match a piece of input that exactly match argument, require whitespaces around.And(first, second)
- Will match two elements one-after-another.Or(first, second)
- Will match one or two elements one-after-another.Xor(first, second)
- Will match the longest element.$1 + $2
- Will createAnd($1, $2)
object.$1 | $2
- Will createOr($1, $2)
object.$1 ^ $2
- Will createXor($1, $2)
object.optional(value)
- Will match the given sequence if can, else it not.group(value)
- Will match the given sequence and round it to tuple.count(cnt)
- Will create callable count object.count.more(value)
- Will match the given count and more of elements.count.less(value)
- Will match count from one to the given count of elements.count.upTo(max, value)
- Will match count between the given count and themax
imal count of given elements.name(nam, value)
- Will match thevalue
as value indict
and thenam
as the key.recurse()
- Will add object ID to database, then add code registered with ID and then run the code using its ID.$1 << $2
- Will add value torecurse
object.
Plus upcoming objects:
combine(value)
- Will"".join(...)
the output of itsvalue
.
setIgnored(val)
- Set ignored characters.DOC_END
- Just EOF.
- The
<<
operator precedence. - I made one too. If you writerule << word() + word() | liter("!")
it will take just the firstword()
. Writerule << (word() + word() | liter("!"))
instead. (Assumning thatrule = recurse()
) - Overstacking Python - I made one too. If you write
rule << (word() + liter("=") + word() | rule + key("and") + rule)
it will infinitely match the second branch (rule + key("and") + rule
), because therule
is matching, because therule
is matching, because therule
is matching, because therule
is matching, ... Writerule << (word() + liter("=") + word() + optional(key("and") + rule))
instead. (Assumning thatrule = recurse()
)