from parsimonious.grammar import Grammar
grammar = Grammar(
"""
tplcall = tplopen tpltext (tplinner)+ tplclose
tplinner = named / positional
named = bar tpltext eq tpltext
positional = bar tpltext
tpltext = ("{{=}}" / ~r"[^\}\|=]")*
tplchar = ~r"[^\}\|=]"
tplopen = "{{"
tplclose = "}}"
eq = "="
bar = "|"
"""
)
test1 = "{{tpl|foo|bar=baz||fooish{{=}}bar}}"
print(grammar.parse(test1))
<Node called "tplcall" matching "{{tpl|foo|bar=baz||fooish{{=}}bar}}">
    <Node called "tplopen" matching "{{">
    <Node called "tpltext" matching "tpl">
        <Node matching "t">
            <RegexNode matching "t">
        <Node matching "p">
            <RegexNode matching "p">
        <Node matching "l">
            <RegexNode matching "l">
    <Node matching "|foo|bar=baz||fooish{{=}}bar">
        <Node called "tplinner" matching "|foo">
            <Node called "positional" matching "|foo">
                <Node called "bar" matching "|">
                <Node called "tpltext" matching "foo">
                    <Node matching "f">
                        <RegexNode matching "f">
                    <Node matching "o">
                        <RegexNode matching "o">
                    <Node matching "o">
                        <RegexNode matching "o">
        <Node called "tplinner" matching "|bar=baz">
            <Node called "named" matching "|bar=baz">
                <Node called "bar" matching "|">
                <Node called "tpltext" matching "bar">
                    <Node matching "b">
                        <RegexNode matching "b">
                    <Node matching "a">
                        <RegexNode matching "a">
                    <Node matching "r">
                        <RegexNode matching "r">
                <Node called "eq" matching "=">
                <Node called "tpltext" matching "baz">
                    <Node matching "b">
                        <RegexNode matching "b">
                    <Node matching "a">
                        <RegexNode matching "a">
                    <Node matching "z">
                        <RegexNode matching "z">
        <Node called "tplinner" matching "|">
            <Node called "positional" matching "|">
                <Node called "bar" matching "|">
                <Node called "tpltext" matching "">
        <Node called "tplinner" matching "|fooish{{=}}bar">
            <Node called "positional" matching "|fooish{{=}}bar">
                <Node called "bar" matching "|">
                <Node called "tpltext" matching "fooish{{=}}bar">
                    <Node matching "f">
                        <RegexNode matching "f">
                    <Node matching "o">
                        <RegexNode matching "o">
                    <Node matching "o">
                        <RegexNode matching "o">
                    <Node matching "i">
                        <RegexNode matching "i">
                    <Node matching "s">
                        <RegexNode matching "s">
                    <Node matching "h">
                        <RegexNode matching "h">
                    <Node matching "{{=}}">
                        <Node matching "{{=}}">
                    <Node matching "b">
                        <RegexNode matching "b">
                    <Node matching "a">
                        <RegexNode matching "a">
                    <Node matching "r">
                        <RegexNode matching "r">
    <Node called "tplclose" matching "}}">