Exemple #1
0
 def resolve(self, symbols: SymbolTable) -> FilesSourceDdv:
     container = symbols.lookup(self._symbol_name)
     assert isinstance(container, SymbolContainer)
     sdv = container.sdv
     assert isinstance(
         sdv, FilesSourceSdv), 'Referenced symbol must be FilesSourceSdv'
     return sdv.resolve(symbols)
Exemple #2
0
 def ret_val(symbols: SymbolTable) -> StringDdv:
     container = symbols.lookup(symbol_name)
     assert isinstance(
         container,
         SymbolContainer), 'Value in Symbol Table must be SymbolContainer'
     assert container.value_type == ValueType.STRING, 'Value type must be STRING'
     return container.sdv.resolve(symbols)
Exemple #3
0
 def resolve(self, symbols: SymbolTable) -> List[StringDdv]:
     container = symbols.lookup(self._symbol_reference.name)
     ddv = container.sdv.resolve(symbols)
     if isinstance(ddv, StringDdv):
         return [ddv]
     if isinstance(ddv, PathDdv):
         return [ddvs.string_ddv_of_single_path(ddv)]
     if isinstance(ddv, ListDdv):
         return list(ddv.string_elements)
     raise TypeError('Unknown Symbol Value: ' + str(ddv))
Exemple #4
0
 def resolve(self, symbols: SymbolTable) -> List[StringValue]:
     container = symbols.lookup(self._symbol_reference.name)
     value = container.resolver.resolve(symbols)
     if isinstance(value, StringValue):
         return [value]
     if isinstance(value, FileRef):
         return [csv.string_value_of_single_file_ref(value)]
     if isinstance(value, ListValue):
         return list(value.string_value_elements)
     raise TypeError('Unknown Symbol Value: ' + str(value))
def _validate_reference(symbol_reference: su.SymbolReference,
                        symbols: SymbolTable) -> Optional[str]:
    referenced_resolver_container = symbols.lookup(symbol_reference.name)
    assert isinstance(referenced_resolver_container, SymbolContainer), \
        'Values in SymbolTable must be ResolverContainer'
    result = symbol_reference.restrictions.is_satisfied_by(symbols, symbol_reference.name,
                                                           referenced_resolver_container)
    if result is None:
        return None
    return restriction_failures.error_message(symbol_reference.name, symbols, result)
 def resolve(self, symbols: SymbolTable) -> StringSourceDdv:
     container = symbols.lookup(self._symbol_name)
     assert isinstance(container, SymbolContainer)  # Type info for IDE
     sdv = container.sdv
     if isinstance(sdv, StringSourceSdv):
         return sdv.resolve(symbols)
     elif isinstance(sdv, StringSdv):
         return sdvs.ConstantStringStringSourceSdv(sdv).resolve(symbols)
     else:
         raise TypeError('Expected string-source or string, found: ' +
                         str(container.value_type))
Exemple #7
0
 def resolve(self, symbols: SymbolTable) -> PathDdv:
     symbol_value_2_path = _WStrRenderingValueSymbol2PathResolverVisitor(
         self._suffix_sdv, self.default_relativity, symbols)
     container = symbols.lookup(self._path_or_string_symbol.name)
     assert isinstance(
         container,
         SymbolContainer), 'Implementation consistency/SymbolContainer'
     sdv = container.sdv
     assert isinstance(
         sdv, DataTypeSdv), 'Implementation consistency/DataTypeSdv'
     return symbol_value_2_path.visit(sdv)
Exemple #8
0
def _assert_table_contains(put: unittest.TestCase,
                           table: sut.SymbolTable,
                           expected_symbol: NameAndValue):
    put.assertTrue(table.contains(expected_symbol.name),
                   'table SHOULD contain the value')
    put.assertIn(expected_symbol.name,
                 table.names_set,
                 'names set should contain the value')
    put.assertIs(expected_symbol.value,
                 table.lookup(expected_symbol.name),
                 'lookup should fins the value')
def _validate_reference(symbol_reference: SymbolReference,
                        symbols: SymbolTable) -> Optional[TextRenderer]:
    referenced_sdv_container = symbols.lookup(symbol_reference.name)
    assert isinstance(referenced_sdv_container, SymbolContainer), \
        'Values in SymbolTable must be SymbolContainer'
    result = symbol_reference.restrictions.is_satisfied_by(
        symbols, symbol_reference.name, referenced_sdv_container)
    if result is None:
        return None
    return restriction_failures.ErrorMessage(symbol_reference.name, symbols,
                                             result)
Exemple #10
0
def _assert_table_contains(put: unittest.TestCase,
                           table: sut.SymbolTable,
                           expected_symbol: NameAndValue[ASymbolTableValue]):
    put.assertTrue(table.contains(expected_symbol.name),
                   'table SHOULD contain the value')
    put.assertIn(expected_symbol.name,
                 table.names_set,
                 'names set should contain the value')
    put.assertIs(expected_symbol.value,
                 table.lookup(expected_symbol.name),
                 'lookup should fins the value')
Exemple #11
0
 def __assertions_on_reference_restrictions(self, put: unittest.TestCase,
                                            actual: PathSdv,
                                            symbols: SymbolTable):
     for idx, reference in enumerate(actual.references):
         assert isinstance(reference, SymbolReference)  # Type info for IDE
         container = symbols.lookup(reference.name)
         assert isinstance(container, SymbolContainer)
         result = reference.restrictions.is_satisfied_by(
             symbols, reference.name, container)
         put.assertIsNone(
             result,
             'Restriction on reference #{}: expects None=satisfaction'.
             format(idx))
 def resolve(self, symbols: SymbolTable) -> sv.StringFragment:
     container = symbols.lookup(self._symbol_reference.name)
     assert isinstance(container, struct.SymbolContainer), 'Value in SymTbl must be SymbolContainer'
     value_resolver = container.resolver
     assert isinstance(value_resolver, DataValueResolver), 'Value must be a DataValueResolver'
     value = value_resolver.resolve(symbols)
     if isinstance(value, sv.StringValue):
         return csv.StringValueFragment(value)
     elif isinstance(value, FileRef):
         return csv.FileRefFragment(value)
     elif isinstance(value, ListValue):
         return csv.ListValueFragment(value)
     else:
         raise TypeError('Not a {}: {}'.format(str(DataValueResolver),
                                               value))
 def resolve(self, symbols: SymbolTable) -> sv.StringFragmentDdv:
     container = symbols.lookup(self._symbol_reference.name)
     assert isinstance(
         container,
         SymbolContainer), 'Value in SymTbl must be SymbolContainer'
     value_sdv = container.sdv
     assert isinstance(value_sdv,
                       DataTypeSdv), 'Value must be a DataTypeSdv'
     value = value_sdv.resolve(symbols)
     if isinstance(value, sv.StringDdv):
         return csv.StringDdvFragmentDdv(value)
     elif isinstance(value, PathDdv):
         return csv.PathFragmentDdv(value)
     elif isinstance(value, ListDdv):
         return csv.ListFragmentDdv(value)
     else:
         raise TypeError('Not a {}: {}'.format(str(DataTypeSdv), value))
def _validate_symbol_definition(symbol_table: SymbolTable,
                                definition: su.SymbolDefinition,
                                ) -> Optional[PartialInstructionControlledFailureInfo]:
    if symbol_table.contains(definition.name):
        already_defined_resolver_container = symbol_table.lookup(definition.name)
        assert isinstance(already_defined_resolver_container, SymbolContainer), \
            'Value in SymTbl must be ResolverContainer'
        return PartialInstructionControlledFailureInfo(
            PartialControlledFailureEnum.VALIDATION_ERROR,
            error_messages.duplicate_symbol_definition(already_defined_resolver_container.source_location,
                                                       definition.name))
    else:
        for referenced_value in definition.references:
            failure_info = validate_symbol_usage(referenced_value, symbol_table)
            if failure_info is not None:
                return failure_info
        symbol_table.add(definition.symbol_table_entry)
        return None
 def _check_indirect(self,
                     symbol_table: SymbolTable,
                     path_to_referring_symbol: tuple,
                     references: list) -> FailureOfIndirectReference:
     for reference in references:
         container = symbol_table.lookup(reference.name)
         result = self._indirect.is_satisfied_by(symbol_table, reference.name, container)
         if result is not None:
             return FailureOfIndirectReference(
                 failing_symbol=reference.name,
                 path_to_failing_symbol=list(path_to_referring_symbol),
                 error=result,
                 meaning_of_failure=self._meaning_of_failure_of_indirect_reference)
         result = self._check_indirect(symbol_table,
                                       path_to_referring_symbol + (reference.name,),
                                       container.resolver.references)
         if result is not None:
             return result
     return None
def _validate_symbol_definition(
    symbol_table: SymbolTable,
    definition: SymbolDefinition,
) -> Optional[PartialInstructionControlledFailureInfo]:
    if symbol_table.contains(definition.name):
        already_defined_sdv_container = symbol_table.lookup(definition.name)
        assert isinstance(already_defined_sdv_container, SymbolContainer), \
            'Value in SymTbl must be ResolverContainer'
        return PartialInstructionControlledFailureInfo(
            PartialControlledFailureEnum.VALIDATION_ERROR,
            error_messages.duplicate_symbol_definition(
                already_defined_sdv_container.source_location,
                definition.name))
    else:
        for referenced_value in definition.references:
            failure_info = validate_symbol_usage(referenced_value,
                                                 symbol_table)
            if failure_info is not None:
                return failure_info
        symbol_table.add(definition.symbol_table_entry)
        return None
 def _check_indirect(
     self, symbol_table: SymbolTable, path_to_referring_symbol: tuple,
     references: Sequence[SymbolReference]
 ) -> Optional[FailureOfIndirectReference]:
     for reference in references:
         container = symbol_table.lookup(reference.name)
         assert isinstance(container, SymbolContainer)  # Type info for IDE
         result = self._indirect.is_satisfied_by(symbol_table,
                                                 reference.name, container)
         if result is not None:
             return FailureOfIndirectReference(
                 failing_symbol=reference.name,
                 path_to_failing_symbol=list(path_to_referring_symbol),
                 error=result,
                 meaning_of_failure=self.
                 _meaning_of_failure_of_indirect_reference)
         result = self._check_indirect(
             symbol_table, path_to_referring_symbol + (reference.name, ),
             container.sdv.references)
         if result is not None:
             return result
     return None
Exemple #18
0
def lookup_container(symbols: SymbolTable, name: str) -> SymbolContainer:
    container = symbols.lookup(name)
    assert isinstance(
        container, SymbolContainer), 'Value in SymTbl must be SymbolContainer'
    return container
 def ret_val(symbols: SymbolTable) -> StringValue:
     container = symbols.lookup(symbol_name)
     assert isinstance(container, SymbolContainer), 'Value in SymTbl must be SymbolContainer'
     return container.resolver.resolve(symbols)
Exemple #20
0
def lookup_container(symbols: SymbolTable, name: str) -> SymbolContainer:
    container = symbols.lookup(name)
    assert isinstance(container, SymbolContainer), 'Value in SymTbl must be SymbolContainer'
    return container