Python pyparsing 模块,LineEnd() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用pyparsing.LineEnd()

项目:bank_wrangler    作者:tmerr    | 项目源码 | 文件源码
def _build_parser():
    date_literal = pp.Regex(r'(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})') \
                     .setParseAction(lambda s,l,t: schema.Date(t.year, t.month, t.day))
    dollars_literal = pp.Regex(r'\$\d+(\.\d{2})') \
                        .setParseAction(lambda s,l,t: schema.Dollars(t[0]))
    string_literal = (pp.QuotedString('"', escChar='\\') | pp.QuotedString("'", escChar='\\')) \
                     .setParseAction(lambda s,l,t: schema.String(t[0]))
    literal = date_literal | dollars_literal | string_literal

    ident = pp.Word(pp.alphas)

    match_op = pp.oneOf(operator_map.keys())
    match = ident + match_op + literal

    assign_op = pp.Literal('=')
    assign = ident + assign_op + literal

    part = (match | assign).setParseAction(lambda s,l,t: [t])
    rule = pp.delimitedList(part) + pp.LineEnd()

    return rule
项目:prlworkflows    作者:PhasesResearchLab    | 项目源码 | 文件源码
def _parse_atat_lattice(lattice_in):
    """Parse an ATAT-style `lat.in` string.

    The parsed string will be in three groups: (Coordinate system) (lattice) (atoms)
    where the atom group is split up into subgroups, each describing the position and atom name
    """
    float_number = Regex(r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?').setParseAction(lambda t: [float(t[0])])
    vector = Group(float_number + float_number + float_number)
    angles = vector
    vector_line = vector + Suppress(LineEnd())
    coord_sys = Group((vector_line + vector_line + vector_line) | (vector + angles + Suppress(LineEnd())))
    lattice = Group(vector + vector + vector)
    atom = Group(vector + Group(OneOrMore(Word(alphas + '_'))))
    atat_lattice_grammer = coord_sys + lattice + Group(OneOrMore(atom))
    # parse the input string and convert it to a POSCAR string
    return atat_lattice_grammer.parseString(lattice_in)
项目:pyagram    作者:hideshi    | 项目源码 | 文件源码
def lexical_analysis(self, src):
        string = pp.Regex('[a-zA-Z0-9_{}"=+\-*/\.:;&%@$#<>? ?-??-??-???-???????-?]+')

        blank = pp.LineStart() + pp.LineEnd()

        start = '['
        end = ']' + pp.LineEnd()

        graph_tag = pp.LineStart() + '@'
        graph = graph_tag + start + string + end

        view_tag = pp.LineStart() + '#'
        view = view_tag + start + string + end

        server_process_tag = pp.LineStart() + '$'
        server_process = server_process_tag + start + string + end

        client_process_tag = pp.LineStart() + '%'
        client_process = client_process_tag + start + string + end

        view_transition_identifier = pp.LineStart() + '-->'
        view_transition = view_transition_identifier + string

        process_transition_identifier = pp.LineStart() + '==>'
        process_transition = process_transition_identifier + string

        state_machine = pp.OneOrMore(graph | view | server_process | client_process | view_transition | process_transition | string | blank)

        return state_machine.parseString(src)