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

本文介绍基于Predictive Parsing的ABNF语法分析器中,针对单字符如HTAB、LF、CR、SP的解析实现,这些函数在匹配时无需前瞻。同时,补充了VCHAR方法,该方法验证字符是否在0x21-0x7E范围内。文章还提及了相关的单元测试和系列文章索引。
摘要由CSDN通过智能技术生成
先来看看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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值