File: parsley_tree_transformer.parsley

package info (click to toggle)
python-parsley 1.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,048 kB
  • sloc: python: 9,897; makefile: 127
file content (36 lines) | stat: -rw-r--r-- 1,468 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
termPattern = indentation? name:name ?(name[0].isupper())
              '(' expr?:patts ')' -> t.TermPattern(name, patts)

subtransform = ws '@' name:n -> t.Bind(n, t.Apply('transform', self.rulename, []))

wide_templatedValue = ws '-->' ' '* wideTemplateBits:contents -> t.StringTemplate(contents)
tall_templatedValue = hspace? '{{{' (' ' | '\t')* vspace? tallTemplateBits:contents '}}}' -> t.StringTemplate(contents)

tallTemplateBits = (exprHole | tallTemplateText)*
tallTemplateText = <(~('}}}' | '$' | '\r' | '\n') anything | '$' '$')+ vspace*> | vspace

wideTemplateBits = (exprHole | wideTemplateText)*
wideTemplateText = <(~(vspace | end |'$') anything | '$' '$')+>

exprHole = '$' name:n -> t.QuasiExprHole(n)

expr1 = foreignApply
       |termPattern
       |subtransform
       |application
       |ruleValue
       |wide_templatedValue
       |tall_templatedValue
       |semanticPredicate
       |semanticAction
       |number:n !(self.isTree()) -> n
       |character
       |string
       |ws '(' expr?:e ws ')' -> e
       |ws '[' expr?:e ws ']' -> t.TermPattern(".tuple.", e or t.And([]))

grammar = rule*:rs ws -> t.Grammar(self.name, True, rs)
rule = noindentation ~~(name:n) (termRulePart(n)+:rs | rulePart(n)+:rs)  -> t.Rule(n, t.Or(rs))

termRulePart :requiredName =  noindentation !(setattr(self, "rulename", requiredName))
                             termPattern:tt ?(tt.args[0].data == requiredName) token("=")? expr:tail -> t.And([tt, tail])