scripts: Adopted Parser in csv.py

It's a bit funny, the motivation for a new Parser class came from the
success of simple regex + space munching in csv.py, but adopting Parser
in csv.py makes sense for a couple reasons:

- Consistency and better code sharing with other scripts that need to
  parse things (stack.py, prettyasserts.py?).

- Should be more efficient, since we avoid copying the entire string
  every time we chomp/slice.

  Though I don't think this really matters for the size of csv.py's
  exprs...

- No need to write every regex twice! Since Parser remembers the last
  match.
This commit is contained in:
Christopher Haster
2024-12-11 01:37:13 -06:00
parent 5d777f84ad
commit dad3367e9e
2 changed files with 115 additions and 58 deletions

View File

@@ -598,6 +598,12 @@ class Parser:
self.__class__.__name__,
self.data[self.i:self.i+32])
def __str__(self):
return self.data[self.i:]
def __len__(self):
return len(self.data) - self.i
def __bool__(self):
return self.i != len(self.data)