idank / bashlex

Python parser for bash
GNU General Public License v3.0
550 stars 94 forks source link

on NotImplementedError: print token #62

Closed milahu closed 2 years ago

milahu commented 2 years ago

before

NotImplementedError: pattern.

after

NotImplementedError: type = pattern. token = *o*

test

#!/usr/bin/env python

import bashlex
import sys

input = """
case foo in
  *o*) echo yes;;
  *) echo no;;
esac
"""

# workaround for https://github.com/idank/bashlex/issues/23
input = "{\n" + input + "\n}"

try:
  parts = bashlex.parse(input)
except Exception as e:
  if not hasattr(e, 'position'):
    raise e
  p = e.position
  print(input[(p - 100):p])
  print('# ERROR ' + e.message)
  print(input[p:(p + 100)])
  sys.exit(1)

for ast in parts:
  print(ast.dump())
idank commented 2 years ago

Can you please rearrange the commits? I think you just need two here (one for the tests and one for the parser).

idank commented 2 years ago

Thanks! :-)