tools/json_schema_compiler/feature_compiler.py
def _ParseKey(self, key, value, shared_values, grammar):
    """Parses the specific key according to the grammar rule for that key if it
    is present in the json value.
      key: The key to parse.
      value: The full value for this feature.
      shared_values: Set of shared vfalues associated with this feature.
      grammar: The rule for the specific key.
    """
    if key not in value:
      return
    v = value[key]

    is_all = False
    if v == 'all' and list in grammar and 'allow_all' in grammar[list]:
      assert grammar[list]['allow_all'], '`allow_all` only supports `True`.'
      v = []
      is_all = True

    if 'shared' in grammar and key in shared_values:
      self._AddKeyError(key, 'Key can be set at most once per feature.')
      return

    value_type = self._GetType(v)
    if value_type not in grammar:
      self._AddKeyError(key, 'Illegal value: "%s"' % v)
      return

    if value_type is list and not is_all and len(v) == 0:
      if 'allow_empty' in grammar[list]:
        assert grammar[list]['allow_empty'], \
               '`allow_empty` only supports `True`.'
      else:
        self._AddKeyError(key, 'List must specify at least one element.')
        return

    expected = grammar[value_type]
    expected_values = None
    enum_map = None
    if 'values' in expected:
      expected_values = expected['values']
    elif 'enum_map' in expected:
      enum_map = expected['enum_map']
      expected_values = list(enum_map)

    if is_all:
      v = copy.deepcopy(expected_values)

    expected_type = None
    if value_type is list and 'subtype' in expected:
      expected_type = expected['subtype']

    cpp_value = None
    # If this value is a list, iterate over each entry and validate. Otherwise,
    # validate the single value.
    if value_type is list:
      cpp_value = []
      for sub_value in v:
        cpp_sub_value = self._GetCheckedValue(key, expected_type,
                                              expected_values, enum_map,
                                              sub_value)
        if cpp_sub_value:
          cpp_value.append(cpp_sub_value)
      cpp_value = '{' + ','.join(cpp_value) + '}'
    else:
      cpp_value = self._GetCheckedValue(key, expected_type, expected_values,
                                        enum_map, v)

    if 'validators' in expected:
      validators = expected['validators']
      for validator, error in validators:
        if not validator(v):
          self._AddKeyError(key, error)

    if cpp_value:
      if 'shared' in grammar:
        shared_values[key] = cpp_value
      else:
        self.feature_values[key] = cpp_value
    elif key in self.feature_values:
      # If the key is empty and this feature inherited a value from its parent,
      # remove the inherited value.
      del self.feature_values[key]
Parses the specific key according to the grammar rule for that key if it
    is present in the json value.
      key: The key to parse.
      value: The full value for this feature.
      shared_values: Set of shared vfalues associated with this feature.
      grammar: The rule for the specific key.
    
Parses the specific key according to the grammar rule for that key if it
is present in the json value.
key: The key to parse.
value: The full value for this feature.
shared_values: Set of shared vfalues associated with this feature.
grammar: The rule for the specific key.
Parses the specific key according to the grammar rule for that key if it is present in the json value . key : The key to parse . value : The full value for this feature . shared_values : Set of shared vfalues associated with this feature . grammar : The rule for the specific key .
def _ParseKey(self, key, value, shared_values, grammar):
    if key not in value:
      return
    v = value[key]
    is_all = False
    if v == 'all' and list in grammar and 'allow_all' in grammar[list]:
      assert grammar[list]['allow_all'], '`allow_all` only supports `True`.'
      v = []
      is_all = True
    if 'shared' in grammar and key in shared_values:
      self._AddKeyError(key, 'Key can be set at most once per feature.')
      return
    value_type = self._GetType(v)
    if value_type not in grammar:
      self._AddKeyError(key, 'Illegal value: "%s"' % v)
      return
    if value_type is list and not is_all and len(v) == 0:
      if 'allow_empty' in grammar[list]:
        assert grammar[list]['allow_empty'], \
               '`allow_empty` only supports `True`.'
      else:
        self._AddKeyError(key, 'List must specify at least one element.')
        return
    expected = grammar[value_type]
    expected_values = None
    enum_map = None
    if 'values' in expected:
      expected_values = expected['values']
    elif 'enum_map' in expected:
      enum_map = expected['enum_map']
      expected_values = list(enum_map)
    if is_all:
      v = copy.deepcopy(expected_values)
    expected_type = None
    if value_type is list and 'subtype' in expected:
      expected_type = expected['subtype']
    cpp_value = None
    if value_type is list:
      cpp_value = []
      for sub_value in v:
        cpp_sub_value = self._GetCheckedValue(key, expected_type,
                                              expected_values, enum_map,
                                              sub_value)
        if cpp_sub_value:
          cpp_value.append(cpp_sub_value)
      cpp_value = '{' + ','.join(cpp_value) + '}'
    else:
      cpp_value = self._GetCheckedValue(key, expected_type, expected_values,
                                        enum_map, v)
    if 'validators' in expected:
      validators = expected['validators']
      for validator, error in validators:
        if not validator(v):
          self._AddKeyError(key, error)
    if cpp_value:
      if 'shared' in grammar:
        shared_values[key] = cpp_value
      else:
        self.feature_values[key] = cpp_value
    elif key in self.feature_values:
      del self.feature_values[key]
def _ParseKey ( self , key , value , shared_values , grammar ) : if key not in value : return v = value [ key ] is_all = False if v == 'all' and list in grammar and 'allow_all' in grammar [ list ] : assert grammar [ list ] [ 'allow_all' ] , '`allow_all` only supports `True`.' v = [ ] is_all = True if 'shared' in grammar and key in shared_values : self . _AddKeyError ( key , 'Key can be set at most once per feature.' ) return value_type = self . _GetType ( v ) if value_type not in grammar : self . _AddKeyError ( key , 'Illegal value: "%s"' % v ) return if value_type is list and not is_all and len ( v ) == 0 : if 'allow_empty' in grammar [ list ] : assert grammar [ list ] [ 'allow_empty' ] , '`allow_empty` only supports `True`.' else : self . _AddKeyError ( key , 'List must specify at least one element.' ) return expected = grammar [ value_type ] expected_values = None enum_map = None if 'values' in expected : expected_values = expected [ 'values' ] elif 'enum_map' in expected : enum_map = expected [ 'enum_map' ] expected_values = list ( enum_map ) if is_all : v = copy . deepcopy ( expected_values ) expected_type = None if value_type is list and 'subtype' in expected : expected_type = expected [ 'subtype' ] cpp_value = None if value_type is list : cpp_value = [ ] for sub_value in v : cpp_sub_value = self . _GetCheckedValue ( key , expected_type , expected_values , enum_map , sub_value ) if cpp_sub_value : cpp_value . append ( cpp_sub_value ) cpp_value = '{' + ',' . join ( cpp_value ) + '}' else : cpp_value = self . _GetCheckedValue ( key , expected_type , expected_values , enum_map , v ) if 'validators' in expected : validators = expected [ 'validators' ] for validator , error in validators : if not validator ( v ) : self . _AddKeyError ( key , error ) if cpp_value : if 'shared' in grammar : shared_values [ key ] = cpp_value else : self . feature_values [ key ] = cpp_value elif key in self . feature_values : del self . feature_values [ key ]
Parses the specific key according to the grammar rule for that key if it
is present in the json value.
Parses the specific key according to the grammar rule for that key if it is present in the json value .
"""Parses the specific key according to the grammar rule for that key if it
    is present in the json value.
      key: The key to parse.
      value: The full value for this feature.
      shared_values: Set of shared vfalues associated with this feature.
      grammar: The rule for the specific key.
    """ # If this value is a list, iterate over each entry and validate. Otherwise, # validate the single value. # If the key is empty and this feature inherited a value from its parent, # remove the inherited value.
self
key
value
shared_values
grammar