Esempio n. 1
0
 def nt_def(self, nt_type, lhs, eq, rhs_list):
     has_sole_production = (len(rhs_list) == 1)
     production_list = []
     for i, rhs in enumerate(rhs_list):
         reducer_was_autogenerated = rhs[1] is None
         p = self.to_production(lhs, i, rhs, has_sole_production)
         if self.needs_asi(lhs, p):
             production_list += self.apply_asi(p, reducer_was_autogenerated)
         else:
             production_list.append(p)
     name, args = lhs
     return (name, eq, grammar.NtDef(args, production_list, nt_type))
Esempio n. 2
0
 def make_nt_def(self, lhs, eq, rhs_list):
     has_sole_production = (len(rhs_list) == 1)
     production_list = []
     for i, rhs in enumerate(rhs_list):
         p = self.to_production(lhs, i, rhs, has_sole_production)
         if self.needs_asi(p):
             production_list += self.apply_asi(p)
         else:
             production_list.append(p)
     if isinstance(lhs, tuple):
         name, args = lhs
         return (name, eq, grammar.NtDef(args, production_list))
     else:
         return (lhs, eq, production_list)
Esempio n. 3
0
 def nt_def(self, nt_type, lhs, eq, rhs_list):
     has_sole_production = (len(rhs_list) == 1)
     production_list = []
     for i, rhs in enumerate(rhs_list):
         if eq == ':':
             # Syntactic grammar. A hack is needed for ASI.
             reducer_was_autogenerated = rhs[1] is None
             p = self.to_production(lhs, i, rhs, has_sole_production)
             if self.needs_asi(lhs, p):
                 production_list += self.apply_asi(p, reducer_was_autogenerated)
             else:
                 production_list.append(p)
         elif eq == '::':
             # Lexical grammar. A hack is needed to replace multicharacter
             # terminals like `!==` into sequences of character terminals.
             rhs = self.expand_lexical_rhs(rhs)
             p = self.to_production(lhs, i, rhs, has_sole_production)
             production_list.append(p)
     return (lhs.name, eq, grammar.NtDef(lhs.args, production_list, nt_type))