Skip to content

Commit

Permalink
symtab: Add micropython support
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Buesch <[email protected]>
  • Loading branch information
mbuesch committed Feb 8, 2020
1 parent 493b0c0 commit fa11434
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
8 changes: 6 additions & 2 deletions awlsim-symtab
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def main():

try:
if opt_infile == "-":
if isPy2Compat:
if isMicroPython:
inDataBytes = sys.stdin.read().encode(SymTabSource.COMPAT_ENCODING)
elif isPy2Compat:
inDataBytes = sys.stdin.read()
else:
inDataBytes = sys.stdin.buffer.read()
Expand Down Expand Up @@ -133,7 +135,9 @@ def main():
"%s" % (encoding, str(e)))

if opt_outfile == "-":
if isPy2Compat:
if isMicroPython:
sys.stdout.write(outDataBytes.decode(SymTabSource.COMPAT_ENCODING))
elif isPy2Compat:
sys.stdout.write(outDataBytes)
sys.stdout.flush()
else:
Expand Down
45 changes: 45 additions & 0 deletions libs/tiny_csv/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,48 @@ class Dialect(object):

def register_dialect(name, d):
pass

class reader(object):
def __init__(self, csvfile, dialect="excel", **fmtparams):
self.i = 0
self.lines = []
for line in csvfile:
elems = []
elem = []
inQuote = False
skip = 0
for i, c in enumerate(line):
if skip > 0:
skip -= 1
continue
if inQuote:
if c == '"' and not line.startswith('""', i):
inQuote = False
elif c == '"' and line.startswith('""', i):
elem.append(c)
skip = 1
else:
elem.append(c)
else:
if c == '"':
inQuote = True
elif c == ';':
elems.append("".join(elem))
elem = []
else:
elem.append(c)
if line:
elems.append("".join(elem))
self.lines.append(elems)

def __iter__(self):
self.i = 0
return self

def __next__(self):
try:
line = self.lines[self.i]
self.i += 1
return line
except IndexError:
raise StopIteration

0 comments on commit fa11434

Please sign in to comment.