Пример #1
0
def test__parser__grammar_greedyuntil(seg_list, fresh_ansi_dialect):
    """Test the GreedyUntil grammar."""
    fs = KeywordSegment.make('foo')
    bs = KeywordSegment.make('bar')
    bas = KeywordSegment.make('baar')
    g0 = GreedyUntil(bs)
    g1 = GreedyUntil(fs, code_only=False)
    g2 = GreedyUntil(bas)
    c = ParseContext(dialect=fresh_ansi_dialect)
    # Greedy matching until the first item should return none
    assert not g0.match(seg_list, parse_context=c)
    # Greedy matching up to foo should return bar (as a raw!)
    assert g1.match(seg_list, parse_context=c).matched_segments == seg_list[:1]
    # Greedy matching up to baar should return bar, foo  (as a raw!)
    assert g2.match(seg_list, parse_context=c).matched_segments == seg_list[:3]
Пример #2
0
def test__parser__grammar_greedyuntil_bracketed(bracket_seg_list, fresh_ansi_dialect):
    """Test the GreedyUntil grammar with brackets."""
    fs = KeywordSegment.make('foo')
    g = GreedyUntil(fs, code_only=False)
    with RootParseContext(dialect=fresh_ansi_dialect) as ctx:
        # Check that we can make it past the brackets
        assert len(g.match(bracket_seg_list, parse_context=ctx)) == 7