• Igor Dejanovic's avatar
    eolterm implementation · 923c4768
    Igor Dejanovic authored
    eolterm is a flag on repetitions that indicates that repetition should
    not continue to match beyond a newline.
    923c4768
test_eolterm.py 490 Bytes
import pytest

# Grammar
from arpeggio import ZeroOrMore, ParserPython, NonTerminal

def grammar():      return first, second
def first():        return ZeroOrMore(["a", "b"], eolterm=True)
def second():       return "a"


def test_eolterm():

    # first rule should match only first line
    # so that second rule will match "a" on the new line
    input = """a a b a b b
    a"""

    parser = ParserPython(grammar, reduce_tree=False)
    result = parser.parse(input)

    assert result