Skip to content

Instantly share code, notes, and snippets.

@introom
Created June 22, 2013 06:01
Show Gist options
  • Save introom/5836043 to your computer and use it in GitHub Desktop.
Save introom/5836043 to your computer and use it in GitHub Desktop.
parsley obj.attr obj[index]
from parsley import makeGrammar
data = b'\x01\x013'
grammarSource = r"""
byte = anything:b1 anything:b2 -> ord(b1), ord(b2)
start = byte:b anything{b[0]}
"""
parser = makeGrammar(grammarSource, {})
ret = parser(data).start()
print(ret)
@tomprince
Copy link

from parsley import makeGrammar

data = b'\x01\x013'

grammarSource = r"""
byte = anything:b1 anything:b2 -> ord(b1), ord(b2)
start = byte:b (->b[0]):b0 anything{b0}
"""

parser = makeGrammar(grammarSource, {})
ret = parser(data).start()
print(ret)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment