Пример #1
0
def remaining_source(remaining_contents_of_first_line: str,
                     following_lines: Sequence[str] = ()) -> TokenParser:
    """
    :param remaining_contents_of_first_line: Part of the first line that has not been consumed.
    :return: Source with some initial content of the first line that has been consumed.
    """
    content = '\n'.join([remaining_contents_of_first_line] + list(following_lines))
    token_stream = TokenStream(content)
    return TokenParser(token_stream)
Пример #2
0
 def _test_case__sym_ref_or_string_parser(self, parser: ParserFromTokens,
                                          tc: TC):
     # ARRANGE #
     token_stream = TokenStream(tc.source_string)
     token_parser = TokenParser(token_stream)
     expected_fragments = tc.expectation.fragments
     head_is_plain = TokenStream(tc.source_string).head.is_plain
     assertion_on_value = (_EqualsEitherOfSymbolName(
         expected_fragments[0].value)
                           if head_is_plain and len(expected_fragments) == 1
                           and expected_fragments[0].is_symbol else
                           _EqualsEitherOfStringSdv(expected_fragments))
     # ACT #
     actual = parser.parse(token_parser)
     # ASSERT #
     tc.expectation.token_stream.apply_with_message(self, token_stream,
                                                    'token_stream')
     assertion_on_value.apply_with_message(self, actual, 'fragment')
Пример #3
0
 def test_missing_argument__parse_sym_ref_or_string_sdv(self):
     parser = sut.SymbolReferenceOrStringParser(CONFIGURATION)
     with self.assertRaises(SingleInstructionInvalidArgumentException):
         parser.parse(TokenParser(TokenStream('')))
Пример #4
0
def _token_parser_of(source: str) -> TokenParser:
    return TokenParser(TokenStream(source))