Example #1
0
def parse_alias_import_star(s):
    alias_import_star = (pseq("import") >> spc1 >> one(__ == "*") >> spc1 >>
                         pseq("as") >> spc1 >> symbolname)
    from_file = spc1 >> pseq("from") >> spc1 >> filename << spc << one(
        __ == ";")
    sym, rest < -alias_import_star(s)
    fname, _ < -from_file(rest)
    return AliasImport(fname, sym)
Example #2
0
def parse_sym_lst_import(s):
    symlst, rest < -(pseq("import") >> spc >> one(__ == "{") >> spc >>
                     parse_sym_lst << spc << one(__ == "}"))(s)
    fname, _ < -(
        spc >> pseq("from") >> spc1 >> filename << spc << one(__ == ";"))(rest)
    return SymImport(fname, symlst)
Example #3
0
def parse_alias_import_as(s):
    from_file = pseq("import") >> spc1 >> filename << spc << pseq("as")
    symname = spc1 >> symbolname << spc << one(__ == ";")
    fname, rest < -from_file(s)
    sym, _ < -symname(rest)
    return AliasImport(fname, sym)
Example #4
0
def parse_pure_import(s):
    pure_import = pseq("import") >> spc1 >> filename << spc << one(__ == ";")
    fname, rest < -pure_import(s)
    return PureImport(fname)
Example #5
0
from fpy.experimental.do import do
from fpy.debug.debug import trace

from flatsol.types import (
    Import,
    PureImport,
    AliasImport,
    Sym,
    PlainSym,
    AliasSym,
    SymImport,
    SrcFile,
)

filename = ptrans(
    one(__ == '"') >> many1(neg(__ == '"')) << one(__ == '"'),
    trans0(c2s),
)
symbolname = ptrans(
    one(or_(lambda x: x.isalpha(), of_("_"))) +
    many(one(or_(lambda x: x.isalnum(), of_("_")))),
    trans0(c2s),
)
spc1 = many1(one(__ == " "))
spc = many(one(__ == " "))


@parser
@do(Right)
def parse_pure_import(s):
    pure_import = pseq("import") >> spc1 >> filename << spc << one(__ == ";")