case-insensitive-lexing: add implementation for Python2/Python3
This commit is contained in:
parent
013dca5d7d
commit
c097636a9b
|
@ -76,3 +76,4 @@ Here are implementations of `CaseChangingCharStream` in various target languages
|
||||||
* [Go](https://github.com/antlr/antlr4/blob/master/doc/resources/case_changing_stream.go)
|
* [Go](https://github.com/antlr/antlr4/blob/master/doc/resources/case_changing_stream.go)
|
||||||
* [Java](https://github.com/antlr/antlr4/blob/master/doc/resources/CaseChangingCharStream.java)
|
* [Java](https://github.com/antlr/antlr4/blob/master/doc/resources/CaseChangingCharStream.java)
|
||||||
* [JavaScript](https://github.com/antlr/antlr4/blob/master/doc/resources/CaseChangingStream.js)
|
* [JavaScript](https://github.com/antlr/antlr4/blob/master/doc/resources/CaseChangingStream.js)
|
||||||
|
* [Python2/3](https://github.com/antlr/antlr4/blob/master/doc/resources/CaseChangingStream.py)
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
class CaseChangingStream():
|
||||||
|
def __init__(self, stream, upper):
|
||||||
|
self._stream = stream
|
||||||
|
self._upper = upper
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
return self._stream.__getattribute__(name)
|
||||||
|
|
||||||
|
def LA(self, offset):
|
||||||
|
c = self._stream.LA(offset)
|
||||||
|
if c <= 0:
|
||||||
|
return c
|
||||||
|
return ord(chr(c).upper() if self._upper else chr(c).lower())
|
Loading…
Reference in New Issue