예제 #1
0
 def test_parse_from_token_parser(self):
     parser = sut.OptionallySurroundedByParenthesesParser(
         _ParserThatRaisesException())
     for case in self.SOURCE_STR_CASES:
         token_parser = _token_parser_of(case.value)
         with self.subTest(case.name):
             with self.assertRaises(
                     SingleInstructionInvalidArgumentException):
                 parser.parse_from_token_parser(token_parser)
예제 #2
0
def program_parser(
    must_be_on_current_line: bool = False,
    exe_file_relativity: RelOptionArgumentConfiguration = pgm_syntax_elements.
    EXE_FILE_REL_OPTION_ARG_CONF,
) -> Parser[ProgramSdv]:
    parser_for_element_on_arbitrary_line = parser_opt_parens.OptionallySurroundedByParenthesesParser(
        _Parser(exe_file_relativity))
    return (CurrentLineMustNotBeEmptyExceptForSpace.of_mandatory_element(
        syntax_elements.PROGRAM_SYNTAX_ELEMENT.singular_name,
        parser_for_element_on_arbitrary_line,
    ) if must_be_on_current_line else parser_for_element_on_arbitrary_line)
예제 #3
0
    expected_source_after_parse.apply_with_message(
        put,
        source,
        'source',
    )


class _ExprWithinParenthesesAbsStx(AbstractSyntax):
    def __init__(self, plain_expt: str):
        self._plain_expt = plain_expt

    def tokenization(self) -> TokenSequence:
        return TokenSequence.sequence([
            layout.OPTIONAL_NEW_LINE,
            reserved_words.PAREN_BEGIN,
            self._plain_expt,
            layout.OPTIONAL_NEW_LINE,
            reserved_words.PAREN_END,
        ])


def _token_parser_of(source: str) -> TokenParser:
    return TokenParser(TokenStream(source))


_SUT_PARSER_OF_INT = sut.OptionallySurroundedByParenthesesParser(
    _ParserOfInt())

if __name__ == '__main__':
    unittest.TextTestRunner().run(suite())
예제 #4
0
파일: parse.py 프로젝트: emilkarlen/exactly
def string_source_parser(
    accepted_file_relativities: RelOptionsConfiguration
) -> Parser[StringSourceSdv]:
    return parser_opt_parens.OptionallySurroundedByParenthesesParser(
        _StringSourceParserWoParens(accepted_file_relativities))