def parse_pattern(text, engine, flags=0, alphabet=None): ''' Parse a standard regular expression. ''' from lepl.rxpy.compat.support import default_alphabet alphabet = default_alphabet(alphabet, text) parser_state = ParserState(alphabet=alphabet, flags=flags, refuse=engine.REFUSE, require=engine.REQUIRE) return parse(text, parser_state, SequenceBuilder)
def parse_groups(texts, engine, flags=0, alphabet=None): ''' Parse set of expressions, used to define groups for `Scanner`. ''' from lepl.rxpy.compat.support import default_alphabet if not texts: raise ValueError('Empty set of texts for scanner') alphabet = default_alphabet(alphabet, texts[0]) parser_state = ParserState(flags=flags, alphabet=alphabet, refuse=engine.REFUSE, require=engine.REQUIRE) sequence = SequenceBuilder(parser_state) for text in texts: sequence.parse_group(text) if parser_state.has_new_flags: parser_state = parser_state.clone_with_new_flags(texts[0]) sequence = SequenceBuilder(parser_state) for text in texts: sequence.parse_group(text) if parser_state.has_new_flags: raise RxpyError('Inconsistent flags') return parser_state, sequence.to_sequence().join(Match(), parser_state)