Package org.parboiled.matchers

Examples of org.parboiled.matchers.Matcher


            return matched;
        }

        public boolean match(MatcherContext<?> context) {
            long timeStamp = System.nanoTime();
            Matcher matcher = context.getMatcher();
            RuleStats ruleStats = ((RuleStats) matcher.getTag());
            int pos = context.getCurrentIndex();

            int subMatches = -++totalMatches;
            int matchSubs = ruleStats.matchSubs;
            int rematchSubs = ruleStats.rematchSubs;
            int mismatchSubs = ruleStats.mismatchSubs;
            int remismatchSubs = ruleStats.remismatchSubs;

            long time = System.nanoTime();
            timeCorrection += time - timeStamp;
            timeStamp = time - timeCorrection;

            boolean matched = matcher.match(context);

            time = System.nanoTime();
            ruleStats.nanoTime += time - timeCorrection - timeStamp;
            timeStamp = time;
View Full Code Here


            return matched;
        }

        public boolean match(MatcherContext<?> context) {
            long timeStamp = System.nanoTime();
            Matcher matcher = context.getMatcher();
            RuleStats ruleStats = ((RuleStats) matcher.getTag());
            int pos = context.getCurrentIndex();

            int subMatches = -++totalMatches;
            int matchSubs = ruleStats.matchSubs;
            int rematchSubs = ruleStats.rematchSubs;
            int mismatchSubs = ruleStats.mismatchSubs;
            int remismatchSubs = ruleStats.remismatchSubs;

            long time = System.nanoTime();
            timeCorrection += time - timeStamp;
            timeStamp = time - timeCorrection;

            boolean matched = matcher.match(context);

            time = System.nanoTime();
            ruleStats.nanoTime += time - timeCorrection - timeStamp;
            timeStamp = time;
View Full Code Here

            return rootContext.runMatcher();
        }

        @SuppressWarnings({"unchecked"})
        public boolean match(MatcherContext<?> context) {
            Matcher matcher = context.getMatcher();
            boolean matched = matcher.match(context);
            if (filter.apply(new Tuple2<Context<?>, Boolean>(context, matched))) {
                print(context, matched);
            }
            return matched;
        }
View Full Code Here

    public static Predicate<Tuple2<Context<?>, Boolean>> rulesBelow(final Rule... rules) {
        return new Predicate<Tuple2<Context<?>, Boolean>>() {
            public boolean apply(Tuple2<Context<?>, Boolean> tuple) {
                MatcherPath path = tuple.a.getPath();
                for (Rule rule : rules) {
                    Matcher matcher = (Matcher) rule;
                    if (tuple.a.getMatcher() != matcher && path.contains(matcher)) return true;
                }
                return false;
            }
        };
View Full Code Here

     * @param path the path to the failed matcher
     * @param errorIndex        the start index of the respective parse error
     * @return the matcher whose label is best for presentation in "expected" strings
     */
    public static Matcher findProperLabelMatcher(@NotNull MatcherPath path, int errorIndex) {
        Matcher found = path.parent != null ? findProperLabelMatcher(path.parent, errorIndex) : null;
        if (found != null) return found;
        if (path.element.startIndex == errorIndex && path.element.matcher.accept(new HasCustomLabelVisitor())) {
            return path.element.matcher;
        }
        return null;
View Full Code Here

        // "original" indices we need to unapply the IndexDelta in order to be able to compare with them.
        int pathStartIndex = error.getStartIndex() - error.getIndexDelta();

        List<String> labelList = new ArrayList<String>();
        for (MatcherPath path : error.getFailedMatchers()) {
            Matcher labelMatcher = ErrorUtils.findProperLabelMatcher(path, pathStartIndex);
            if (labelMatcher == null) continue;
            String[] labels = getLabels(labelMatcher);
            for (String label : labels) {
                if (label != null && !labelList.contains(label)) {
                    labelList.add(label);
View Full Code Here

                // a sequence should never be the deepest matcher of a failed matcher path
                Preconditions.checkState(ix.get() + 1 < failedMatcherPath.length());

                // we only accept the sequence name as a good label if the failed matcher is its first child
                Matcher failedSub = failedMatcherPath.get(ix.get() + 1);
                Matcher firstSub = ProxyMatcher.unwrap(matcher.getChildren().get(0));
                return firstSub == failedSub;
            }
        };

        for (int i = commonPrefixLength; i < failedMatcherPath.length(); i++) {
            ix.set(i);
            Matcher matcher = failedMatcherPath.get(i);
            if (matcher.accept(hasProperLabelVisitor)) {
                return matcher;
            }
        }
        return null;
    }
View Full Code Here

    }

    public String getExpectedString(InvalidInputError error) {
        List<String> labelList = new ArrayList<String>();
        for (MatcherPath path : error.getFailedMatchers()) {
            Matcher labelMatcher = ErrorUtils.findProperLabelMatcher(path, error.getLastMatch());
            if (labelMatcher == null) continue;
            String[] labels = getLabels(labelMatcher);
            for (String label : labels) {
                if (label != null && !labelList.contains(label)) {
                    labelList.add(label);
View Full Code Here

TOP

Related Classes of org.parboiled.matchers.Matcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.