How to use the parsita.util.constant function in parsita

To help you get started, we’ve selected a few parsita examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github drhagen / parsita / examples / json.py View on Github external
from parsita import *
from parsita.util import constant

# JSON definition according to https://tools.ietf.org/html/rfc7159


class JsonStringParsers(TextParsers, whitespace=None):
    quote = lit(r'\"') > constant('"')
    reverse_solidus = lit(r'\\') > constant('\\')
    solidus = lit(r'\/') > constant('/')
    backspace = lit(r'\b') > constant('\b')
    form_feed = lit(r'\f') > constant('\f')
    line_feed = lit(r'\n') > constant('\n')
    carriage_return = lit(r'\r') > constant('\r')
    tab = lit(r'\t') > constant('\t')
    uni = reg(r'\\u([0-9a-fA-F]{4})') > (lambda x: chr(int(x.group(1), 16)))

    escaped = (quote | reverse_solidus | solidus | backspace | form_feed
               | line_feed | carriage_return | tab | uni)
    unescaped = reg(r'[\u0020-\u0021\u0023-\u005B\u005D-\U0010FFFF]+')

    string = '"' >> rep(escaped | unescaped) << '"' > ''.join


class JsonParsers(TextParsers, whitespace=r'[ \t\n\r]*'):
    number = reg(r'-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?') > float
github drhagen / parsita / examples / json.py View on Github external
from parsita import *
from parsita.util import constant

# JSON definition according to https://tools.ietf.org/html/rfc7159


class JsonStringParsers(TextParsers, whitespace=None):
    quote = lit(r'\"') > constant('"')
    reverse_solidus = lit(r'\\') > constant('\\')
    solidus = lit(r'\/') > constant('/')
    backspace = lit(r'\b') > constant('\b')
    form_feed = lit(r'\f') > constant('\f')
    line_feed = lit(r'\n') > constant('\n')
    carriage_return = lit(r'\r') > constant('\r')
    tab = lit(r'\t') > constant('\t')
    uni = reg(r'\\u([0-9a-fA-F]{4})') > (lambda x: chr(int(x.group(1), 16)))

    escaped = (quote | reverse_solidus | solidus | backspace | form_feed
               | line_feed | carriage_return | tab | uni)
    unescaped = reg(r'[\u0020-\u0021\u0023-\u005B\u005D-\U0010FFFF]+')

    string = '"' >> rep(escaped | unescaped) << '"' > ''.join


class JsonParsers(TextParsers, whitespace=r'[ \t\n\r]*'):
    number = reg(r'-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?') > float

    false = lit('false') > constant(False)
    true = lit('true') > constant(True)
    null = lit('null') > constant(None)
github drhagen / parsita / examples / json.py View on Github external
from parsita import *
from parsita.util import constant

# JSON definition according to https://tools.ietf.org/html/rfc7159


class JsonStringParsers(TextParsers, whitespace=None):
    quote = lit(r'\"') > constant('"')
    reverse_solidus = lit(r'\\') > constant('\\')
    solidus = lit(r'\/') > constant('/')
    backspace = lit(r'\b') > constant('\b')
    form_feed = lit(r'\f') > constant('\f')
    line_feed = lit(r'\n') > constant('\n')
    carriage_return = lit(r'\r') > constant('\r')
    tab = lit(r'\t') > constant('\t')
    uni = reg(r'\\u([0-9a-fA-F]{4})') > (lambda x: chr(int(x.group(1), 16)))

    escaped = (quote | reverse_solidus | solidus | backspace | form_feed
               | line_feed | carriage_return | tab | uni)
    unescaped = reg(r'[\u0020-\u0021\u0023-\u005B\u005D-\U0010FFFF]+')

    string = '"' >> rep(escaped | unescaped) << '"' > ''.join
github drhagen / parsita / examples / json.py View on Github external
tab = lit(r'\t') > constant('\t')
    uni = reg(r'\\u([0-9a-fA-F]{4})') > (lambda x: chr(int(x.group(1), 16)))

    escaped = (quote | reverse_solidus | solidus | backspace | form_feed
               | line_feed | carriage_return | tab | uni)
    unescaped = reg(r'[\u0020-\u0021\u0023-\u005B\u005D-\U0010FFFF]+')

    string = '"' >> rep(escaped | unescaped) << '"' > ''.join


class JsonParsers(TextParsers, whitespace=r'[ \t\n\r]*'):
    number = reg(r'-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?') > float

    false = lit('false') > constant(False)
    true = lit('true') > constant(True)
    null = lit('null') > constant(None)

    string = JsonStringParsers.string

    array = '[' >> repsep(value, ',') << ']'

    entry = string << ':' & value
    obj = '{' >> repsep(entry, ',') << '}' > dict

    value = number | false | true | null | string | array | obj


if __name__ == '__main__':
    strings = [
        '"name"',
        '-12.40e2',
        '[false, true, null]',
github drhagen / parsita / examples / json.py View on Github external
line_feed = lit(r'\n') > constant('\n')
    carriage_return = lit(r'\r') > constant('\r')
    tab = lit(r'\t') > constant('\t')
    uni = reg(r'\\u([0-9a-fA-F]{4})') > (lambda x: chr(int(x.group(1), 16)))

    escaped = (quote | reverse_solidus | solidus | backspace | form_feed
               | line_feed | carriage_return | tab | uni)
    unescaped = reg(r'[\u0020-\u0021\u0023-\u005B\u005D-\U0010FFFF]+')

    string = '"' >> rep(escaped | unescaped) << '"' > ''.join


class JsonParsers(TextParsers, whitespace=r'[ \t\n\r]*'):
    number = reg(r'-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?') > float

    false = lit('false') > constant(False)
    true = lit('true') > constant(True)
    null = lit('null') > constant(None)

    string = JsonStringParsers.string

    array = '[' >> repsep(value, ',') << ']'

    entry = string << ':' & value
    obj = '{' >> repsep(entry, ',') << '}' > dict

    value = number | false | true | null | string | array | obj


if __name__ == '__main__':
    strings = [
        '"name"',
github drhagen / parsita / examples / json.py View on Github external
from parsita import *
from parsita.util import constant

# JSON definition according to https://tools.ietf.org/html/rfc7159


class JsonStringParsers(TextParsers, whitespace=None):
    quote = lit(r'\"') > constant('"')
    reverse_solidus = lit(r'\\') > constant('\\')
    solidus = lit(r'\/') > constant('/')
    backspace = lit(r'\b') > constant('\b')
    form_feed = lit(r'\f') > constant('\f')
    line_feed = lit(r'\n') > constant('\n')
    carriage_return = lit(r'\r') > constant('\r')
    tab = lit(r'\t') > constant('\t')
    uni = reg(r'\\u([0-9a-fA-F]{4})') > (lambda x: chr(int(x.group(1), 16)))

    escaped = (quote | reverse_solidus | solidus | backspace | form_feed
               | line_feed | carriage_return | tab | uni)
    unescaped = reg(r'[\u0020-\u0021\u0023-\u005B\u005D-\U0010FFFF]+')

    string = '"' >> rep(escaped | unescaped) << '"' > ''.join


class JsonParsers(TextParsers, whitespace=r'[ \t\n\r]*'):
    number = reg(r'-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?') > float

    false = lit('false') > constant(False)
    true = lit('true') > constant(True)
github drhagen / parsita / examples / json.py View on Github external
from parsita import *
from parsita.util import constant

# JSON definition according to https://tools.ietf.org/html/rfc7159


class JsonStringParsers(TextParsers, whitespace=None):
    quote = lit(r'\"') > constant('"')
    reverse_solidus = lit(r'\\') > constant('\\')
    solidus = lit(r'\/') > constant('/')
    backspace = lit(r'\b') > constant('\b')
    form_feed = lit(r'\f') > constant('\f')
    line_feed = lit(r'\n') > constant('\n')
    carriage_return = lit(r'\r') > constant('\r')
    tab = lit(r'\t') > constant('\t')
    uni = reg(r'\\u([0-9a-fA-F]{4})') > (lambda x: chr(int(x.group(1), 16)))

    escaped = (quote | reverse_solidus | solidus | backspace | form_feed
               | line_feed | carriage_return | tab | uni)
    unescaped = reg(r'[\u0020-\u0021\u0023-\u005B\u005D-\U0010FFFF]+')

    string = '"' >> rep(escaped | unescaped) << '"' > ''.join


class JsonParsers(TextParsers, whitespace=r'[ \t\n\r]*'):
github drhagen / parsita / examples / json.py View on Github external
from parsita import *
from parsita.util import constant

# JSON definition according to https://tools.ietf.org/html/rfc7159


class JsonStringParsers(TextParsers, whitespace=None):
    quote = lit(r'\"') > constant('"')
    reverse_solidus = lit(r'\\') > constant('\\')
    solidus = lit(r'\/') > constant('/')
    backspace = lit(r'\b') > constant('\b')
    form_feed = lit(r'\f') > constant('\f')
    line_feed = lit(r'\n') > constant('\n')
    carriage_return = lit(r'\r') > constant('\r')
    tab = lit(r'\t') > constant('\t')
    uni = reg(r'\\u([0-9a-fA-F]{4})') > (lambda x: chr(int(x.group(1), 16)))

    escaped = (quote | reverse_solidus | solidus | backspace | form_feed
               | line_feed | carriage_return | tab | uni)
    unescaped = reg(r'[\u0020-\u0021\u0023-\u005B\u005D-\U0010FFFF]+')

    string = '"' >> rep(escaped | unescaped) << '"' > ''.join


class JsonParsers(TextParsers, whitespace=r'[ \t\n\r]*'):
    number = reg(r'-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?') > float

    false = lit('false') > constant(False)
github drhagen / parsita / examples / json.py View on Github external
carriage_return = lit(r'\r') > constant('\r')
    tab = lit(r'\t') > constant('\t')
    uni = reg(r'\\u([0-9a-fA-F]{4})') > (lambda x: chr(int(x.group(1), 16)))

    escaped = (quote | reverse_solidus | solidus | backspace | form_feed
               | line_feed | carriage_return | tab | uni)
    unescaped = reg(r'[\u0020-\u0021\u0023-\u005B\u005D-\U0010FFFF]+')

    string = '"' >> rep(escaped | unescaped) << '"' > ''.join


class JsonParsers(TextParsers, whitespace=r'[ \t\n\r]*'):
    number = reg(r'-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?') > float

    false = lit('false') > constant(False)
    true = lit('true') > constant(True)
    null = lit('null') > constant(None)

    string = JsonStringParsers.string

    array = '[' >> repsep(value, ',') << ']'

    entry = string << ':' & value
    obj = '{' >> repsep(entry, ',') << '}' > dict

    value = number | false | true | null | string | array | obj


if __name__ == '__main__':
    strings = [
        '"name"',
        '-12.40e2',
github drhagen / parsita / examples / json.py View on Github external
from parsita import *
from parsita.util import constant

# JSON definition according to https://tools.ietf.org/html/rfc7159


class JsonStringParsers(TextParsers, whitespace=None):
    quote = lit(r'\"') > constant('"')
    reverse_solidus = lit(r'\\') > constant('\\')
    solidus = lit(r'\/') > constant('/')
    backspace = lit(r'\b') > constant('\b')
    form_feed = lit(r'\f') > constant('\f')
    line_feed = lit(r'\n') > constant('\n')
    carriage_return = lit(r'\r') > constant('\r')
    tab = lit(r'\t') > constant('\t')
    uni = reg(r'\\u([0-9a-fA-F]{4})') > (lambda x: chr(int(x.group(1), 16)))

    escaped = (quote | reverse_solidus | solidus | backspace | form_feed
               | line_feed | carriage_return | tab | uni)
    unescaped = reg(r'[\u0020-\u0021\u0023-\u005B\u005D-\U0010FFFF]+')

    string = '"' >> rep(escaped | unescaped) << '"' > ''.join


class JsonParsers(TextParsers, whitespace=r'[ \t\n\r]*'):
    number = reg(r'-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][-+]?[0-9]+)?') > float

parsita

Parser combinator library for Python

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis