xpeg::bol : Element(Element:TYPE_BOL);
Begin of Line の略です。
ファイルを読み込み、先頭が”#“の行のみイテレートします。
inherit(xpeg); if (fs : FileStream("text.txt", "r")){ fs.scan(bol >> "#" >> cap(comment: any/0) >> eol){ it["comment"].p; } fs.close; }
# comment a b c def # not comment #comment2 adc
comment comment2
ファイルを読み込み、先頭が"//"の時はコメントとして、それ以外のときはそれ以外として、出力します。
Xtal側のバグなのかそもそもこういう書き方できないのかしらないけど割とうまくいかない。
inherit(xpeg); if (fs : FileStream("text.txt", "r")){ fs.scan((bol >> "//" >> cap(com: any/0) >> eol)|(bol >> cap(lin: any/0) >> eol)){ if (it["com"]){ ("comment : "~it["com"]).p; } else { // else if (it["lin"]) ("line : "~it["lin"]).p; } } fs.close; }
// comment this is not comment comment janai! // hoge
comment : comment line : this is not comment line : comment janai! // hoge