How to use compile_node method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

patcomp.py

Source:patcomp.py Github

copy

Full Screen

...43 root = self.driver.parse_tokens(tokens, debug=debug)44 except parse.ParseError as e:45 raise PatternSyntaxError(str(e)) from None46 if with_tree:47 return self.compile_node(root), root48 else:49 return self.compile_node(root)50 def compile_node(self, node):51 """Compiles a node, recursively.52 This is one big switch on the node type.53 """54 # XXX Optimize certain Wildcard-containing-Wildcard patterns55 # that can be merged56 if node.type == self.syms.Matcher:57 node = node.children[0] # Avoid unneeded recursion58 if node.type == self.syms.Alternatives:59 # Skip the odd children since they are just '|' tokens60 alts = [self.compile_node(ch) for ch in node.children[::2]]61 if len(alts) == 1:62 return alts[0]63 p = pytree.WildcardPattern([[a] for a in alts], min=1, max=1)64 return p.optimize()65 if node.type == self.syms.Alternative:66 units = [self.compile_node(ch) for ch in node.children]67 if len(units) == 1:68 return units[0]69 p = pytree.WildcardPattern([units], min=1, max=1)70 return p.optimize()71 if node.type == self.syms.NegatedUnit:72 pattern = self.compile_basic(node.children[1:])73 p = pytree.NegatedPattern(pattern)74 return p.optimize()75 assert node.type == self.syms.Unit76 name = None77 nodes = node.children78 if len(nodes) >= 3 and nodes[1].type == token.EQUAL:79 name = nodes[0].value80 nodes = nodes[2:]81 repeat = None82 if len(nodes) >= 2 and nodes[-1].type == self.syms.Repeater:83 repeat = nodes[-1]84 nodes = nodes[:-1]85 # Now we've reduced it to: STRING | NAME [Details] | (...) | [...]86 pattern = self.compile_basic(nodes, repeat)87 if repeat is not None:88 assert repeat.type == self.syms.Repeater89 children = repeat.children90 child = children[0]91 if child.type == token.STAR:92 min = 093 max = pytree.HUGE94 elif child.type == token.PLUS:95 min = 196 max = pytree.HUGE97 elif child.type == token.LBRACE:98 assert children[-1].type == token.RBRACE99 assert len(children) in (3, 5)100 min = max = self.get_int(children[1])101 if len(children) == 5:102 max = self.get_int(children[3])103 else:104 assert False105 if min != 1 or max != 1:106 pattern = pattern.optimize()107 pattern = pytree.WildcardPattern([[pattern]], min=min, max=max)108 if name is not None:109 pattern.name = name110 return pattern.optimize()111 def compile_basic(self, nodes, repeat=None):112 # Compile STRING | NAME [Details] | (...) | [...]113 assert len(nodes) >= 1114 node = nodes[0]115 if node.type == token.STRING:116 value = str(literals.evalString(node.value))117 return pytree.LeafPattern(_type_of_literal(value), value)118 elif node.type == token.NAME:119 value = node.value120 if value.isupper():121 if value not in TOKEN_MAP:122 raise PatternSyntaxError("Invalid token: %r" % value)123 if nodes[1:]:124 raise PatternSyntaxError("Can't have details for token")125 return pytree.LeafPattern(TOKEN_MAP[value])126 else:127 if value == "any":128 type = None129 elif not value.startswith("_"):130 type = getattr(self.pysyms, value, None)131 if type is None:132 raise PatternSyntaxError("Invalid symbol: %r" % value)133 if nodes[1:]: # Details present134 content = [self.compile_node(nodes[1].children[1])]135 else:136 content = None137 return pytree.NodePattern(type, content)138 elif node.value == "(":139 return self.compile_node(nodes[1])140 elif node.value == "[":141 assert repeat is None142 subpattern = self.compile_node(nodes[1])143 return pytree.WildcardPattern([[subpattern]], min=0, max=1)144 assert False, node145 def get_int(self, node):146 assert node.type == token.NUMBER147 return int(node.value)148# Map named tokens to the type value for a LeafPattern149TOKEN_MAP = {"NAME": token.NAME,150 "STRING": token.STRING,151 "NUMBER": token.NUMBER,152 "TOKEN": None}153def _type_of_literal(value):154 if value[0].isalpha():155 return token.NAME156 elif value in grammar.opmap:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run dbt-osmosis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful