TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Sexy Lexing with Python

37 点作者 rogercosseboom超过 16 年前

2 条评论

tdavis大约 16 年前
Correct me if I'm wrong, but isn't this a bit like reinventing the wheel when PLY is around? <a href="http://www.dabeaz.com/ply/" rel="nofollow">http://www.dabeaz.com/ply/</a><p>There's another popular library that escapes me, too.
blinks大约 16 年前
I wrote one of these a while back: <a href="http://knot.appspot.com/e/simple-python-scanner" rel="nofollow">http://knot.appspot.com/e/simple-python-scanner</a><p>For his example, it needs one more line:<p><pre><code> simple = Scan( IDENTIFIER = r'[\w_]\w*', OPERATOR = r'[-+\*=]', DIGIT = r'\d+(\.\d+)?', END_STATEMENT = r';', SPACE = r'\s+', ) simple.ignore('SPACE') simple('foo = 5 * 30; bar = bar - 60;') # generates tokens.</code></pre>