_CONSTANTS = {
    '-Infinity': NegInf,
    'Infinity': PosInf,
    'NaN': NaN,
    'true': True,
    'false': False,
    'null': None,
}


def JSONConstant(match, context, c=_CONSTANTS):
    return c[match.group(0)], None


pattern('(-?Infinity|NaN|true|false|null)')(JSONConstant)


def JSONNumber(match, context):
    match = JSONNumber.regex.match(match.string, *match.span())
    integer, frac, exp = match.groups()
    if frac or exp:
        res = float(integer + (frac or '') + (exp or ''))
    else:
        res = int(integer)
    return res, None


pattern(r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?')(JSONNumber)

STRINGCHUNK = re.compile(r'(.*?)(["\\])', FLAGS)

def errmsg(msg, doc, pos, end=None):
    lineno, colno = linecol(doc, pos)
    if end is None:
        return '%s: line %d column %d (char %d)' % (msg, lineno, colno, pos)
    endlineno, endcolno = linecol(doc, end)
    return '%s: line %d column %d - line %d column %d (char %d - %d)' % (
        msg, lineno, colno, endlineno, endcolno, pos, end)


def JSONInfinity(match, context):
    return PosInf, None


pattern('Infinity')(JSONInfinity)


def JSONNegInfinity(match, context):
    return NegInf, None


pattern('-Infinity')(JSONNegInfinity)


def JSONNaN(match, context):
    return NaN, None


pattern('NaN')(JSONNaN)
        colno = pos
    else:
        colno = pos - doc.rindex('\n', 0, pos)
    return lineno, colno

def errmsg(msg, doc, pos, end=None):
    lineno, colno = linecol(doc, pos)
    if end is None:
        return '%s: line %d column %d (char %d)' % (msg, lineno, colno, pos)
    endlineno, endcolno = linecol(doc, end)
    return '%s: line %d column %d - line %d column %d (char %d - %d)' % (
        msg, lineno, colno, endlineno, endcolno, pos, end)

def JSONInfinity(match, context):
    return PosInf, None
pattern('Infinity')(JSONInfinity)

def JSONNegInfinity(match, context):
    return NegInf, None
pattern('-Infinity')(JSONNegInfinity)

def JSONNaN(match, context):
    return NaN, None
pattern('NaN')(JSONNaN)

def JSONTrue(match, context):
    return True, None
pattern('true')(JSONTrue)

def JSONFalse(match, context):
    return False, None
Exemple #4
0
    endlineno, endcolno = linecol(doc, end)
    return '%s: line %d column %d - line %d column %d (char %d - %d)' % (
        msg, lineno, colno, endlineno, endcolno, pos, end)

_CONSTANTS = {
    '-Infinity': NegInf,
    'Infinity': PosInf,
    'NaN': NaN,
    'true': True,
    'false': False,
    'null': None,
}

def JSONConstant(match, context, c=_CONSTANTS):
    return c[match.group(0)], None
pattern('(-?Infinity|NaN|true|false|null)')(JSONConstant)

def JSONNumber(match, context):
    match = JSONNumber.regex.match(match.string, *match.span())
    integer, frac, exp = match.groups()
    if frac or exp:
        res = float(integer + (frac or '') + (exp or ''))
    else:
        res = int(integer)
    return res, None
pattern(r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?')(JSONNumber)

STRINGCHUNK = re.compile(r'(.*?)(["\\])', FLAGS)
BACKSLASH = {
    '"': u'"', '\\': u'\\', '/': u'/',
    'b': u'\b', 'f': u'\f', 'n': u'\n', 'r': u'\r', 't': u'\t',
Exemple #5
0
        colno,
        endlineno,
        endcolno,
        pos,
        end,
    )


_CONSTANTS = {"-Infinity": NegInf, "Infinity": PosInf, "NaN": NaN, "true": True, "false": False, "null": None}


def JSONConstant(match, context, c=_CONSTANTS):
    return c[match.group(0)], None


pattern("(-?Infinity|NaN|true|false|null)")(JSONConstant)


def JSONNumber(match, context):
    match = JSONNumber.regex.match(match.string, *match.span())
    integer, frac, exp = match.groups()
    if frac or exp:
        res = float(integer + (frac or "") + (exp or ""))
    else:
        res = int(integer)
    return res, None


pattern(r"(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?")(JSONNumber)

STRINGCHUNK = re.compile(r'(.*?)(["\\])', FLAGS)