Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.assertNotEqual(succ, fail)
read = SequenceReader([1, 2, 3])
self.assertEqual(read.first, 1)
self.assertEqual(read.rest.first, 2)
self.assertEqual(str(read), 'Reader(1@0)')
self.assertEqual(str(read.rest.rest.rest), 'Reader(finished)')
read = StringReader('a b')
self.assertEqual(read.first, 'a')
self.assertEqual(read.rest.first, ' ')
self.assertEqual(str(read), 'StringReader(a@0)')
self.assertEqual(str(read.rest.rest.rest), 'StringReader(finished)')
cont = Continue(read, 40)
self.assertEqual(cont.value, 40)
self.assertEqual(str(cont), 'Continue(40, StringReader(a@0))')
back = Backtrack(read, lambda: 'no further')
self.assertEqual(back.expected[0](), 'no further')
self.assertEqual(str(back), "Backtrack(StringReader(a@0), ['no further'])")
error = ParseError('Expected a but found b at index 0')
self.assertEqual(str(error), 'Expected a but found b at index 0')
self.assertEqual(repr(error), "ParseError('Expected a but found b at index 0')")
self.assertEqual(read.first, 1)
self.assertEqual(read.rest.first, 2)
self.assertEqual(str(read), 'Reader(1@0)')
self.assertEqual(str(read.rest.rest.rest), 'Reader(finished)')
read = StringReader('a b')
self.assertEqual(read.first, 'a')
self.assertEqual(read.rest.first, ' ')
self.assertEqual(str(read), 'StringReader(a@0)')
self.assertEqual(str(read.rest.rest.rest), 'StringReader(finished)')
cont = Continue(read, 40)
self.assertEqual(cont.value, 40)
self.assertEqual(str(cont), 'Continue(40, StringReader(a@0))')
back = Backtrack(read, lambda: 'no further')
self.assertEqual(back.expected[0](), 'no further')
self.assertEqual(str(back), "Backtrack(StringReader(a@0), ['no further'])")
error = ParseError('Expected a but found b at index 0')
self.assertEqual(str(error), 'Expected a but found b at index 0')
self.assertEqual(repr(error), "ParseError('Expected a but found b at index 0')")
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
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)
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
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]',
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"',
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)
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]*'):
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)