Module: SPARQL::Grammar

Defined in:
lib/sparql/grammar.rb,
lib/sparql/grammar/lexer.rb,
lib/sparql/grammar/parser.rb,
lib/sparql/grammar/version.rb

Overview

A SPARQL grammar for RDF.rb.

See Also:

Defined Under Namespace

Modules: Meta, VERSION Classes: Lexer, Parser, SPARQL_GRAMMAR

Constant Summary

METHODS =
%w(SELECT CONSTRUCT DESCRIBE ASK).map(&:to_sym)
KEYWORDS =
%w(BASE PREFIX LIMIT OFFSET DISTINCT REDUCED
ORDER BY ASC DESC FROM NAMED WHERE GRAPH
OPTIONAL UNION FILTER).map(&:to_sym).unshift(*METHODS)
FUNCTIONS =
%w(STR LANGMATCHES LANG DATATYPE BOUND sameTerm
isIRI isURI isBLANK isLITERAL REGEX).map(&:to_sym)

Class Method Summary (collapse)

Class Method Details

+ (Parser) parse(query, options = {}, &block)

Parse the given SPARQL `query` string.

Examples:

result = SPARQL::Grammar.parse("SELECT * WHERE { ?s ?p ?o }")

Raises:



39
40
41
# File 'lib/sparql/grammar.rb', line 39

def self.parse(query, options = {}, &block)
  Parser.new(query, options).parse
end

+ (Lexer) tokenize(query, options = {}) {|lexer| ... }

Tokenizes the given SPARQL `query` string.

Examples:

lexer = SPARQL::Grammar.tokenize("SELECT * WHERE { ?s ?p ?o }")
lexer.each_token do |token|
  puts token.inspect
end

Yields:

  • (lexer)

Yield Parameters:

Raises:



72
73
74
# File 'lib/sparql/grammar.rb', line 72

def self.tokenize(query, options = {}, &block)
  Lexer.tokenize(query, options, &block)
end

+ (Boolean) valid?(query, options = {})

Returns `true` if the given SPARQL `query` string is valid.

Examples:

SPARQL::Grammar.valid?("SELECT ?s WHERE { ?s ?p ?o }")  #=> true
SPARQL::Grammar.valid?("SELECT s WHERE { ?s ?p ?o }")   #=> false


53
54
55
# File 'lib/sparql/grammar.rb', line 53

def self.valid?(query, options = {})
  Parser.new(query, options).valid?
end