基于Predictive Parsing的ABNF语法分析器(五)——AbnfParser文法解析器之单字符的情形(如HTAB、LF、CR、SP)

先来看看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: [email protected])

    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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值