org.antlr.v4.runtime.tree.ParseTreeProperty Java Examples

The following examples show how to use org.antlr.v4.runtime.tree.ParseTreeProperty. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserAgentTreeFlattener.java    From yauaa with Apache License 2.0 6 votes vote down vote up
/**
 * Parse the useragent and return every part that was found.
 *
 * @param userAgent The useragent instance that needs to be parsed
 * @return If the parse was valid (i.e. were there any parser errors: true=valid; false=has errors
 */
private MutableUserAgent parseIntoCleanUserAgent(MutableUserAgent userAgent) {
    if (userAgent.getUserAgentString() == null) {
        userAgent.set(SYNTAX_ERROR, "true", 1);
        return userAgent; // Cannot parse this
    }

    // Parse the userAgent into tree
    UserAgentContext userAgentContext = parseUserAgent(userAgent);

    // Walk the tree an inform the calling analyzer about all the nodes found
    state = new ParseTreeProperty<>();

    State rootState = new State(AGENT);
    rootState.calculatePath(PathType.CHILD, false);
    state.put(userAgentContext, rootState);

    if (userAgent.hasSyntaxError()) {
        inform(null, SYNTAX_ERROR, "true");
    } else {
        inform(null, SYNTAX_ERROR, "false");
    }

    ParseTreeWalker.DEFAULT.walk(this, userAgentContext);
    return userAgent;
}