forked from Imagelibrary/littlefs
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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user