alex / alex/rply

can't lex byte strings on Python 3

Đang mở
#55 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
391
Fork
62
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I wanted a Python 3 lexer that consumes byte strings, but this doesn't seem possible with LexerGenerator. For example, for this test program:

``` python
from rply import LexerGenerator
lg = LexerGenerator()
lg.add('NUMBER', br'\d+')
lg.add('ADD', br'\+')
lg.ignore(br'\s+')
lexer = lg.build()
for token in lexer.lex(b'1 + 1'):
print(token)
```

you get:

```
Traceback (most recent call last):
File "test.py", line 7, in
for token in lexer.lex(b'1 + 1'):
File "/usr/lib/python3/dist-packages/rply/lexer.py", line 56, in __next__
return self.next()
File "/usr/lib/python3/dist-packages/rply/lexer.py", line 46, in next
colno = self._update_pos(match)
File "/usr/lib/python3/dist-packages/rply/lexer.py", line 27, in _update_pos
self._lineno += self.s.count("\n", match.start, match.end)
TypeError: a bytes-like object is required, not 'str'
```

(I ended up writing my own lexer for unrelated reasons, so this is not a show-stopper for me, but I thought you might want to fix it.)

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.