本文整理汇总了Java中org.parboiled.MatcherContext.getCurrentIndex方法的典型用法代码示例。如果您正苦于以下问题:Java MatcherContext.getCurrentIndex方法的具体用法?Java MatcherContext.getCurrentIndex怎么用?Java MatcherContext.getCurrentIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.parboiled.MatcherContext
的用法示例。
在下文中一共展示了MatcherContext.getCurrentIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: match
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
@Override
public <V> boolean match(MatcherContext<V> context) {
int cur = context.getCurrentIndex();
if(cur == 0) {
context.createNode();
return true;
}
InputBuffer buffer = context.getInputBuffer();
if(buffer.charAt(cur-1)=='\n') {
context.createNode();
return true;
}
return false;
}
示例2: 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;
}
示例3: match
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
@Override
public <V> boolean match(MatcherContext<V> context) {
int cur = context.getCurrentIndex();
InputBuffer buffer = context.getInputBuffer();
String content = InputBufferUtils.collectContent(buffer);
content = content.substring(cur);
Matcher m = pattern.matcher(content);
if(m.find()) {
int start = m.start();
if(start == 0) {
int end = m.end();
int delta = end - start;
context.advanceIndex(delta);
context.createNode();
return true;
} else {
return false;
}
} else {
return false;
}
}
示例4: 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;
}
示例5: match
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
public boolean match(MatcherContext context) {
int lastIndex = context.getCurrentIndex();
Object valueStackSnapshot = context.getValueStack().takeSnapshot();
if (!subMatcher.getSubContext(context).runMatcher()) return false;
// reset location, Test matchers never advance
context.setCurrentIndex(lastIndex);
// erase all value stack changes the the submatcher could have made
context.getValueStack().restoreSnapshot(valueStackSnapshot);
return true;
}
示例6: match
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
public boolean match(MatcherContext context) {
int lastIndex = context.getCurrentIndex();
Object valueStackSnapshot = context.getValueStack().takeSnapshot();
if (subMatcher.getSubContext(context).runMatcher()) return false;
// reset location, Test matchers never advance
context.setCurrentIndex(lastIndex);
// erase all value stack changes the the submatcher could have made
context.getValueStack().restoreSnapshot(valueStackSnapshot);
return true;
}
示例7: 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;
}
示例8: match
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
public boolean match(MatcherContext<?> context) {
boolean matched = inner == null && context.getMatcher().match(context) || inner != null && inner.match(context);
if (context.getCurrentIndex() == errorIndex) {
if (matched && seeking) {
seeking = false;
}
if (!matched && !seeking && context.getMatcher().accept(isSingleCharMatcherVisitor)) {
failedMatchers.add(context.getPath());
}
}
return matched;
}
示例9: 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;
}
示例10: qualifiesForResync
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
private boolean qualifiesForResync(MatcherContext context) {
if (context.getCurrentIndex() == context.getStartIndex() || !context.getPath().isPrefixOf(lastMatchPath)) {
// if we have a sequence that hasn't match anything yet or is not a prefix we might still have to
// resync on it if there is no other sequence parent anymore
MatcherContext parent = context.getParent();
while (parent != null) {
if (parent.getMatcher() instanceof SequenceMatcher) return false;
parent = parent.getParent();
}
}
return true;
}
示例11: willMatchDelError
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
private boolean willMatchDelError(MatcherContext context) {
int preSkipIndex = context.getCurrentIndex();
context.advanceIndex(2); // skip del marker char and illegal char
if (!runTestMatch(context)) {
// if we wouldn't succeed with the match do not swallow the ERROR char & Co
context.setCurrentIndex(preSkipIndex);
return false;
}
context.setStartIndex(context.getCurrentIndex());
if (context.getParent() != null) context.getParent().markError();
return true;
}
示例12: willMatchInsError
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
private boolean willMatchInsError(MatcherContext context) {
int preSkipIndex = context.getCurrentIndex();
context.advanceIndex(1); // skip ins marker char
if (!runTestMatch(context)) {
// if we wouldn't succeed with the match do not swallow the ERROR char
context.setCurrentIndex(preSkipIndex);
return false;
}
context.setStartIndex(context.getCurrentIndex());
context.markError();
return true;
}
示例13: rerunAndExecuteErrorActions
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
@SuppressWarnings( {"ConstantConditions"})
private void rerunAndExecuteErrorActions(MatcherContext context) {
// the context is for the resync action, which at this point has FAILED, i.e. ALL its sub actions haven't
// had a chance to change the value stack, even the ones having run before the actual parse error matcher
// so we need to rerun all sub matchers of the resync sequence up to the point of the parse error
// and then run the minimal set of action in "error action mode"
int savedCurrentIndex = context.getCurrentIndex();
context.setCurrentIndex(context.getStartIndex()); // restart matching the resync sequence
boolean preError = true;
for (Matcher child : context.getMatcher().getChildren()) {
if (preError && !child.getSubContext(context).runMatcher()) {
// run what will be the preceding matcher of all error actions
new EmptyMatcher().getSubContext(context).runMatcher();
context.setIntTag(1); // signal that at least one rule has run before the error actions
preError = false;
}
if (!preError) {
context.setInErrorRecovery(true);
List<ActionMatcher> errorActions = child.accept(new CollectResyncActionsVisitor());
checkState(errorActions != null);
for (ActionMatcher errorAction : errorActions) {
// execute the error actions without looking at their boolean results !!!
errorAction.getSubContext(context).runMatcher();
}
context.setInErrorRecovery(false);
}
}
context.setCurrentIndex(savedCurrentIndex);
}
示例14: 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();
}
示例15: match
import org.parboiled.MatcherContext; //导入方法依赖的package包/类
public boolean match(MatcherContext<?> context) {
if (inner == null && context.getMatcher().match(context) || inner != null && inner.match(context)) {
if (errorIndex < context.getCurrentIndex() && notTestNot(context)) {
errorIndex = context.getCurrentIndex();
}
return true;
}
return false;
}