diff options
author | William Carroll <wpcarro@gmail.com> | 2022-02-28T19·59-0800 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-03-01T02·07+0000 |
commit | 88a3051ae5a0b34670a5f43c6fa30a55ad76f8f1 (patch) | |
tree | 5502eab42ce20185df45f0d486dbcc8af615aebc /users/wpcarro/scratch/simple-select/scanner.py | |
parent | 7770ccf0e3d929f0db7b58b3e21eac75bc136537 (diff) |
feat(wpcarro/simple-select): support tokenizer for query language r/3880
Support a tokenizer for a query language that looks like: ``` -fname:/W.*m/ lname:"Von Carroll" ``` Parser otw... Change-Id: I2badf14a41313ca2f75dec20adbcf9031b22ab83 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5338 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI
Diffstat (limited to 'users/wpcarro/scratch/simple-select/scanner.py')
-rw-r--r-- | users/wpcarro/scratch/simple-select/scanner.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/users/wpcarro/scratch/simple-select/scanner.py b/users/wpcarro/scratch/simple-select/scanner.py index 96704ec1ab3c..5dae68aee551 100644 --- a/users/wpcarro/scratch/simple-select/scanner.py +++ b/users/wpcarro/scratch/simple-select/scanner.py @@ -2,15 +2,15 @@ # scanner/lexer needs are peek and advance; other functions (e.g. match) are # nice-to-haves. class Scanner(object): - def __init__(self, source): + def __init__(self, chars): self.i = 0 - self.source = source + self.chars = chars def exhausted(self): - return self.i >= len(self.source) + return self.i >= len(self.chars) def peek(self, n=0): - return self.source[self.i + n] if self.i + n < len(self.source) else '\0' + return self.chars[self.i + n] if self.i in range(0, len(self.chars)) else '\0' def advance(self): result = self.peek() |