def extract(grammar, inputdata, fixed_start = False, return_first=False):
    """
    Receives a sequence and a grammar, 
    returns a list of PositionTokens with all of the parts of the sequence that 
    are recognized by the grammar
    """
    if not inputdata:
        return []
    checker = checker_factory(grammar)

    totallen = len(inputdata)
    from pydsl.grammar.PEG import Choice
    try:
        maxl = grammar.maxsize or totallen
    except NotImplementedError:
        maxl = totallen
    try:
        #minl = grammar.minsize #FIXME: It won't work with incompatible alphabets
        minl = 1
    except NotImplementedError:
        minl = 1
    if fixed_start:
        max_start = 1
    else:
        max_start = totallen
    result = []
    for i in range(max_start):
        for j in range(i+minl, min(i+maxl, totallen) + 1):
            slice = inputdata[i:j]
            check = checker.check(slice)
            if check:
                this_pt = PositionToken(slice, grammar, i, j)
                if return_first:
                    return this_pt
                result.append(this_pt)
    return result
def extract ( grammar , inputdata , fixed_start = False , return_first = False ) : if not inputdata : return [ ] checker = checker_factory ( grammar ) totallen = len ( inputdata ) from pydsl . grammar . PEG import Choice try : maxl = grammar . maxsize or totallen except NotImplementedError : maxl = totallen try : minl = 1 except NotImplementedError : minl = 1 if fixed_start : max_start = 1 else : max_start = totallen result = [ ] for i in range ( max_start ) : for j in range ( i + minl , min ( i + maxl , totallen ) + 1 ) : slice = inputdata [ i : j ] check = checker . check ( slice ) if check : this_pt = PositionToken ( slice , grammar , i , j ) if return_first : return this_pt result . append ( this_pt ) return result
Receives a sequence and a grammar, 
    returns a list of PositionTokens with all of the parts of the sequence that 
    are recognized by the grammar