当前位置: 首页>>代码示例>>Java>>正文


Java MatcherContext.getCurrentChar方法代码示例

本文整理汇总了Java中org.parboiled.MatcherContext.getCurrentChar方法的典型用法代码示例。如果您正苦于以下问题:Java MatcherContext.getCurrentChar方法的具体用法?Java MatcherContext.getCurrentChar怎么用?Java MatcherContext.getCurrentChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.parboiled.MatcherContext的用法示例。


在下文中一共展示了MatcherContext.getCurrentChar方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: match

import org.parboiled.MatcherContext; //导入方法依赖的package包/类
@Override public boolean match(MatcherContext<Node> context) {
	char current = context.getCurrentChar();
	if (Character.isJavaIdentifierPart(current)) {
		context.advanceIndex();
		context.createNode();
		return true;
	}
	return false;
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:10,代码来源:BasicsParser.java

示例2: match

import org.parboiled.MatcherContext; //导入方法依赖的package包/类
@Override
public boolean match(MatcherContext context) {
    if (!context.fastStringMatching()) {
        return super.match(context);
    }

    Record rec = root;
    int ix = context.getCurrentIndex();
    InputBuffer buffer = context.getInputBuffer();
    char c = context.getCurrentChar();
    int endIx = -1;

    loop:
    while (true) {
        char[] chars = rec.chars;
        for (int i = 0; i < chars.length; i++) {
            if (c == chars[i]) {
                ix++;
                rec = rec.subs[i];
                if (rec == null) { // success, we complected a tree path to a leave
                    endIx = ix;
                    break loop;
                }
                if (rec.complete) { // we completed a valid match path, but continue looking for a longer match
                    endIx = ix;
                }
                c = buffer.charAt(ix);
                continue loop;
            }
        }
        // we checked all sub branches of the current node, none matched, so we are done
        break;
    }

    if (endIx == -1) return false; // we matched no complete path, so fail

    context.advanceIndex(endIx - context.getCurrentIndex());
    context.createNode();
    return true;
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:41,代码来源:FirstOfStringsMatcher.java

示例3: match

import org.parboiled.MatcherContext; //导入方法依赖的package包/类
public boolean match(MatcherContext context) {
    switch (context.getCurrentChar()) {
        case Chars.DEL_ERROR:
        case Chars.INS_ERROR:
        case Chars.RESYNC:
        case Chars.RESYNC_START:
        case Chars.RESYNC_END:
        case Chars.RESYNC_EOI:
        case Chars.EOI:
            return false;
    }
    context.advanceIndex(1);
    context.createNode();
    return true;
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:16,代码来源:AnyMatcher.java

示例4: match

import org.parboiled.MatcherContext; //导入方法依赖的package包/类
public boolean match(MatcherContext context) {
    char c = context.getCurrentChar();
    if (c != charLow && c != charUp) return false;
    context.advanceIndex(1);
    context.createNode();
    return true;
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:8,代码来源:CharIgnoreCaseMatcher.java

示例5: match

import org.parboiled.MatcherContext; //导入方法依赖的package包/类
public boolean match(MatcherContext context) {
    char c = context.getCurrentChar();
    if (c < cLow || c > cHigh) return false;

    context.advanceIndex(1);
    context.createNode();
    return true;
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:9,代码来源:CharRangeMatcher.java

示例6: match

import org.parboiled.MatcherContext; //导入方法依赖的package包/类
public boolean match(MatcherContext<?> context) {
    Matcher matcher = context.getMatcher();
    if (matcher.accept(isSingleCharMatcherVisitor)) {
        if (prepareErrorLocation(context) && matcher.match(context)) {
            if (fringeIndex < context.getCurrentIndex()) {
                fringeIndex = context.getCurrentIndex();
                lastMatchPath = context.getPath();
            }
            return true;
        }
        return false;
    }

    if (matcher.match(context)) {
        return true;
    }

    // if we didn't match we might have to resynchronize
    if (matcher instanceof SequenceMatcher) {
        switch(context.getCurrentChar()) {
            case RESYNC:
            case RESYNC_START:
            case RESYNC_EOI:
                // however we only resynchronize if we are at a RESYNC location and the matcher is a SequenceMatcher
                // that has already matched at least one character and that is a parent of the last match
                return qualifiesForResync(context) && resynchronize(context);
        }
        
        // check for timeout only on failures of sequences so as to not add too much overhead
        if (System.currentTimeMillis() - startTimeStamp > timeout) {
            throw new TimeoutException(getRootMatcher(), buffer, lastParsingResult);
        }
    }
    return false;
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:36,代码来源:RecoveringParseRunner.java

示例7: prepareErrorLocation

import org.parboiled.MatcherContext; //导入方法依赖的package包/类
private boolean prepareErrorLocation(MatcherContext context) {
    switch (context.getCurrentChar()) {
        case DEL_ERROR:
            return willMatchDelError(context);
        case INS_ERROR:
            return willMatchInsError(context);
        case RESYNC:
        case RESYNC_START:
        case RESYNC_EOI:
            return false;
        default:
            return true;
    }
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:15,代码来源:RecoveringParseRunner.java

示例8: gobbleIllegalCharacters

import org.parboiled.MatcherContext; //导入方法依赖的package包/类
private int gobbleIllegalCharacters(MatcherContext context, List<Matcher> followMatchers) {
    while_loop:
    while (true) {
        char currentChar = context.getCurrentChar();
        if (currentChar == EOI) break;
        for (Matcher followMatcher : followMatchers) {
            if (followMatcher.accept(new IsStarterCharVisitor(currentChar))) {
                break while_loop;
            }
        }
        context.advanceIndex(1);
    }
    return context.getCurrentIndex();
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:15,代码来源:RecoveringParseRunner.java

示例9: match

import org.parboiled.MatcherContext; //导入方法依赖的package包/类
public boolean match(MatcherContext context) {
    if (context.getCurrentChar() != character) return false;
    context.advanceIndex(1);
    context.createNode();
    return true;
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:7,代码来源:CharMatcher.java

示例10: resynchronize

import org.parboiled.MatcherContext; //导入方法依赖的package包/类
private boolean resynchronize(MatcherContext context) {
    context.markError();

    // create a node for the failed Sequence, taking ownership of all sub nodes created so far
    context.createNode();

    // by resyncing we flip an unmatched sequence to a matched one, so in order to keep the value stack
    // consistent we go into a special "error action mode" and execute the minimal set of actions underneath
    // the resync sequence
    rerunAndExecuteErrorActions(context);
    
    // skip over all characters that are not legal followers of the failed Sequence
    switch (context.getCurrentChar()) {
        case RESYNC:
            // this RESYNC error is the last error, we establish the length of the bad sequence and
            // change this RESYNC marker to a RESYNC_START / RESYNC_END block
            context.advanceIndex(1); // gobble RESYNC marker
            List<Matcher> followMatchers = new FollowMatchersVisitor().getFollowMatchers(context);
            int endIndex = gobbleIllegalCharacters(context, followMatchers);
            currentError.setEndIndex(endIndex);
            buffer.replaceInsertedChar(currentError.getStartIndex() - 1, RESYNC_START);
            buffer.insertChar(endIndex, RESYNC_END);
            context.advanceIndex(1); // gobble RESYNC_END marker
            break;

        case RESYNC_START:
            // a RESYNC error we have already recovered from before
            context.advanceIndex(1); // gobble RESYNC_START
            while (context.getCurrentChar() != RESYNC_END) {
                context.advanceIndex(1); // skip all characters up to the RESYNC_END
                checkState(context.getCurrentChar() != EOI); // we MUST find a RESYNC_END before EOI
            }
            context.advanceIndex(1); // gobble RESYNC_END marker
            break;
        
        case RESYNC_EOI:
            // if we are resyncing on EOI we don't swallow anything
            // we also do not have to update the currentError since we only hit this code here
            // in the final run
            break;

        default:
            throw new IllegalStateException();
    }

    return true;
}
 
开发者ID:parboiled1,项目名称:parboiled,代码行数:48,代码来源:RecoveringParseRunner.java


注:本文中的org.parboiled.MatcherContext.getCurrentChar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。