From b29f31d96e2b175385cabb1ac6b26d4ad73c1013 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Wed, 3 Mar 2021 20:33:02 +0000 Subject: [PATCH] Add continuation lines. --- pyreveng/instree.py | 58 ++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/pyreveng/instree.py b/pyreveng/instree.py index da5846d..cde2503 100644 --- a/pyreveng/instree.py +++ b/pyreveng/instree.py @@ -24,37 +24,35 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. -""" -InsTree -- A class for disassembling - -This class turns a textual description close to what is typically used -for documenting CPUs into a skeleton disassembler. - - instree = * ( - (assypart (wordmap/bitmap) [pilspec]) \ - ('#' comment NL) - ) - - assypart = * (nonspacenonpipe WSP) - - delim = ' ' / '|' - - wordmap = '|' *(delim (hex|field)) '|' - - bitmap = '|' bit *(delim (field|bit)) '|' - - bit = '?' / '0' / '1' - - hex = 2* ( bit / '2' / '3' / ... 'D' / 'E' / 'F' ) - # Always upper case, at least two digits - - pilspec = '{' NL IL_specificatoin NL '}' NL - -XXX: wordmap has yet to be implemented +''' + InsTree -- A class for disassembling + ==================================== + + This is the fundamental syntax in Bill Fenner approved ABNF: + + spec = *(blankline / comment / specline) + blankline = *WSP LF + comment = *WSP "#" *(VCHAR / WSP) LF + specline = mnemonic 1*WSP operands 1*WSP wordspec 1*WSP [ pilspec ] LF + mnemonic = 1*VCHAR + operands = operand *( "," operand ) + operand = 1*( %x21-2B / %x2D-7E ) + wordspec = "|" 1*field + field = bitfield / hexfield / varfield / linebreak + bit = ( "0" / "1" / "?" ) + bitfield = bit *( " " bit ) "|" + hexfield = *WSP 1*( DIGIT / %x41-46 ) *WSP "|" + varfield = *WSP %x61-7A 1*( %x61-7A / %x30-39 / "_" ) *WSP "|" + linebreak = *WSP "&" LF *WSP "|" + pilspec = *WSP "{" LF *pillines "}" LF + pillines = (HTAB / %x20-7C / "~") 1*(WSP / VCHAR ) LF + + On top of this are other requirements, in particular the widths of fields. """ import sys +import re class UsageTrouble(Exception): pass @@ -350,6 +348,10 @@ def load_string(self, s, handler=None): i = 0 banned = False s = s.expandtabs() + + # Join continuation lines + s = re.sub("\\|\\s*&\n\\s*\\|", "|", s) + last = '' while i < len(s): @@ -468,5 +470,7 @@ def find(self, priv, adr, getmore): Foo |0 1 0 1 0 1 0 1|1 1 1 1 1 1 1 1| Foo2 |0 ? 0 1 0 1 0 1|1 1 1 1 1 1 1 1| #Foo_05 | ca | data |0 0 0 0|foo | +Foo5 |0 ? 0 1 0 1 0 1| \ + |1 1 1 1 1 1 1 1| """) IT.dump()