# Path: delphin/repp.py
# DEFAULT_TOKENIZER = r'[ \t]+'
# class REPPError(PyDelphinException):
# class REPPWarning(PyDelphinWarning):
# class REPPResult(NamedTuple):
# class REPPStep(NamedTuple):
# class _REPPOperation(object):
# class _REPPRule(_REPPOperation):
# class _REPPGroup(_REPPOperation):
# class _REPPGroupCall(_REPPOperation):
# class _REPPIterativeGroup(_REPPGroup):
# class REPP(object):
#     def _apply(self, s: str, active: Set[str]) -> Iterator[REPPStep]:
#     def apply(self, s: str, active: Iterable[str] = None) -> REPPResult:
#     def trace(
#         self, s: str, active: Iterable[str] = None, verbose: bool = False
#     ) -> _Trace:
#     def _trace(
#         self, s: str, active: Set[str], verbose: bool
#     ) -> _Trace:
#     def tokenize(
#         self,
#         s: str,
#         pattern: str = DEFAULT_TOKENIZER,
#         active: Iterable[str] = None
#     ) -> YYTokenLattice:
#     def tokenize_result(
#             self, result: REPPResult, pattern: str = DEFAULT_TOKENIZER
#     ) -> YYTokenLattice:
#     def __init__(self, pattern: str, replacement: str):
#     def __str__(self):
#     def _apply(self, s: str, active: Set[str]) -> Iterator[REPPStep]:
#     def _itermatches(
#             self, ms: Iterable[Match[str]]
#     ) -> Iterator[Tuple[int, Match[str]]]:
#     def _itersegments(
#             self, m: Match[str]
#     ) -> Iterator[Tuple[str, int, int, bool]]:
#     def __init__(
#             self, operations: List[_REPPOperation] = None, name: str = None
#     ):
#     def __repr__(self):
#     def __str__(self):
#     def _apply(self, s: str, active: Set[str]) -> Iterator[REPPStep]:
#     def __init__(self, name: str, modules: Dict[str, 'REPP']):
#     def _apply(self, s: str, active: Set[str]) -> Iterator[REPPStep]:
#     def __str__(self):
#     def _apply(self, s: str, active: Set[str]) -> Iterator[REPPStep]:
#     def __init__(
#             self,
#             name: str = None,
#             modules: Dict[str, 'REPP'] = None,
#             active: Iterable[str] = None):
#     def from_config(cls, path: PathLike, directory=None):
#     def from_file(cls, path, directory=None, modules=None, active=None):
#     def from_string(cls, s, name=None, modules=None, active=None):
#     def activate(self, mod: str) -> None:
#     def deactivate(self, mod: str) -> None:
#     def _apply(self, s: str, active: Set[str]) -> Iterator[REPPStep]:
#     def apply(self, s: str, active: Iterable[str] = None) -> REPPResult:
#     def trace(
#         self, s: str, active: Iterable[str] = None, verbose: bool = False
#     ) -> _Trace:
#     def tokenize(
#             self, s: str, pattern: str = None, active: Iterable[str] = None
#     ) -> YYTokenLattice:
#     def tokenize_result(
#             self, result: REPPResult, pattern: str = DEFAULT_TOKENIZER
#     ) -> YYTokenLattice:
# def _compile(pattern: str) -> Pattern[str]:
# def _zeromap(s: str) -> _CMap:
# def _mergemap(map1: _CMap, map2: _CMap) -> _CMap:
# def _copy_part(
#         s: str,
#         shift: int,
#         parts: List[str],
#         smap: _CMap,
#         emap: _CMap
# ) -> None:
# def _insert_part(
#         s: str,
#         w: int,
#         shift: int,
#         parts: List[str],
#         smap: _CMap,
#         emap: _CMap
# ) -> None:
# def _tokenize(result: REPPResult, pattern: str) -> List[Tuple[int, int, str]]:
# def _repp_lines(path: Path) -> List[str]:
# def _parse_repp(lines: List[str], r: REPP, directory: Path) -> None:
# def _parse_repp_group(
#     lines: List[str], r: REPP, directory: Path
# ) -> Iterator[_REPPOperation]:


import pytest
    import regex
from delphin import repp
from delphin.lnk import Lnk
        r'!(^| )([()%,])([^ ])	\1\2 \3' '\n'
        r'!([^ ])([()%,])( |$)	\1 \2\3' '\n'
        '#\n'
        '>1'
    ).tokenize('(42%),')
    assert len(x.tokens) == 5
    assert x.tokens[0].form == '('
    assert x.tokens[0].lnk == Lnk.charspan(0, 1)
    assert x.tokens[1].form == '42'
    assert x.tokens[1].lnk == Lnk.charspan(1, 3)
    assert x.tokens[2].form == '%'
    assert x.tokens[2].lnk == Lnk.charspan(3, 4)
    assert x.tokens[3].form == ')'
    assert x.tokens[3].lnk == Lnk.charspan(4, 5)
    assert x.tokens[4].form == ','
    assert x.tokens[4].lnk == Lnk.charspan(5, 6)


def test_trace():
    x = r.from_string(r'''
!(\w+)	[\1]
!\[([^\]]+)\]	*\1*
''')
    steps = list(x.trace('abc def'))
    assert len(steps) == 4
    # first rule of module
    assert isinstance(steps[0], repp.REPPStep)
    assert steps[0].input == 'abc def'
    assert steps[0].output == '[abc] [def]'
    # second rule of module

# Path: delphin/repp.py
# DEFAULT_TOKENIZER = r'[ \t]+'
# class REPPError(PyDelphinException):
# class REPPWarning(PyDelphinWarning):
# class REPPResult(NamedTuple):
# class REPPStep(NamedTuple):
# class _REPPOperation(object):
# class _REPPRule(_REPPOperation):
# class _REPPGroup(_REPPOperation):
# class _REPPGroupCall(_REPPOperation):
# class _REPPIterativeGroup(_REPPGroup):
# class REPP(object):
#     def _apply(self, s: str, active: Set[str]) -> Iterator[REPPStep]:
#     def apply(self, s: str, active: Iterable[str] = None) -> REPPResult:
#     def trace(
#         self, s: str, active: Iterable[str] = None, verbose: bool = False
#     ) -> _Trace:
#     def _trace(
#         self, s: str, active: Set[str], verbose: bool
#     ) -> _Trace:
#     def tokenize(
#         self,
#         s: str,
#         pattern: str = DEFAULT_TOKENIZER,
#         active: Iterable[str] = None
#     ) -> YYTokenLattice:
#     def tokenize_result(
#             self, result: REPPResult, pattern: str = DEFAULT_TOKENIZER
#     ) -> YYTokenLattice:
#     def __init__(self, pattern: str, replacement: str):
#     def __str__(self):
#     def _apply(self, s: str, active: Set[str]) -> Iterator[REPPStep]:
#     def _itermatches(
#             self, ms: Iterable[Match[str]]
#     ) -> Iterator[Tuple[int, Match[str]]]:
#     def _itersegments(
#             self, m: Match[str]
#     ) -> Iterator[Tuple[str, int, int, bool]]:
#     def __init__(
#             self, operations: List[_REPPOperation] = None, name: str = None
#     ):
#     def __repr__(self):
#     def __str__(self):
#     def _apply(self, s: str, active: Set[str]) -> Iterator[REPPStep]:
#     def __init__(self, name: str, modules: Dict[str, 'REPP']):
#     def _apply(self, s: str, active: Set[str]) -> Iterator[REPPStep]:
#     def __str__(self):
#     def _apply(self, s: str, active: Set[str]) -> Iterator[REPPStep]:
#     def __init__(
#             self,
#             name: str = None,
#             modules: Dict[str, 'REPP'] = None,
#             active: Iterable[str] = None):
#     def from_config(cls, path: PathLike, directory=None):
#     def from_file(cls, path, directory=None, modules=None, active=None):
#     def from_string(cls, s, name=None, modules=None, active=None):
#     def activate(self, mod: str) -> None:
#     def deactivate(self, mod: str) -> None:
#     def _apply(self, s: str, active: Set[str]) -> Iterator[REPPStep]:
#     def apply(self, s: str, active: Iterable[str] = None) -> REPPResult:
#     def trace(
#         self, s: str, active: Iterable[str] = None, verbose: bool = False
#     ) -> _Trace:
#     def tokenize(
#             self, s: str, pattern: str = None, active: Iterable[str] = None
#     ) -> YYTokenLattice:
#     def tokenize_result(
#             self, result: REPPResult, pattern: str = DEFAULT_TOKENIZER
#     ) -> YYTokenLattice:
# def _compile(pattern: str) -> Pattern[str]:
# def _zeromap(s: str) -> _CMap:
# def _mergemap(map1: _CMap, map2: _CMap) -> _CMap:
# def _copy_part(
#         s: str,
#         shift: int,
#         parts: List[str],
#         smap: _CMap,
#         emap: _CMap
# ) -> None:
# def _insert_part(
#         s: str,
#         w: int,
#         shift: int,
#         parts: List[str],
#         smap: _CMap,
#         emap: _CMap
# ) -> None:
# def _tokenize(result: REPPResult, pattern: str) -> List[Tuple[int, int, str]]:
# def _repp_lines(path: Path) -> List[str]:
# def _parse_repp(lines: List[str], r: REPP, directory: Path) -> None:
# def _parse_repp_group(
#     lines: List[str], r: REPP, directory: Path
# ) -> Iterator[_REPPOperation]:


# Path: tests/repp_test.py
import pytest
    import regex
from delphin import repp
from delphin.lnk import Lnk

        r'!(^| )([()%,])([^ ])	\1\2 \3' '\n'
        r'!([^ ])([()%,])( |$)	\1 \2\3' '\n'
        '#\n'
        '>1'
    ).tokenize('(42%),')
    assert len(x.tokens) == 5
    assert x.tokens[0].form == '('
    assert x.tokens[0].lnk == Lnk.charspan(0, 1)
    assert x.tokens[1].form == '42'
    assert x.tokens[1].lnk == Lnk.charspan(1, 3)
    assert x.tokens[2].form == '%'
    assert x.tokens[2].lnk == Lnk.charspan(3, 4)
    assert x.tokens[3].form == ')'
    assert x.tokens[3].lnk == Lnk.charspan(4, 5)
    assert x.tokens[4].form == ','
    assert x.tokens[4].lnk == Lnk.charspan(5, 6)


def test_trace():
    x = r.from_string(r'''
!(\w+)	[\1]
!\[([^\]]+)\]	*\1*
''')
    steps = list(x.trace('abc def'))
    assert len(steps) == 4
    # first rule of module
    assert isinstance(steps[0], repp.REPPStep)
    assert steps[0].input == 'abc def'
    assert steps[0].output == '[abc] [def]'
    # second rule of module

    assert isinstance(steps[1], repp.REPPStep)