PyParsing を使用して先頭または末尾の空白文字を削除して、コードをきれいにしようとしています。FollowedBy
文字列に一致するがそれを含まないサブクラスを利用できるため、先頭の空白を削除するのは非常に簡単でした。これで、識別文字列に続くものにも同じものが必要になります。
ここに小さな例があります:
from pyparsing import *
insource = """
annotation (Documentation(info="
<html>
<b>FOO</b>
</html>
"));
"""
# Working replacement:
HTMLStartref = OneOrMore(White(' \t\n')) + (FollowedBy(CaselessLiteral('<html>')))
## Not working because of non-existing "LeadBy"
# HTMLEndref = LeadBy(CaselessLiteral('</html>')) + OneOrMore(White(' \t\n')) + FollowedBy('"')
out = Suppress(HTMLStartref).transformString(insource)
out2 = Suppress(HTMLEndref).transformString(out)
出力として次のようになります。
>>> print out
annotation (Documentation(info="<html>
<b>FOO</b>
</html>
"));
そして取得する必要があります:
>>> print out2
annotation (Documentation(info="<html>
<b>FOO</b>
</html>"));
私はドキュメントを見ましたが、" LeadBy
" に相当するものFollowedBy
やそれを達成する方法を見つけることができませんでした。