示例#1
0
def between_(open, close):
    open, close = sequence(open, many(space)), sequence(many(space), close)
    return lambda parser: between(open, close, parser)
示例#2
0
semi = trailing_space(char(';'))
colon = trailing_space(char(':'))
dot = trailing_space(char('.'))

sepBy_ = lambda sep: lambda parser: sepBy(parser, sep)
sepBy1_ = lambda sep: lambda parser: sepBy1(parser, sep)

semiSep = sepBy_(semi)
semiSep1 = sepBy1_(semi)

commaSep = sepBy_(comma)
commaSep1 = sepBy1_(comma)


def updateSign(sign, num):
    return num * (-1 if sign == '-' else 1)


natural = fmap(int, digits)

integer = fmap(lambda x: updateSign(*x),
               sequence(option('', oneOf('-+')), natural))

doublePos = fmap(lambda x: float(''.join(x)),
                 sequence(digits, char('.'), option('0', digits)))

double = fmap(lambda x: updateSign(*x),
              sequence(option('', oneOf('-+')), doublePos))

integerOrDouble = tryP(double) | integer
示例#3
0
def string(s):
    '''Parses a string 's'. Returns it. '''

    return syntax_tree(mkString)(sequence(*map(char, s)))
示例#4
0
def between_(open, close):
    open, close = sequence(open, many(space)), sequence(many(space), close)
    return lambda parser: between(open, close, parser)
示例#5
0


sepBy_  = lambda sep: lambda parser: sepBy(parser, sep)
sepBy1_ = lambda sep: lambda parser: sepBy1(parser, sep)

semiSep  = sepBy_(semi)
semiSep1 = sepBy1_(semi)

commaSep  = sepBy_(comma)
commaSep1 = sepBy1_(comma)



def updateSign(sign, num):
    return num * (-1 if sign == '-' else 1)


natural         = fmap(int, digits)

integer         = fmap(lambda x: updateSign(*x),
                       sequence(option('', oneOf('-+')), natural))

doublePos       = fmap(lambda x: float(''.join(x)),
                       sequence(digits, char('.'), option('0', digits)))

double          = fmap(lambda x: updateSign(*x),
                       sequence(option('', oneOf('-+')), doublePos))

integerOrDouble = tryP(double) | integer
示例#6
0
文件: char.py 项目: bmhacker/pyparsec
def string(s):
    '''Parses a string 's'. Returns it. '''

    return syntax_tree(mkString)(sequence(*map(char, s)))