QSIG fully implemented
[obnox/wireshark/wip.git] / tools / asn2wrs.py
index 5a649d23bb25ec8a56bf73da2fdf7ecd3dc912dd..e4757202d37d32e5e30309f6a16e2d09968521b6 100755 (executable)
@@ -251,7 +251,7 @@ reserved_words = {
 #  'IMPLIED'     : 'IMPLIED',
   'IMPORTS'     : 'IMPORTS',
   'INCLUDES'    : 'INCLUDES',
-#  'INSTANCE'    : 'INSTANCE',
+  'INSTANCE'    : 'INSTANCE',
   'INTEGER'     : 'INTEGER',
   'INTERSECTION' : 'INTERSECTION',
   'MAX'         : 'MAX',
@@ -288,8 +288,8 @@ reserved_words = {
 }
 
 for k in static_tokens.keys():
-    if static_tokens [k] == None:
-        static_tokens [k] = k
+  if static_tokens [k] == None:
+    static_tokens [k] = k
 
 StringTypes = ['Numeric', 'Printable', 'IA5', 'BMP', 'Universal', 'UTF8',
                'Teletex', 'T61', 'Videotex', 'Graphic', 'ISO646', 'Visible',
@@ -327,7 +327,7 @@ def t_QSTRING (t):
 def t_UCASE_IDENT (t):
     r"[A-Z](-[a-zA-Z0-9]|[a-zA-Z0-9])*" # can't end w/ '-'
     if (is_class_ident(t.value)): t.type = 'CLASS_IDENT'
-    if (is_x880_syntax(t.value)): t.type = t.value
+    if (is_class_syntax(t.value)): t.type = t.value
     t.type = reserved_words.get(t.value, t.type)
     return t
 
@@ -551,6 +551,7 @@ class EthCtx:
     self.default_containing_variant = '_pdu_new'
     self.default_embedded_pdv_cb = None
     self.default_external_type_cb = None
+    self.emitted_pdu = {}
     self.module = {}
     self.module_ord = []
     self.all_type_attr = {}
@@ -609,10 +610,12 @@ class EthCtx:
       pass
     return "MIN((%s),(%s))" % (a, b) 
 
-  def value_get_eth(self, nm):
-    ethname = nm
-    if self.value.has_key(nm):
-      ethname = self.value[nm]['ethname']
+  def value_get_eth(self, val):
+    if isinstance(val, Value):
+      return val.to_str(self)
+    ethname = val
+    if self.value.has_key(val):
+      ethname = self.value[val]['ethname']
     return ethname
 
   def value_get_val(self, nm):
@@ -674,6 +677,49 @@ class EthCtx:
       val = self.all_vals[module][nm]
     return val
 
+  def get_obj_repr(self, ident, restr):
+    def set_type_fn(cls, field, fnfield):
+      obj[fnfield + '_fn'] = 'NULL'
+      obj[fnfield + '_pdu'] = 'NULL'
+      if val.has_key(field) and isinstance(val[field], Type_Ref):
+        p = val[field].eth_type_default_pars(self, '')
+        obj[fnfield + '_fn'] = p['TYPE_REF_FN']
+        obj[fnfield + '_fn'] = obj[fnfield + '_fn'] % p  # one iteration
+        if (self.conform.check_item('PDU', cls + '.' + field)):
+          obj[fnfield + '_pdu'] = 'dissect_' + self.field[val[field].val]['ethname']
+      return
+    # end of get_type_fn()
+    obj = { '_name' : ident, '_ident' : asn2c(ident)}
+    obj['_class'] = self.oassign[ident].cls
+    val = self.oassign[ident].val
+    fld = None
+    fld_neg = False
+    if len(restr) > 0:
+      fld = restr[0]
+      if fld[0] == '!':
+        fld_neg = True
+        fld = fld[1:]
+    if fld:
+      if fld_neg:
+        if val.has_key(fld):
+          return None
+      else:
+        if not val.has_key(fld):
+          return None
+    for f in val.keys():
+      if isinstance(val[f], Node):
+        obj[f] = val[f].fld_obj_repr(self)
+      else:
+        obj[f] = str(val[f])
+    if (obj['_class'] == 'TYPE-IDENTIFIER') or (obj['_class'] == 'ABSTRACT-SYNTAX'):
+      set_type_fn(obj['_class'], '&Type', '_type')
+    if (obj['_class'] == 'OPERATION'):
+      set_type_fn(obj['_class'], '&ArgumentType', '_argument')
+      set_type_fn(obj['_class'], '&ResultType', '_result')
+    if (obj['_class'] == 'ERROR'):
+      set_type_fn(obj['_class'], '&ParameterType', '_parameter')
+    return obj
+
   #--- eth_reg_module -----------------------------------------------------------
   def eth_reg_module(self, module):
     #print "eth_reg_module(module='%s')" % (module)
@@ -723,6 +769,19 @@ class EthCtx:
     if  (self.exports_all):
       self.vexports.append(ident)
 
+  #--- eth_reg_oassign --------------------------------------------------------
+  def eth_reg_oassign(self, oassign):
+    ident = oassign.ident
+    #print "eth_reg_oassign(ident='%s')" % (ident)
+    if self.oassign.has_key(ident):
+      if self.oassign[ident] == oassign:
+        return  # OK - already defined
+      else:
+        raise "Duplicate information object assignment for " + ident
+    self.oassign[ident] = oassign
+    self.oassign_ord.append(ident)
+    self.oassign_cls.setdefault(oassign.cls, []).append(ident)
+
   #--- eth_import_type --------------------------------------------------------
   def eth_import_type(self, ident, mod, proto):
     #print "eth_import_type(ident='%s', mod='%s', prot='%s')" % (ident, mod, proto)
@@ -834,6 +893,9 @@ class EthCtx:
                                    'STRINGS' : val.eth_strings(), 'BITMASK' : '0' }
     self.type[ident]['attr'].update(self.conform.use_item('TYPE_ATTR', ident))
     self.type_ord.append(ident)
+    # PDU
+    if (self.conform.check_item('PDU', ident)):
+      self.eth_reg_field(ident, ident, impl=val.HasImplicitTag(self), pdu=self.conform.use_item('PDU', ident))
 
   #--- eth_reg_objectclass ----------------------------------------------------------
   def eth_reg_objectclass(self, ident, val):
@@ -879,7 +941,10 @@ class EthCtx:
   def eth_reg_field(self, ident, type, idx='', parent=None, impl=False, pdu=None):
     #print "eth_reg_field(ident='%s', type='%s')" % (ident, type)
     if self.field.has_key(ident):
-      raise "Duplicate field for " + ident
+      if pdu and (type == self.field[ident]['type']):
+        pass  # OK already created PDU
+      else:
+        raise "Duplicate field for " + ident
     self.field[ident] = {'type' : type, 'idx' : idx, 'impl' : impl, 'pdu' : pdu,
                          'modified' : '', 'attr' : {} , 'create_field' : False }
     name = ident.split('/')[-1]
@@ -924,6 +989,9 @@ class EthCtx:
     self.objectclass = {}
     self.objectclass_ord = []
     self.objectclass_imp = []
+    self.oassign = {}
+    self.oassign_ord = []
+    self.oassign_cls = {}
     #--- Modules ------------
     self.modules = []
     self.exports_all = False
@@ -996,7 +1064,7 @@ class EthCtx:
       self.type[t]['val'].eth_reg_sub(t, self, components_available=True)
 
     #--- required selection types ---------------------------
-    print "self.sel_req_ord = ", self.sel_req_ord
+    #print "self.sel_req_ord = ", self.sel_req_ord
     for t in self.sel_req_ord:
       tt = self.sel_req[t]['typ']
       if not self.type.has_key(tt):
@@ -1123,6 +1191,8 @@ class EthCtx:
       nm = asn2c(nm)
       if (self.field[f]['pdu']): 
         nm += '_PDU'
+        if (not self.merge_modules):
+          nm = self.eproto + '_' + nm
       t = self.field[f]['type']
       if self.type.has_key(t):
         ethtype = self.type[t]['ethname']
@@ -1158,7 +1228,7 @@ class EthCtx:
         self.eth_hfpdu_ord.append(nm)
       else:
         self.eth_hf_ord.append(nm)
-      fullname = "hf_%s_%s" % (self.eproto, nm)
+      fullname = 'hf_%s_%s' % (self.eproto, nm)
       attr = self.eth_get_type_attr(self.field[f]['type']).copy()
       attr.update(self.field[f]['attr'])
       if (self.NAPI() and attr.has_key('NAME')):
@@ -1661,7 +1731,11 @@ class EthCtx:
       fx.write('/*--- PDUs ---*/\n\n')
       for f in self.eth_hfpdu_ord:
         if (self.eth_hf[f]['pdu']):
-          fx.write(out_pdu(f))
+          if (self.emitted_pdu.has_key(f)):
+            fx.write("  /* %s already emitted */\n" % (f))
+          else:
+            fx.write(out_pdu(f))
+            self.emitted_pdu[f] = True
       fx.write('\n')
     fempty = pos == fx.tell()
     self.output.file_close(fx, discard=fempty)
@@ -1731,6 +1805,38 @@ class EthCtx:
     fx.write('\n')
     self.output.file_close(fx, discard=fempty)
 
+  #--- eth_output_table -----------------------------------------------------
+  def eth_output_table(self):
+    for num in self.conform.report.keys():
+      fx = self.output.file_open('table' + num)
+      for rep in self.conform.report[num]:
+        if rep['type'] == 'HDR':
+          fx.write('\n')
+        if rep['var']:
+          var = rep['var']
+          var_list = var.split('.')
+          cls = var_list[0]
+          del var_list[0]
+          if (self.oassign_cls.has_key(cls)):
+            for ident in self.oassign_cls[cls]:
+             obj = self.get_obj_repr(ident, var_list)
+             if not obj:
+               continue
+             obj['_LOOP'] = var
+             obj['_DICT'] = str(obj)
+             try:
+               text = rep['text'] % obj
+             except (KeyError):
+               raise sys.exc_type, "%s:%s invalid key %s for information object %s of %s" % (rep['fn'], rep['lineno'], sys.exc_value, ident, var)
+             fx.write(text)
+          else:
+            fx.write("/* Unknown or empty loop list %s */\n" % (var))
+        else:
+          fx.write(rep['text'])
+        if rep['type'] == 'FTR':
+          fx.write('\n')
+      self.output.file_close(fx)
+
   #--- dupl_report -----------------------------------------------------
   def dupl_report(self):
     # types
@@ -1765,6 +1871,9 @@ class EthCtx:
       print "\n# Value assignments"
       for a in self.vassign_ord:
         print ' ', a
+      print "\n# Information object assignments"
+      for a in self.oassign_ord:
+        print " %-12s (%s)" % (a, self.oassign[a].cls)
     if self.dbg('t'):
       print "\n# Imported Types"
       print "%-40s %-24s %-24s" % ("ASN.1 name", "Module", "Protocol")
@@ -1860,6 +1969,7 @@ class EthCtx:
     self.eth_output_dis_hnd()
     self.eth_output_dis_reg()
     self.eth_output_dis_tab()
+    self.eth_output_table()
 
   def dbg_modules(self):
     def print_mod(m):
@@ -1898,6 +2008,7 @@ class EthCnf:
     self.table = {}
     self.order = {}
     self.fn = {}
+    self.report = {}
     self.suppress_line = False
     self.include_path = []
     #                                   Value name             Default value       Duplicity check   Usage check
@@ -2092,7 +2203,8 @@ class EthCnf:
       return par
 
     f = open(fn, "r")
-    directive = re.compile(r'^\s*#\.(?P<name>[A-Z_]+)\s+')
+    directive = re.compile(r'^\s*#\.(?P<name>[A-Z_][A-Z_0-9]*)\s+')
+    report = re.compile(r'^TABLE(?P<num>\d*)_(?P<type>HDR|BODY|FTR)$')
     comment = re.compile(r'^\s*#[^.]')
     empty = re.compile(r'^\s*$')
     lineno = 0
@@ -2118,6 +2230,7 @@ class EthCnf:
       if comment.search(line): continue
       result = directive.search(line)
       if result:  # directive
+        rep_result = report.search(result.group('name'))
         if result.group('name') == 'END_OF_CNF':
           f.close()
         elif result.group('name') == 'OPT':
@@ -2220,6 +2333,20 @@ class EthCnf:
           par = get_par(line[result.end():], 1, 1, fn=fn, lineno=lineno)
           if not par: continue
           self.update_item('ASSIGNED_ID', 'OBJECT_IDENTIFIER', ids={par[0] : par[0]}, fn=fn, lineno=lineno)
+        elif rep_result:  # Reports
+          num = rep_result.group('num')
+          type = rep_result.group('type')
+          if type == 'BODY':
+            par = get_par(line[result.end():], 1, 1, fn=fn, lineno=lineno)
+            if not par: continue
+          else:
+            par = get_par(line[result.end():], 0, 0, fn=fn, lineno=lineno)
+          rep = { 'type' : type, 'var' : None, 'text' : '', 'fn' : fn, 'lineno' : lineno }
+          if len(par) > 0:
+            rep['var'] = par[0]
+          self.report.setdefault(num, []).append(rep)
+          ctx = 'TABLE'
+          name = num
         elif result.group('name') == 'INCLUDE':
           par = get_par(line[result.end():], 1, 1, fn=fn, lineno=lineno)
           if not par: 
@@ -2403,6 +2530,8 @@ class EthCnf:
         if not set_type_to_class(name, par[0], par[1:]):
           warnings.warn_explicit("Could not set type of class member %s.&%s to %s" % (name, par[0], par[1]),
                                   UserWarning, fn, lineno)
+      elif ctx == 'TABLE':
+        self.report[name][-1]['text'] += line
 
   def set_opt(self, opt, par, fn, lineno):
     #print "set_opt: %s, %s" % (opt, par)
@@ -2576,7 +2705,9 @@ class EthOut:
       fx.write('\n')
       mstr = "--- "
       if self.ectx.groups():
-        mstr += "Modules"
+        mstr += "Module"
+        if (len(self.ectx.modules) > 1):
+          mstr += "s"
         for (m, p) in self.ectx.modules:
           mstr += " %s" % (m)
       else:
@@ -2703,7 +2834,7 @@ class Node:
         l.append ("".join (map (lambda (k,v): self.str_child (k, v, depth + 1),
                                 self.__dict__.items ())))
         return "\n".join (l)
-    def __str__(self):
+    def __repr__(self):
         return "\n" + self.str_depth (0)
     def to_python (self, ctx):
         return self.str_depth (ctx.indent_lev)
@@ -2711,8 +2842,11 @@ class Node:
     def eth_reg(self, ident, ectx):
         pass
 
-#--- value_assign -------------------------------------------------------------
-class value_assign (Node):
+    def fld_obj_repr(self, ectx):
+        return "/* TO DO %s */" % (str(self))
+
+#--- ValueAssignment -------------------------------------------------------------
+class ValueAssignment (Node):
   def __init__(self,*args, **kw) :
     Node.__init__ (self,*args, **kw)
 
@@ -2721,6 +2855,52 @@ class value_assign (Node):
     ectx.eth_reg_vassign(self)
     ectx.eth_reg_value(self.ident, self.typ, self.val)
 
+#--- ObjectAssignment -------------------------------------------------------------
+class ObjectAssignment (Node):
+  def __init__(self,*args, **kw) :
+    Node.__init__ (self,*args, **kw)
+
+  def __eq__(self, other):
+    if self.cls != other.cls:
+      return False
+    if len(self.val) != len(other.val):
+      return False
+    for f in (self.val.keys()):
+      if not other.val.has_key(f):
+        return False
+      if isinstance(self.val[f], Node) and isinstance(other.val[f], Node):
+        if not self.val[f].fld_obj_eq(other.val[f]):
+          return False
+      else:
+        if str(self.val[f]) != str(other.val[f]):
+          return False
+    return True
+
+  def eth_reg(self, ident, ectx):
+    def make_virtual_type(cls, field, prefix):
+      if isinstance(self.val, str): return
+      if self.val.has_key(field) and not isinstance(self.val[field], Type_Ref):
+        vnm = prefix + '-' + self.ident
+        virtual_tr = Type_Ref(val = vnm)
+        t = self.val[field]
+        self.val[field] = virtual_tr
+        ectx.eth_reg_assign(vnm, t, virt=True)
+        ectx.eth_reg_type(vnm, t)
+        t.eth_reg_sub(vnm, ectx)
+      if self.val.has_key(field) and ectx.conform.check_item('PDU', cls + '.' + field):
+        ectx.eth_reg_field(self.val[field].val, self.val[field].val, impl=self.val[field].HasImplicitTag(ectx), pdu=ectx.conform.use_item('PDU', cls + '.' + field))
+      return
+    # end of make_virtual_type()
+    if ectx.conform.omit_assignment('V', self.ident, ectx.Module()): return # Assignment to omit
+    ectx.eth_reg_oassign(self)
+    if (self.cls == 'TYPE-IDENTIFIER') or (self.cls == 'ABSTRACT-SYNTAX'):
+      make_virtual_type(self.cls, '&Type', 'TYPE')
+    if (self.cls == 'OPERATION'):
+      make_virtual_type(self.cls, '&ArgumentType', 'ARG')
+      make_virtual_type(self.cls, '&ResultType', 'RES')
+    if (self.cls == 'ERROR'):
+      make_virtual_type(self.cls, '&ParameterType', 'PAR')
+
 
 #--- Type ---------------------------------------------------------------------
 class Type (Node):
@@ -2824,9 +3004,11 @@ class Type (Node):
     print "#Selection '%s' required for non-CHOICE type %s" % (sel, self.type)
     print self.str_depth(1)
     
+  def fld_obj_eq(self, other):
+    return isinstance(other, Type) and (self.eth_tname() == other.eth_tname())
+
   def eth_reg(self, ident, ectx, tstrip=0, tagflag=False, selflag=False, idx='', parent=None):
     #print "eth_reg(): %s, ident=%s, tstrip=%d, tagflag=%s, selflag=%s, parent=%s" %(self.type, ident, tstrip, str(tagflag), str(selflag), str(parent))
-    if (selflag): print "eth_reg(): %s, ident=%s, tstrip=%d, tagflag=%s, selflag=%s, parent=%s" %(self.type, ident, tstrip, str(tagflag), str(selflag), str(parent))
     if (ectx.Tag() and (len(self.tags) > tstrip)):
       tagged_type = TaggedType(val=self, tstrip=tstrip)
       tagged_type.AddTag(self.tags[tstrip])
@@ -2847,8 +3029,6 @@ class Type (Node):
       ectx.eth_reg_assign(nm, self)
       if self.type == 'Type_Ref':
         ectx.eth_reg_type(nm, self)
-      if (ectx.conform.check_item('PDU', nm)):
-        ectx.eth_reg_field(nm, nm, impl=self.HasImplicitTag(ectx), pdu=ectx.conform.use_item('PDU', nm))
     virtual_tr = Type_Ref(val=ectx.conform.use_item('SET_TYPE', nm))
     if (self.type == 'Type_Ref') or ectx.conform.check_item('SET_TYPE', nm):
       if ident and (ectx.conform.check_item('TYPE_RENAME', nm) or ectx.conform.get_fn_presence(nm) or selflag):
@@ -2954,8 +3134,10 @@ class Type (Node):
     }
     if (ectx.eth_type[tname]['tree']):
       pars['ETT_INDEX'] = ectx.eth_type[tname]['tree']
-    if (not ectx.Per()):
-      pars['PINFO'] = 'pinfo'
+    if (ectx.merge_modules):
+      pars['PROTOP'] = ''
+    else:
+      pars['PROTOP'] = ectx.eth_type[tname]['proto'] + '_'
     return pars
 
   def eth_type_fn(self, proto, tname, ectx):
@@ -2967,7 +3149,11 @@ class Type (Node):
       pars.update(ectx.conform.use_item('FN_PARS', ectx.eth_type[tname]['ref'][0]))
     pars['DEFAULT_BODY'] = body
     for i in range(4):
-      for k in pars.keys(): pars[k] = pars[k] % pars
+      for k in pars.keys(): 
+        try:
+          pars[k] = pars[k] % pars
+        except (TypeError):
+          raise sys.exc_type, "%s\n%s" % (str(pars), sys.exc_value)
     out = '\n'
     out += self.eth_type_default_table(ectx, tname) % pars
     out += ectx.eth_type_fn_hdr(tname)
@@ -2990,6 +3176,14 @@ class Value (Node):
   def get_dep(self):
     return None
 
+  def fld_obj_repr(self, ectx):
+    return self.to_str(ectx)
+
+#--- Value_Ref -----------------------------------------------------------------
+class Value_Ref (Value):
+  def to_str(self, ectx):
+    return asn2c(self.val)
+
 #--- ObjectClass ---------------------------------------------------------------------
 class ObjectClass (Node):
   def __init__(self,*args, **kw) :
@@ -3166,7 +3360,7 @@ class Constraint (Node):
 
   def IsNegativ(self):
     def is_neg(sval):
-      return sval[0] == '-'
+      return isinstance(sval, str) and (sval[0] == '-')
     if self.type == 'SingleValue':
       return is_neg(self.subtype)
     elif self.type == 'ValueRange':
@@ -3176,6 +3370,8 @@ class Constraint (Node):
 
   def eth_constrname(self):
     def int2str(val):
+      if isinstance(val, Value_Ref):
+        return asn2c(val.val)
       try:
         if (int(val) < 0):
           return 'M' + str(-int(val))
@@ -3238,10 +3434,13 @@ class Module_Body (Node):
       for s in i.symbol_list:
         if isinstance(s, Type_Ref):
           ectx.eth_import_type(s.val, mod, proto)
+        elif isinstance(s, Value_Ref):
+          ectx.eth_import_value(s.val, mod, proto)
         elif isinstance(s, Class_Ref):
           ectx.eth_import_class(s.val, mod, proto)
         else:
-          ectx.eth_import_value(s, mod, proto)
+          msg = 'Unknown kind of imported symbol %s from %s' % (str(s), mod)
+          warnings.warn_explicit(msg, UserWarning, '', '')
     # AssignmentList
     for a in self.assign_list:
       a.eth_reg('', ectx)
@@ -3303,6 +3502,9 @@ class Type_Ref (Type):
   def eth_tname(self):
     return asn2c(self.val)
 
+  def fld_obj_repr(self, ectx):
+    return self.val
+
   def get_components(self, ectx):
     if not ectx.type.has_key(self.val) or ectx.type[self.val]['import']:
       msg = "Can not get COMPONENTS OF %s which is imported type" % (self.val)
@@ -3332,7 +3534,10 @@ class Type_Ref (Type):
       return ectx.type[self.val]['val'].IndetermTag(ectx)
 
   def eth_type_default_pars(self, ectx, tname):
-    pars = Type.eth_type_default_pars(self, ectx, tname)
+    if tname:
+      pars = Type.eth_type_default_pars(self, ectx, tname)
+    else:
+      pars = {}
     t = ectx.type[self.val]['ethname']
     pars['TYPE_REF_PROTO'] = ectx.eth_type[t]['proto']
     pars['TYPE_REF_TNAME'] = t
@@ -3631,7 +3836,7 @@ class SequenceOfType (SeqOfType):
   def eth_type_default_pars(self, ectx, tname):
     pars = Type.eth_type_default_pars(self, ectx, tname)
     (pars['MIN_VAL'], pars['MAX_VAL'], pars['EXT']) = self.eth_get_size_constr(ectx)
-    pars['TABLE'] = '%(TNAME)s_sequence_of'
+    pars['TABLE'] = '%(PROTOP)s%(TNAME)s_sequence_of'
     return pars
 
   def eth_type_default_body(self, ectx, tname):
@@ -3688,7 +3893,7 @@ class SetOfType (SeqOfType):
   def eth_type_default_pars(self, ectx, tname):
     pars = Type.eth_type_default_pars(self, ectx, tname)
     (pars['MIN_VAL'], pars['MAX_VAL'], pars['EXT']) = self.eth_get_size_constr(ectx)
-    pars['TABLE'] = '%(TNAME)s_set_of'
+    pars['TABLE'] = '%(PROTOP)s%(TNAME)s_set_of'
     return pars
 
   def eth_type_default_body(self, ectx, tname):
@@ -3793,7 +3998,7 @@ class SequenceType (SeqType):
 
   def eth_type_default_pars(self, ectx, tname):
     pars = Type.eth_type_default_pars(self, ectx, tname)
-    pars['TABLE'] = '%(TNAME)s_sequence'
+    pars['TABLE'] = '%(PROTOP)s%(TNAME)s_sequence'
     return pars
 
   def eth_type_default_body(self, ectx, tname):
@@ -3838,7 +4043,7 @@ class SetType(SeqType):
 
   def eth_type_default_pars(self, ectx, tname):
     pars = Type.eth_type_default_pars(self, ectx, tname)
-    pars['TABLE'] = '%(TNAME)s_set'
+    pars['TABLE'] = '%(PROTOP)s%(TNAME)s_set'
     return pars
 
   def eth_type_default_body(self, ectx, tname):
@@ -3924,7 +4129,7 @@ class ChoiceType (Type):
     return ee
 
   def sel_req(self, ident, sel, ectx):
-    print "sel_req(ident='%s', sel=%s)\n%s" % (ident, sel, str(self))
+    #print "sel_req(ident='%s', sel=%s)\n%s" % (ident, sel, str(self))
     ee = self.sel_item(ident, sel, ectx)
     if ee:
       ee.eth_reg(ident, ectx, tstrip=0, selflag=True)
@@ -4014,7 +4219,7 @@ class ChoiceType (Type):
 
   def eth_type_default_pars(self, ectx, tname):
     pars = Type.eth_type_default_pars(self, ectx, tname)
-    pars['TABLE'] = '%(TNAME)s_choice'
+    pars['TABLE'] = '%(PROTOP)s%(TNAME)s_choice'
     return pars
 
   def eth_type_default_table(self, ectx, tname):
@@ -4126,6 +4331,9 @@ class ChoiceValue (Value):
   def to_str(self, ectx):
     return self.val.to_str(ectx)
 
+  def fld_obj_eq(self, other):
+    return isinstance(other, ChoiceValue) and (self.choice == other.choice) and (str(self.val.val) == str(other.val.val))
+
 #--- EnumeratedType -----------------------------------------------------------
 class EnumeratedType (Type):
   def to_python (self, ctx):
@@ -4221,7 +4429,7 @@ class EnumeratedType (Type):
     pars['EXT'] = ext
     pars['EXT_NUM'] = str(ext_num)
     if (map_table):
-      pars['TABLE'] = '%(TNAME)s_value_map'
+      pars['TABLE'] = '%(PROTOP)s%(TNAME)s_value_map'
     else:
       pars['TABLE'] = 'NULL'
     return pars
@@ -4359,6 +4567,35 @@ class OpenType (Type):
       body = '#error Can not decode %s' % (tname)
     return body
 
+#--- InstanceOfType -----------------------------------------------------------
+class InstanceOfType (Type):
+  def eth_tname(self):
+    return 'INSTANCE_OF'
+
+  def eth_ftype(self, ectx):
+    return ('FT_NONE', 'BASE_NONE')
+
+  def GetTTag(self, ectx):
+    return ('BER_CLASS_UNI', 'BER_UNI_TAG_EXTERNAL')
+
+  def eth_type_default_pars(self, ectx, tname):
+    pars = Type.eth_type_default_pars(self, ectx, tname)
+    if ectx.default_external_type_cb:
+      pars['TYPE_REF_FN'] = ectx.default_external_type_cb
+    else:
+      pars['TYPE_REF_FN'] = 'NULL'
+    return pars
+
+  def eth_type_default_body(self, ectx, tname):
+    if (ectx.Ber()):  
+      body = ectx.eth_fn_call('dissect_%(ER)s_external_type', ret='offset',
+                              par=(('%(IMPLICIT_TAG)s', '%(TREE)s', '%(TVB)s', '%(OFFSET)s', '%(ACTX)s', '%(HF_INDEX)s', '%(TYPE_REF_FN)s',),))
+    elif (ectx.Per()):
+      body = '#error Can not decode %s' % (tname)
+    else:
+      body = '#error Can not decode %s' % (tname)
+    return body
+
 #--- AnyType -----------------------------------------------------------
 class AnyType (Type):
   def to_python (self, ctx):
@@ -4897,7 +5134,7 @@ class BitStringType (Type):
       pars['ETT_INDEX'] = '-1'
     pars['TABLE'] = 'NULL'
     if self.eth_named_bits():
-      pars['TABLE'] = '%(TNAME)s_bits'
+      pars['TABLE'] = '%(PROTOP)s%(TNAME)s_bits'
     if self.HasContentsConstraint():
       pars['FN_VARIANT'] = ectx.default_containing_variant
       t = self.constr.GetContents(ectx)
@@ -4972,6 +5209,12 @@ class BStringValue (Value):
       vv += bstring_tab[v[i:i+4]]
     return vv
 
+#--- HStringValue ------------------------------------------------------------
+class HStringValue (Value):
+  def to_str(self, ectx):
+    vv = '0x'
+    vv += self.val[1:-2]
+    return vv
 
 #--- FieldSpec ----------------------------------------------------------------
 class FieldSpec (Node):
@@ -5042,7 +5285,7 @@ def p_identifier (t):
 # 11.4 Value references
 def p_valuereference (t):
   'valuereference : LCASE_IDENT'
-  t[0] = t[1]
+  t[0] = Value_Ref(val=t[1])
 
 # 11.5 Module references
 def p_modulereference (t):
@@ -5158,7 +5401,7 @@ def p_SymbolsFromModule (t):
   'SymbolsFromModule : SymbolList FROM GlobalModuleReference'
   t[0] = Node ('SymbolList', symbol_list = t[1], module = t[3])
   for s in (t[0].symbol_list): 
-    if (isinstance(s, str) and s[0].islower()): lcase_ident_assigned[s] = t[3]
+    if (isinstance(s, Value_Ref)): lcase_ident_assigned[s.val] = t[3]
   if t[0].module.val == 'Remote-Operations-Information-Objects':
     for i in range(len(t[0].symbol_list)):
       s = t[0].symbol_list[i]
@@ -5196,13 +5439,16 @@ def p_Symbol (t):
             | ParameterizedReference'''
   t[0] = t[1]
 
-def p_Reference (t):
+def p_Reference_1 (t):
   '''Reference : type_ref
                | valuereference
-               | objectclassreference
-               | LCASE_IDENT_ASSIGNED'''
+               | objectclassreference '''
   t[0] = t[1]
 
+def p_Reference_2 (t):
+  '''Reference : LCASE_IDENT_ASSIGNED'''
+  t[0] = Value_Ref (val=t[1])
+
 def p_AssignmentList_1 (t):
   'AssignmentList : AssignmentList Assignment'
   t[0] = t[1] + [t[2]]
@@ -5238,7 +5484,7 @@ def p_DefinedType (t):
 
 def p_DefinedValue(t):
   '''DefinedValue : ExternalValueReference
-                  | identifier'''
+                  | valuereference'''
   t[0] = t[1]
 
 # 13.6
@@ -5261,8 +5507,8 @@ def p_TypeAssignment (t):
 
 # 15.2
 def p_ValueAssignment (t):
-  'ValueAssignment : valuereference ValueType ASSIGNMENT Value'
-  t[0] = value_assign (ident = t[1], typ = t[2], val = t[4])
+  'ValueAssignment : LCASE_IDENT ValueType ASSIGNMENT Value'
+  t[0] = ValueAssignment(ident = t[1], typ = t[2], val = t[4])
 
 # only "simple" types are supported to simplify grammer
 def p_ValueType (t):
@@ -5305,6 +5551,7 @@ def p_BuiltinType (t):
                  | EmbeddedPDVType
                  | EnumeratedType
                  | ExternalType
+                 | InstanceOfType
                  | IntegerType
                  | NullType
                  | ObjectClassFieldType
@@ -5334,7 +5581,8 @@ def p_NamedType (t):
 # 16.7
 def p_Value (t):
   '''Value : BuiltinValue
-           | ReferencedValue'''
+           | ReferencedValue
+           | ObjectClassFieldValue'''
   t[0] = t[1]
 
 # 16.9
@@ -5630,7 +5878,8 @@ def p_DefaultValue_1 (t):
                   | RealValue
                   | hex_string
                   | binary_string
-                  | char_string'''
+                  | char_string
+                  | ObjectClassFieldValue'''
   t[0] = t[1]
 
 def p_DefaultValue_2 (t):
@@ -5669,16 +5918,15 @@ def p_SequenceOfType (t):
 
 # 26.1
 def p_SetType_1 (t):
-    'SetType : SET LBRACE RBRACE'
-    if t[3].has_key('ext_list'):
-        t[0] = SetType (elt_list = [])
+  'SetType : SET LBRACE RBRACE'
+  t[0] = SetType (elt_list = [])
 
 def p_SetType_2 (t):
-    'SetType : SET LBRACE ComponentTypeLists RBRACE'
-    if t[3].has_key('ext_list'):
-        t[0] = SetType (elt_list = t[3]['elt_list'], ext_list = t[3]['ext_list'])
-    else:
-        t[0] = SetType (elt_list = t[3]['elt_list'])
+  'SetType : SET LBRACE ComponentTypeLists RBRACE'
+  if t[3].has_key('ext_list'):
+    t[0] = SetType (elt_list = t[3]['elt_list'], ext_list = t[3]['ext_list'])
+  else:
+    t[0] = SetType (elt_list = t[3]['elt_list'])
 
 
 # 27 Notation for set-of types ------------------------------------------------
@@ -6224,12 +6472,12 @@ def p_ExceptionIdentification (t):
 
 
 def p_binary_string (t):
-    'binary_string : BSTRING'
-    t[0] = BStringValue(val = t[1])
+  'binary_string : BSTRING'
+  t[0] = BStringValue(val = t[1])
 
 def p_hex_string (t):
-    'hex_string : HSTRING'
-    t[0] = t[1]
+  'hex_string : HSTRING'
+  t[0] = HStringValue(val = t[1])
 
 def p_char_string (t):
     'char_string : QSTRING'
@@ -6288,6 +6536,8 @@ def p_DefinedObjectClass (t):
   '''DefinedObjectClass : objectclassreference
                         | UsefulObjectClassReference'''
   t[0] = t[1]
+  global obj_class
+  obj_class = t[0].val
 
 def p_DefinedObject (t):
   '''DefinedObject : objectreference'''
@@ -6297,7 +6547,7 @@ def p_DefinedObject (t):
 def p_UsefulObjectClassReference (t):
   '''UsefulObjectClassReference : TYPE_IDENTIFIER 
                                 | ABSTRACT_SYNTAX'''
-  t[0] = t[1]
+  t[0] = Class_Ref(val=t[1])
 
 # 9 Information object class definition and assignment
 
@@ -6392,10 +6642,12 @@ def p_ValueSetOptionalitySpec_2 (t):
 
 # 9.11
 def p_ObjectFieldSpec (t):
-  '''ObjectFieldSpec : lcasefieldreference CLASS_IDENT
-                     | lcasefieldreference CLASS_IDENT ObjectOptionalitySpec '''
+  '''ObjectFieldSpec : lcasefieldreference DefinedObjectClass
+                     | lcasefieldreference DefinedObjectClass ObjectOptionalitySpec '''
   t[0] = ObjectFieldSpec(cls=t[2])
   t[0].SetName(t[1])
+  global obj_class
+  obj_class = None
 
 def p_ObjectOptionalitySpec_1 (t):
   'ObjectOptionalitySpec ::= OPTIONAL'
@@ -6407,8 +6659,8 @@ def p_ObjectOptionalitySpec_2 (t):
 
 # 9.12
 def p_ObjectSetFieldSpec (t):
-  '''ObjectSetFieldSpec : ucasefieldreference CLASS_IDENT
-                        | ucasefieldreference CLASS_IDENT ObjectSetOptionalitySpec '''
+  '''ObjectSetFieldSpec : ucasefieldreference DefinedObjectClass
+                        | ucasefieldreference DefinedObjectClass ObjectSetOptionalitySpec '''
   t[0] = ObjectSetFieldSpec(cls=t[2])
   t[0].SetName(t[1])
 
@@ -6439,9 +6691,10 @@ def p_FieldName_2 (t):
 
 # 11.1
 def p_ObjectAssignment (t):
-  '''ObjectAssignment : objectreference CLASS_IDENT ASSIGNMENT Object
-                      | objectreference UsefulObjectClassReference ASSIGNMENT Object'''
-  t[0] = Node('ObjectAssignment', name=t[1], cls=t[2], val=t[4])
+  'ObjectAssignment : objectreference DefinedObjectClass ASSIGNMENT Object'
+  t[0] = ObjectAssignment (ident = t[1], cls=t[2].val, val=t[4])
+  global obj_class
+  obj_class = None
 
 # 11.3
 def p_Object (t):
@@ -6452,8 +6705,86 @@ def p_Object (t):
 
 # 11.4
 def p_ObjectDefn (t):
-  'ObjectDefn : lbraceignore rbraceignore'
-  t[0] = None
+  'ObjectDefn : lbraceobject bodyobject rbraceobject'
+  t[0] = t[2]
+
+#  {...} block of object definition
+def p_lbraceobject(t):
+  'lbraceobject : braceobjectbegin LBRACE'
+  t[0] = t[1]
+
+def p_braceobjectbegin(t):
+  'braceobjectbegin : '
+  global lexer
+  global obj_class
+  if set_class_syntax(obj_class):
+    state = 'INITIAL'
+  else:
+    lexer.level = 1
+    state = 'braceignore'
+  lexer.push_state(state)
+
+def p_rbraceobject(t):
+  'rbraceobject : braceobjectend RBRACE'
+  t[0] = t[2]
+
+def p_braceobjectend(t):
+  'braceobjectend : '
+  global lexer
+  lexer.pop_state()
+  set_class_syntax(None)
+
+def p_bodyobject_1 (t):
+  'bodyobject : '
+  t[0] = { }
+
+def p_bodyobject_2 (t):
+  'bodyobject : cls_syntax_list'
+  t[0] = t[1]
+
+def p_cls_syntax_list_1 (t):
+  'cls_syntax_list : cls_syntax_list cls_syntax'
+  t[0] = t[1]
+  t[0].update(t[2])
+
+def p_cls_syntax_list_2 (t):
+  'cls_syntax_list : cls_syntax'
+  t[0] = t[1]
+
+# X.681
+def p_cls_syntax_1 (t):
+  'cls_syntax : Type IDENTIFIED BY Value'
+  t[0] = { get_class_fieled(' ') : t[1], get_class_fieled(' '.join((t[2], t[3]))) : t[4] }
+
+def p_cls_syntax_2 (t):
+  'cls_syntax : HAS PROPERTY Value'
+  t[0] = { get_class_fieled(' '.join(t[1:-1])) : t[-1:][0] }
+
+# X.880
+def p_cls_syntax_3 (t):
+  '''cls_syntax : ERRORS ObjectSet
+                 | LINKED ObjectSet
+                 | RETURN RESULT BooleanValue 
+                 | SYNCHRONOUS BooleanValue
+                 | INVOKE PRIORITY Value 
+                 | RESULT_PRIORITY Value 
+                 | PRIORITY Value 
+                 | ALWAYS RESPONDS BooleanValue
+                 | IDEMPOTENT BooleanValue '''
+  t[0] = { get_class_fieled(' '.join(t[1:-1])) : t[-1:][0] }
+
+def p_cls_syntax_4 (t):
+  '''cls_syntax : ARGUMENT Type
+                 | RESULT Type
+                 | PARAMETER Type
+                 | CODE Value '''
+  t[0] = { get_class_fieled(t[1]) : t[2] }
+
+def p_cls_syntax_5 (t):
+  '''cls_syntax : ARGUMENT Type OPTIONAL BooleanValue
+                 | RESULT Type OPTIONAL BooleanValue
+                 | PARAMETER Type OPTIONAL BooleanValue '''
+  t[0] = { get_class_fieled(t[1]) : t[2], get_class_fieled(' '.join((t[1], t[3]))) : t[4] }
 
 # 12 Information object set definition and assignment
 
@@ -6474,7 +6805,18 @@ def p_ObjectClassFieldType (t):
   'ObjectClassFieldType : DefinedObjectClass DOT FieldName'
   t[0] = get_type_from_class(t[1], t[3])
 
-# 15 Information from objects
+# 14.6
+def p_ObjectClassFieldValue (t):
+  '''ObjectClassFieldValue : OpenTypeFieldVal'''
+  t[0] = t[1]
+
+def p_OpenTypeFieldVal (t):
+  '''OpenTypeFieldVal : Type COLON Value
+                      | NullType COLON NullValue'''
+  t[0] = t[3]
+
+
+# 15 Information from objects -------------------------------------------------
 
 # 15.1
 
@@ -6482,6 +6824,17 @@ def p_ValueFromObject (t):
   'ValueFromObject : LCASE_IDENT DOT FieldName'
   t[0] = t[1] + '.' + t[3]
 
+
+# Annex C - The instance-of type ----------------------------------------------
+
+# C.2
+def p_InstanceOfType (t):
+  'InstanceOfType : INSTANCE OF DefinedObjectClass'
+  t[0] = InstanceOfType()
+
+
+# ---  tables ---
+
 useful_object_class_types = {
   # Annex A
   'TYPE-IDENTIFIER.&id'   : lambda : ObjectIdentifierType(),
@@ -6507,6 +6860,71 @@ class_types_creator = {
 
 class_names = { }
 
+x681_syntaxes = {
+  'TYPE-IDENTIFIER' : {
+    ' '             : '&Type',
+    'IDENTIFIED'    : 'IDENTIFIED',
+    #'BY'            : 'BY',         
+    'IDENTIFIED BY' : '&id',         
+  },
+  'ABSTRACT-SYNTAX' : {
+    ' '             : '&Type',
+    'IDENTIFIED'    : 'IDENTIFIED',
+    #'BY'            : 'BY',         
+    'IDENTIFIED BY' : '&id',         
+    'HAS'           : 'HAS',
+    'PROPERTY'      : 'PROPERTY',         
+    'HAS PROPERTY'  : '&property',         
+  },
+}
+
+class_syntaxes_enabled = { 
+  'TYPE-IDENTIFIER' : True,
+  'ABSTRACT-SYNTAX' : True,
+}
+
+class_syntaxes = {
+  'TYPE-IDENTIFIER' : x681_syntaxes['TYPE-IDENTIFIER'],
+  'ABSTRACT-SYNTAX' : x681_syntaxes['ABSTRACT-SYNTAX'],
+}
+
+class_current_syntax = None
+
+def get_syntax_tokens(syntaxes):
+  tokens = { }
+  for s in (syntaxes):
+    for k in (syntaxes[s].keys()):
+      if k.find(' ') < 0:
+        tokens[k] = k
+        tokens[k] = tokens[k].replace('-', '_')
+  return tokens.values()
+
+tokens = tokens + get_syntax_tokens(x681_syntaxes)
+
+def set_class_syntax(syntax):
+  global class_syntaxes_enabled
+  global class_current_syntax
+  #print "set_class_syntax", syntax, class_current_syntax
+  if class_syntaxes_enabled.get(syntax, False):
+    class_current_syntax = syntax
+    return True
+  else:
+    class_current_syntax = None
+    return False
+
+def is_class_syntax(name):
+  global class_syntaxes
+  global class_current_syntax
+  #print "is_class_syntax", name, class_current_syntax
+  if not class_current_syntax:
+    return False
+  return class_syntaxes[class_current_syntax].has_key(name)
+
+def get_class_fieled(name):
+  if not class_current_syntax:
+    return None
+  return class_syntaxes[class_current_syntax][name]
+
 def is_class_ident(name):
   return class_names.has_key(name)
 
@@ -6536,13 +6954,29 @@ def set_type_to_class(cls, fld, pars):
   typename = 'OpenType'
   if (len(pars) > 0):
     typename = pars[0]
+  else:
+    pars.append(typename)
   typeref = None
   if (len(pars) > 1):
+    if (isinstance(pars[1], Class_Ref)):
+      pars[1] = pars[1].val
     typeref = pars[1]
 
-  if object_class_types.has_key(key): return False
-  if object_class_typerefs.has_key(key): return False
-  if object_class_classrefs.has_key(key): return False
+  msg = None
+  if object_class_types.has_key(key): 
+    msg = object_class_types[key]().type
+  if object_class_typerefs.has_key(key):
+    msg = "TypeReference " + object_class_typerefs[key]
+  if object_class_classrefs.has_key(key):
+    msg = "ClassReference " + object_class_classrefs[key]
+
+  if msg == ' '.join(pars): 
+    msg = None
+
+  if msg:
+    msg0 = "Can not define CLASS field %s as '%s'\n" % (key, ' '.join(pars))
+    msg1 = "Already defined as '%s'" % (msg)
+    raise msg0 + msg1
 
   if (typename == 'ClassReference'):
     if not typeref: return False
@@ -6593,7 +7027,7 @@ def p_UserDefinedConstraintParameterList_3 (t):
 
 # 9.3
 def p_UserDefinedConstraintParameter (t):
-  'UserDefinedConstraintParameter : type_ref'
+  'UserDefinedConstraintParameter : Type'
   t[0] = t[1]
 
 # 10 Table constraints, including component relation constraints --------------
@@ -6671,12 +7105,14 @@ def p_ParameterizedTypeAssignment (t):
   t[0].SetName(t[1])  # t[0].SetName(t[1] + 'xxx')
 
 def p_ParameterizedObjectAssignment (t):
-  'ParameterizedObjectAssignment : objectreference ParameterList CLASS_IDENT ASSIGNMENT Object'
-  t[0] = Node('ObjectAssignment', name=t[1], cls=t[3], val=t[5])
+  'ParameterizedObjectAssignment : objectreference ParameterList DefinedObjectClass ASSIGNMENT Object'
+  t[0] = ObjectAssignment (ident = t[1], cls=t[3].val, val=t[5])
+  global obj_class
+  obj_class = None
 
 def p_ParameterizedObjectSetAssignment (t):
-  'ParameterizedObjectSetAssignment : UCASE_IDENT ParameterList CLASS_IDENT ASSIGNMENT ObjectSet'
-  t[0] = Node('ObjectSetAssignment', name=t[1], cls=t[3], val=t[5])
+  'ParameterizedObjectSetAssignment : UCASE_IDENT ParameterList DefinedObjectClass ASSIGNMENT ObjectSet'
+  t[0] = Node('ObjectSetAssignment', name=t[1], cls=t[3].val, val=t[5])
 
 # 8.3
 def p_ParameterList (t):
@@ -6781,45 +7217,51 @@ x880_classes = {
 
 x880_syntaxes = {
   'OPERATION' : {
-    'ARGUMENT'       : 'ARGUMENT',
-    'RESULT'         : 'RESULT',         
-    'RETURN'         : 'RETURN',         
-    'ERRORS'         : 'ERRORS',         
-    'LINKED'         : 'LINKED',         
-    'SYNCHRONOUS'    : 'SYNCHRONOUS',    
-    'IDEMPOTENT'     : 'IDEMPOTENT',     
+    'ARGUMENT'       : '&ArgumentType',
+    'ARGUMENT OPTIONAL' : '&argumentTypeOptional',
+    'RESULT'         : '&ResultType',         
+    'RESULT OPTIONAL' : '&resultTypeOptional',         
+    'RETURN'         : 'RETURN',
+    'RETURN RESULT'  : '&returnResult',
+    'ERRORS'         : '&Errors',         
+    'LINKED'         : '&Linked',         
+    'SYNCHRONOUS'    : '&synchronous',    
+    'IDEMPOTENT'     : '&idempotent',     
     'ALWAYS'         : 'ALWAYS',         
-    'RESPONDS'       : 'RESPONDS',       
+    'RESPONDS'       : 'RESPONDS',
+    'ALWAYS RESPONDS' : '&alwaysReturns',       
     'INVOKE'         : 'INVOKE',         
-    'PRIORITY'       : 'PRIORITY',       
-    'RESULT-PRIORITY': 'RESULT-PRIORITY',
-    'CODE'           : 'CODE',           
+    'PRIORITY'       : 'PRIORITY',
+    'INVOKE PRIORITY' : '&InvokePriority',
+    'RESULT-PRIORITY': '&ResultPriority',
+    'CODE'           : '&operationCode',           
   },
   'ERROR' : {
+    'PARAMETER'      : '&ParameterType',       
+    'PARAMETER OPTIONAL' : '&parameterTypeOptional',       
+    'PRIORITY'       : '&ErrorPriority',       
+    'CODE'           : '&errorCode',           
   },
-  'OPERATION-PACKAGE' : {
-  },
-  'CONNECTION-PACKAGE' : {
-  },
-  'CONTRACT' : {
-  },
-  'ROS-OBJECT-CLASS' : {
-  },
+#  'OPERATION-PACKAGE' : {
+#  },
+#  'CONNECTION-PACKAGE' : {
+#  },
+#  'CONTRACT' : {
+#  },
+#  'ROS-OBJECT-CLASS' : {
+#  },
 }
 
-x880_syntaxes_enabled = { }
-x880_current_syntaxes = None
-
 def x880_import(name):
   if x880_syntaxes.has_key(name):
-    x880_syntaxes_enabled[name] = True
+    class_syntaxes_enabled[name] = True
+    class_syntaxes[name] = x880_syntaxes[name]
   if x880_classes.has_key(name):
     add_class_ident(name)
     for f in (x880_classes[name].keys()):
       set_type_to_class(name, f, x880_classes[name][f])
 
-def is_x880_syntax(name):
-  return False
+tokens = tokens + get_syntax_tokens(x880_syntaxes)
 
 #  {...} OID value
 #def p_lbrace_oid(t):
@@ -6849,7 +7291,7 @@ def p_braceignorebegin(t):
   'braceignorebegin : '
   global lexer
   lexer.level = 1
-  lexer.begin('braceignore')
+  lexer.push_state('braceignore')
 
 def p_rbraceignore(t):
   'rbraceignore : braceignoreend RBRACE'
@@ -6858,7 +7300,7 @@ def p_rbraceignore(t):
 def p_braceignoreend(t):
   'braceignoreend : '
   global lexer
-  lexer.begin('INITIAL')
+  lexer.pop_state()
 
 def p_error(t):
   global input_file