# Path: penman/_lexer.py
# PATTERNS = {
#     'COMMENT':    r'\#.*$',
#     'STRING':     r'"[^"\\]*(?:\\.[^"\\]*)*"',
#     'ALIGNMENT':  r'~(?:[a-z]\.?)?[0-9]+(?:,[0-9]+)*',
#     # ROLE cannot be made up of COLON + SYMBOL because it then becomes
#     # difficult to detect anonymous roles: (a : b) vs (a :b c)
#     'ROLE':       r':[^ \t\r\n\v\f()\/:~]*',
#     'SYMBOL':     r'[^ \t\r\n\v\f()\/:~]+',
#     'LPAREN':     r'\(',
#     'RPAREN':     r'\)',
#     'SLASH':      r'\/',  # concept (node label) role
#     'UNEXPECTED': r'[^ \t\r\n\v\f]'
# }
# PENMAN_RE = _compile('COMMENT',
#                      'STRING',
#                      'LPAREN', 'RPAREN', 'SLASH',
#                      'ROLE', 'SYMBOL', 'ALIGNMENT',
#                      'UNEXPECTED')
# TRIPLE_RE = _compile('COMMENT',
#                      'STRING',
#                      'LPAREN', 'RPAREN',
#                      'SYMBOL',
#                      'UNEXPECTED')
# def _compile(*names: str) -> Pattern[str]:
#     def __init__(self, iterator):
#     def __iter__(self):
#     def __next__(self):
#     def __bool__(self):
#     def peek(self) -> Token:
#     def next(self) -> Token:
#     def expect(self, *choices):
#     def accept(self, *choices):
#     def error(self, message: str, token=None) -> DecodeError:
# def lex(lines: Union[Iterable[str], str],
#         pattern: Union[Pattern[str], str] = None) -> TokenIterator:
# def _lex(lines: Iterable[str], regex: Pattern[str]) -> Iterator[Token]:
# class Token(NamedTuple):
# class TokenIterator(Iterator[Token]):


from penman import _lexer as lexer
    assert _lex('instance(a , alpha)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'SYMBOL', 'SYMBOL', 'RPAREN']
    assert _lex('instance(a ,alpha)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'SYMBOL', 'RPAREN']
    assert _lex('instance(a, alpha) ^ VAL(a, 1.0)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'SYMBOL', 'RPAREN',
        'SYMBOL',
        'SYMBOL', 'LPAREN', 'SYMBOL', 'SYMBOL', 'RPAREN']
    assert _lex('instance(a, 1,000)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'SYMBOL', 'RPAREN']
    assert _lex('instance(a,1,000)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'RPAREN']
    assert _lex('role(a,b) ^ role(b,c)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'RPAREN',
        'SYMBOL',
        'SYMBOL', 'LPAREN', 'SYMBOL', 'RPAREN']
    assert _lex('role(a,b)^role(b,c)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'RPAREN',
        'SYMBOL', 'LPAREN', 'SYMBOL', 'RPAREN']


def test_TokenIterator():
    pass  # TODO: write tests for expect() and accept()


def test_nonbreaking_space_issue_99():
    # https://github.com/goodmami/penman/issues/99
    assert [tok.type for tok in lexer.lex('1 2')] == ['SYMBOL', 'SYMBOL']
    assert [tok.type for tok in lexer.lex('1\t2')] == ['SYMBOL', 'SYMBOL']
    assert [tok.type for tok in lexer.lex('1\n2')] == ['SYMBOL', 'SYMBOL']

# Path: penman/_lexer.py
# PATTERNS = {
#     'COMMENT':    r'\#.*$',
#     'STRING':     r'"[^"\\]*(?:\\.[^"\\]*)*"',
#     'ALIGNMENT':  r'~(?:[a-z]\.?)?[0-9]+(?:,[0-9]+)*',
#     # ROLE cannot be made up of COLON + SYMBOL because it then becomes
#     # difficult to detect anonymous roles: (a : b) vs (a :b c)
#     'ROLE':       r':[^ \t\r\n\v\f()\/:~]*',
#     'SYMBOL':     r'[^ \t\r\n\v\f()\/:~]+',
#     'LPAREN':     r'\(',
#     'RPAREN':     r'\)',
#     'SLASH':      r'\/',  # concept (node label) role
#     'UNEXPECTED': r'[^ \t\r\n\v\f]'
# }
# PENMAN_RE = _compile('COMMENT',
#                      'STRING',
#                      'LPAREN', 'RPAREN', 'SLASH',
#                      'ROLE', 'SYMBOL', 'ALIGNMENT',
#                      'UNEXPECTED')
# TRIPLE_RE = _compile('COMMENT',
#                      'STRING',
#                      'LPAREN', 'RPAREN',
#                      'SYMBOL',
#                      'UNEXPECTED')
# def _compile(*names: str) -> Pattern[str]:
#     def __init__(self, iterator):
#     def __iter__(self):
#     def __next__(self):
#     def __bool__(self):
#     def peek(self) -> Token:
#     def next(self) -> Token:
#     def expect(self, *choices):
#     def accept(self, *choices):
#     def error(self, message: str, token=None) -> DecodeError:
# def lex(lines: Union[Iterable[str], str],
#         pattern: Union[Pattern[str], str] = None) -> TokenIterator:
# def _lex(lines: Iterable[str], regex: Pattern[str]) -> Iterator[Token]:
# class Token(NamedTuple):
# class TokenIterator(Iterator[Token]):


# Path: tests/test_lexer.py
from penman import _lexer as lexer

    assert _lex('instance(a , alpha)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'SYMBOL', 'SYMBOL', 'RPAREN']
    assert _lex('instance(a ,alpha)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'SYMBOL', 'RPAREN']
    assert _lex('instance(a, alpha) ^ VAL(a, 1.0)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'SYMBOL', 'RPAREN',
        'SYMBOL',
        'SYMBOL', 'LPAREN', 'SYMBOL', 'SYMBOL', 'RPAREN']
    assert _lex('instance(a, 1,000)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'SYMBOL', 'RPAREN']
    assert _lex('instance(a,1,000)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'RPAREN']
    assert _lex('role(a,b) ^ role(b,c)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'RPAREN',
        'SYMBOL',
        'SYMBOL', 'LPAREN', 'SYMBOL', 'RPAREN']
    assert _lex('role(a,b)^role(b,c)') == [
        'SYMBOL', 'LPAREN', 'SYMBOL', 'RPAREN',
        'SYMBOL', 'LPAREN', 'SYMBOL', 'RPAREN']


def test_TokenIterator():
    pass  # TODO: write tests for expect() and accept()


def test_nonbreaking_space_issue_99():
    # https://github.com/goodmami/penman/issues/99
    assert [tok.type for tok in lexer.lex('1 2')] == ['SYMBOL', 'SYMBOL']
    assert [tok.type for tok in lexer.lex('1\t2')] == ['SYMBOL', 'SYMBOL']
    assert [tok.type for tok in lexer.lex('1\n2')] == ['SYMBOL', 'SYMBOL']

    assert [tok.type for tok in lexer.lex('1\r2')] == ['SYMBOL', 'SYMBOL']