先来看看AbnfParser类如何对ABNF文法中最简单的一些单字节符号如何进行解析,这些单字节符号包括跳格、换行、回车和空格:
/*
This file is one of the component a Context-free Grammar Parser Generator,
which accept a piece of text as the input, and generates a parser
for the inputted context-free grammar.
Copyright (C) 2013, Junbiao Pan (Email: panjunbiao@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// HTAB = %x09
protected String HTAB() throws IOException, MatchException {
// 断言下一个字符为0x09(否则抛出MatchException异常)
assertMatch(is.peek(), 0x09);
int value = is.read();
// 返回HTAB的字符串值
return String.valueOf((char)value);
}
// LF = %x0A
protected String LF() throws IOException, MatchException {
// 断言下一个字符为0x0A(否则抛出MatchException异常)
assertMatch(is.peek(), 0x0A);
int value = is.read();
// 返回换行的字符串值
return String.valueOf((char)value);
}
// CR = %x0D
protected String CR() throws IOException, MatchException {
// 断言下一个字符为0x0D(否则抛出MatchExcepti