Ruby のツリートップを使用して Packages.gz を開こうとしていますが、キーワードと値を明確にするのに問題があります。これが私のツリートップ文法です:
grammar Debian
rule collection
entry+
end
rule entry
(tag space value)
end
rule package_details
tag value &[^$]
end
rule tag
[A-Za-z0-9\-]+ ":"
end
rule value
(!tag value_line+ "\n")+
end
rule value_line
([A-Za-z0-9 <>@()=\.\-|/,_"':])+
end
rule space
[ \t]+
end
end
そして、ここに私のサンプル入力があります:
Package: acct
Priority: optional
Section: admin
Installed-Size: 352
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Mathieu Trudel <mathieu.tl@gmail.com>
Architecture: i386
Version: 6.5.4-2ubuntu1
Depends: dpkg (>= 1.15.4) | install-info, libc6 (>= 2.4)
Filename: pool/main/a/acct/acct_6.5.4-2ubuntu1_i386.deb
Size: 111226
MD5sum: 10cba1458ace8c31169c0e9e915c9a0f
SHA1: 6c2dcdc480144a9922329cd4fa22c7d1cb83fcbb
SHA256: bf8d8bb8eef3939786a1cefc39f94079f43464b71099f4a59b61b24cafdbc010
Description: The GNU Accounting utilities for process and login accounting
GNU Accounting Utilities is a set of utilities which reports and summarizes
data about user connect times and process execution statistics.
.
"Login accounting" provides summaries of system resource usage based on connect
time, and "process accounting" provides summaries based on the commands
executed on the system.
.
The 'last' command is provided by the sysvinit package and not included here.
Homepage: http://www.gnu.org/software/acct/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 18m
これはほぼ 100% 機能しますが、URL を調べるときに失敗します。問題は、URL に ":" が含まれていることです。サンプルのホームページ エントリを編集して、「:」を「_」に置き換えると、そのまま表示されます。
これは私の最初の PEG 文法ですが、あいまいさを減らして簡潔にする必要があることがわかります。高度なドキュメントを見て、タグを次のように定義したいと思います
rule tag
!(!'\n' .) [A-Za-z0-9\-]+ ":"
end
しかし、私はそれが何をしているのか完全には理解していません。タグは、私が意味するように(改行または何も持たない)してはなりません(改行または何もない)。機微は私を逃れる...
その形式に切り替えると助けになりますか?なぜそれが一致しないのか誰かが知っていますか?