如果我有一个关键字,当它遇到一个关键字时,我如何才能让它只抓取行的其余部分并将其作为字符串返回?一旦遇到行尾,返回该行的所有内容。在
我要看的是:
description here is the rest of my text to collect
因此,当lexer遇到description时,我希望以字符串的形式返回“这是要收集的其余文本”
我定义了以下内容,但似乎抛出了一个错误:
^{pr2}$这是返回的错误的一部分:
File "/Users/me/Coding/wm/wm_parser/ply/lex.py", line 393, in token
raise LexError("Illegal character '%s' at index %d" % (lexdata[lexpos],lexpos), lexdata[lexpos:])
ply.lex.LexError: Illegal character ' ' at index 40
最后,如果我想为不止一个令牌使用这个功能,我该如何实现呢?在
谢谢你的时间
你的代码没有什么大问题,事实上,我只是复制你的代码并运行它,它运行得很好
结果是:
^{pr2}$所以也许你可以检查代码的其他部分
如果我想让这个功能用于多个令牌,那么您可以简单地捕获单词,当这些令牌中出现一个单词时,开始通过上面的代码捕获其余内容。在
不清楚为什么需要使用lexer/parser来完成这个任务,而不需要进一步的信息。在
相关问题 更多 >
编程相关推荐