Class QueryPrologLexer


  • public class QueryPrologLexer
    extends java.lang.Object
    A simple lexer that tokenizes a syntactically legal input SPARQL query string on prolog items (prefixes, base declarations, IRIs, comments, and syntactical tokens such as keywords, opening and closing brackets, and hashes).
    • Field Detail

      • IRI_PATTERN

        private static final java.util.regex.Pattern IRI_PATTERN
      • PREFIX_PATTERN

        private static final java.util.regex.Pattern PREFIX_PATTERN
      • COMMENT_PATTERN

        private static final java.util.regex.Pattern COMMENT_PATTERN
    • Constructor Detail

      • QueryPrologLexer

        public QueryPrologLexer()
    • Method Detail

      • lex

        public static java.util.List<QueryPrologLexer.Token> lex​(java.lang.String input)
        Tokenizes a syntactically legal input SPARQL query on prolog elements. The last token in the returned list is of type QueryPrologLexer.TokenType.REST_OF_QUERY and contains the SPARQL query string minus the prolog.
        Parameters:
        input - a syntactically legal SPARQL query string
        Returns:
        a list with tokens for each prolog element. If the input string is syntactically legal SPARQL, the final returned token is guaranteed to be of type QueryPrologLexer.TokenType.REST_OF_QUERY and to contain the SPARQL query string minus the prolog. If the input string is not syntactically legal SPARQL, the method will still return normally but no guarantees about the returned list are made.
      • getRestOfQueryToken

        public static QueryPrologLexer.Token getRestOfQueryToken​(java.lang.String input)
        Tokenizes the input string on prolog elements and returns the final Token. If the input string is a syntactically legal SPARQL query, this Token will be of type QueryPrologLexer.TokenType.REST_OF_QUERY and contain the query string minus prolog.
        Parameters:
        input - a syntactically legal SPARQL string
        Returns:
        if the input is syntactically legal SPARQL, a Token containing the query string without prolog. If the input is not syntactically legal, the method will still exist normally, but no guarantees are made about the returned object.
      • readComment

        private static java.lang.String readComment​(java.lang.String input,
                                                    int index)
        Reads the first comment line from the input, and returns the comment line (including the line break character) without the leading "#".
        Parameters:
        input -
        index -
        Returns:
      • readPrefix

        private static java.lang.String readPrefix​(java.lang.String input,
                                                   int index)
      • readIRI

        private static java.lang.String readIRI​(java.lang.String input,
                                                int index)