キーワードがある場合、キーワードが見つかったら、残りの行を取得して文字列として返すにはどうすればよいですか?行末に遭遇したら、その行のすべてを返します。
これが私が見ている行です:
description here is the rest of my text to collect
したがって、レクサーが説明に遭遇したときに、「収集する残りのテキストはここにあります」を文字列として返したいと思います。
次のように定義しましたが、エラーが発生しているようです。
states = (
('bcdescription', 'exclusive'),
)
def t_bcdescription(t):
r'description '
t.lexer.code_start = t.lexer.lexpos
t.lexer.level = 1
t.lexer.begin('bcdescription')
def t_bcdescription_close(t):
r'\n'
t.value = t.lexer.lexdata[t.lexer.code_start:t.lexer.lexpos+1]
t.type="BCDESCRIPTION"
t.lexer.lineno += t.valiue.count('\n')
t.lexer.begin('INITIAL')
return t
これは、返されるエラーの一部です。
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
最後に、この機能を複数のトークンに使用したい場合、どうすればそれを実現できますか?
御時間ありがとうございます