本文整理汇总了Java中org.parboiled.MatcherContext.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java MatcherContext.getPath方法的具体用法?Java MatcherContext.getPath怎么用?Java MatcherContext.getPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.parboiled.MatcherContext
的用法示例。
在下文中一共展示了MatcherContext.getPath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: match
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
public boolean match(MatcherContext context) {
boolean matched = subMatcher.getSubContext(context).runMatcher();
if (!matched) return false;
// collect all further matches as well
int lastIndex = context.getCurrentIndex();
while (subMatcher.getSubContext(context).runMatcher()) {
int currentIndex = context.getCurrentIndex();
if (currentIndex == lastIndex) {
throw new GrammarException("The inner rule of OneOrMore rule '%s' must not allow empty matches",
context.getPath());
}
lastIndex = currentIndex;
}
context.createNode();
return true;
}
示例2: match
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
public boolean match(MatcherContext context) {
checkArgNotNull(context, "context");
int lastIndex = context.getCurrentIndex();
while (subMatcher.getSubContext(context).runMatcher()) {
int currentLocation = context.getCurrentIndex();
if (currentLocation == lastIndex) {
throw new GrammarException("The inner rule of ZeroOrMore rule '%s' must not allow empty matches",
context.getPath());
}
lastIndex = currentLocation;
}
context.createNode();
return true;
}
示例3: 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;
}
示例4: print
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
private void print(MatcherContext<?> context, boolean matched) {
Position pos = context.getInputBuffer().getPosition(context.getCurrentIndex());
MatcherPath path = context.getPath();
MatcherPath prefix = lastPath != null ? path.commonPrefix(lastPath) : null;
if (prefix != null && prefix.length() > 1) getLog().receive("..(" + (prefix.length() - 1) + ")../");
getLog().receive(path.toString(prefix != null ? prefix.parent : null));
String line = context.getInputBuffer().extractLine(pos.line);
getLog().receive(", " + (matched ? "matched" : "failed") + ", cursor at " + pos.line + ':' + pos.column +
" after \"" + line.substring(0, Math.min(line.length(), pos.column - 1)) + "\"\n");
lastPath = path;
}