Package com.inrupt.client.parser


package com.inrupt.client.parser

Parsing support for the Inrupt Java Client Libraries

The Solid ecosystem relies on conformance with many different formal specifications. Consequently, many of these specifications define formal grammars as part of a protocol definition. For HTTP interactions, this principally consists of header definitions.

This module defines a formal grammar for different HTTP headers along with generated lexer and parser classes for use with processing these headers in a specification-compliant way.

The grammars in this module make use of the ANTLR tooling. From these defined grammars, Java classes are automatically generated. Convenience methods are provided at higher levels to make this parsing simple, but it is also possible to use these classes directly.

For example, parsing a WWW-Authenticate header might take this form in code:


    WwwAuthenticateLexer lexer = new WwwAuthenticateLexer(CharStreams.fromString(header));
    WwwAuthenticateParser parser = new WwwAuthenticateParser(new CommonTokenStream(lexer));
    List<Challenge> tree = parser.wwwAuthenticate();

    System.out.println(tree.toStringTree(parser));
 

Alternatively, this is an example using a custom listener:


    WwwAuthenticateLexer lexer = new WwwAuthenticateLexer(CharStreams.fromString(header));
    WwwAuthenticateParser parser = new WwwAuthenticateParser(new CommonTokenStream(lexer));
    List<Challenge> tree = parser.wwwAuthenticate();

    ParseTreeWalker walker = new ParseTreeWalker();
    MyCustomListener listener = new MyCustomListener();
    walker.walk(listener, tree);