Search in sources :

Example 1 with RegexStringUtility

use of priv.bajdcc.util.lexer.regex.RegexStringUtility in project jMiniLang by bajdcc.

the class StringFilter method filter.

@Override
public RegexStringIteratorData filter(IRegexStringIterator iterator) {
    // 获取解析组件
    RegexStringUtility utility = iterator.utility();
    RegexStringIteratorData data = new RegexStringIteratorData();
    try {
        if (!iterator.available()) {
            data.kMeta = MetaType.END;
            data.chCurrent = MetaType.END.getChar();
        } else {
            data.kMeta = iterator.meta();
            data.chCurrent = iterator.current();
            iterator.next();
            if (data.kMeta == kMeta) {
                // 过滤终结符
                data.kMeta = MetaType.NULL;
            } else if (data.kMeta == MetaType.ESCAPE) {
                // 处理转义
                data.chCurrent = iterator.current();
                iterator.next();
                data.kMeta = MetaType.MUST_SAVE;
                data.chCurrent = utility.fromEscape(data.chCurrent, RegexError.ESCAPE);
            }
        }
    } catch (RegexException e) {
        System.err.println(e.getPosition() + " : " + e.getMessage());
        data.kMeta = MetaType.ERROR;
        data.chCurrent = MetaType.ERROR.getChar();
    }
    return data;
}
Also used : RegexStringUtility(priv.bajdcc.util.lexer.regex.RegexStringUtility) RegexStringIteratorData(priv.bajdcc.util.lexer.regex.RegexStringIteratorData) RegexException(priv.bajdcc.util.lexer.error.RegexException)

Example 2 with RegexStringUtility

use of priv.bajdcc.util.lexer.regex.RegexStringUtility in project jMiniLang by bajdcc.

the class StringPairFilter method filter.

@Override
public RegexStringIteratorData filter(IRegexStringIterator iterator) {
    // 获取解析组件
    RegexStringUtility utility = iterator.utility();
    RegexStringIteratorData data = new RegexStringIteratorData();
    try {
        if (!iterator.available()) {
            data.kMeta = MetaType.END;
            data.chCurrent = MetaType.END.getChar();
        } else {
            data.kMeta = iterator.meta();
            data.chCurrent = iterator.current();
            iterator.next();
            if (data.kMeta == kMetaBegin || data.kMeta == kMetaEnd) {
                // 过滤终结符
                data.kMeta = MetaType.NULL;
            } else if (data.kMeta == MetaType.ESCAPE) {
                // 处理转义
                data.chCurrent = iterator.current();
                iterator.next();
                data.kMeta = MetaType.MUST_SAVE;
                data.chCurrent = utility.fromEscape(data.chCurrent, RegexError.ESCAPE);
            }
        }
    } catch (RegexException e) {
        System.err.println(e.getPosition() + " : " + e.getMessage());
        data.kMeta = MetaType.ERROR;
        data.chCurrent = MetaType.ERROR.getChar();
    }
    return data;
}
Also used : RegexStringUtility(priv.bajdcc.util.lexer.regex.RegexStringUtility) RegexStringIteratorData(priv.bajdcc.util.lexer.regex.RegexStringIteratorData) RegexException(priv.bajdcc.util.lexer.error.RegexException)

Example 3 with RegexStringUtility

use of priv.bajdcc.util.lexer.regex.RegexStringUtility in project jMiniLang by bajdcc.

the class CharacterFilter method filter.

@Override
public RegexStringIteratorData filter(IRegexStringIterator iterator) {
    // 获取解析组件
    RegexStringUtility utility = iterator.utility();
    RegexStringIteratorData data = new RegexStringIteratorData();
    try {
        if (!iterator.available()) {
            data.kMeta = MetaType.END;
            data.chCurrent = MetaType.END.getChar();
        } else {
            data.kMeta = iterator.meta();
            data.chCurrent = iterator.current();
            iterator.next();
            if (data.kMeta == MetaType.SINGLE_QUOTE) {
                // 过滤单引号
                data.kMeta = MetaType.NULL;
            } else if (data.kMeta == MetaType.ESCAPE) {
                // 处理转义
                data.chCurrent = iterator.current();
                iterator.next();
                data.kMeta = MetaType.MUST_SAVE;
                data.chCurrent = utility.fromEscape(data.chCurrent, RegexError.ESCAPE);
            }
        }
    } catch (RegexException e) {
        System.err.println(e.getPosition() + " : " + e.getMessage());
        data.kMeta = MetaType.ERROR;
        data.chCurrent = MetaType.ERROR.getChar();
    }
    return data;
}
Also used : RegexStringUtility(priv.bajdcc.util.lexer.regex.RegexStringUtility) RegexStringIteratorData(priv.bajdcc.util.lexer.regex.RegexStringIteratorData) RegexException(priv.bajdcc.util.lexer.error.RegexException)

Aggregations

RegexException (priv.bajdcc.util.lexer.error.RegexException)3 RegexStringIteratorData (priv.bajdcc.util.lexer.regex.RegexStringIteratorData)3 RegexStringUtility (priv.bajdcc.util.lexer.regex.RegexStringUtility)3