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; }
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; }
public boolean match(MatcherContext context) { Object valueStackSnapshot = context.getValueStack().takeSnapshot(); List<Matcher> children = getChildren(); int size = children.size(); for (int i = 0; i < size; i++) { Matcher matcher = children.get(i); // remember the current index in the context, so we can access it for building the current follower set context.setIntTag(i); if (!matcher.getSubContext(context).runMatcher()) { // rule failed, so invalidate all stack actions the rule might have done context.getValueStack().restoreSnapshot(valueStackSnapshot); return false; } } context.createNode(); return true; }
@SuppressWarnings({"unchecked"}) public <V> boolean match(MatcherContext<V> context) { if (skipInPredicates && context.inPredicate()) return true; // actions need to run in the parent context MatcherContext parentContext = context.getParent(); if (!contextAwares.isEmpty()) { for (ContextAware contextAware : contextAwares) { contextAware.setContext(parentContext); } } try { Object valueStackSnapshot = context.getValueStack().takeSnapshot(); if (!action.run(parentContext)) { // failing actions are not allowed to change the ValueStack context.getValueStack().restoreSnapshot(valueStackSnapshot); return false; } // since we initialize the actions own context only partially in getSubContext(MatcherContext) // (in order to be able to still access the previous subcontexts fields in action expressions) // we need to make sure to not accidentally advance the current index of our parent with some old // index from a previous subcontext, so we explicitly set the marker here context.setCurrentIndex(parentContext.getCurrentIndex()); return true; } catch (ActionException e) { context.getParseErrors().add(new ActionError(context.getInputBuffer(), context.getCurrentIndex(), e.getMessage(), context.getPath(), e)); return false; } }