Skip to content

Commit

Permalink
Support the 'a' keyword in SPARQL lexer (#1493)
Browse files Browse the repository at this point in the history
The case-sensitive keyword `a` is a valid keyword in SPARQL. At
present, the SPARQL lexer does not recognise it as such. This commit
fixes that error (the rule is similar to the one used in the Turtle lexer).
  • Loading branch information
pyrmont committed May 12, 2020
1 parent 6266fc7 commit c68336e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/rouge/lexers/sparql.rb
Expand Up @@ -35,20 +35,21 @@ def self.keywords
state :root do
rule %r(\s+)m, Text::Whitespace
rule %r(#.*), Comment::Single

rule %r("""), Str::Double, :string_double_literal
rule %r("), Str::Double, :string_double
rule %r('''), Str::Single, :string_single_literal
rule %r('), Str::Single, :string_single

rule %r([$?]\w+), Name::Variable
rule %r((\w*:)(\w+)?) do |m|
token Name::Namespace, m[1]
token Str::Symbol, m[2]
end
rule %r(<[^>]*>), Name::Namespace
rule %r(true|false)i, Keyword::Constant

rule %r/a\b/, Keyword

rule %r([A-Z]\w+\b)i do |m|
if self.class.builtins.include? m[0].upcase
token Name::Builtin
Expand Down Expand Up @@ -101,7 +102,7 @@ def self.keywords
end
mixin :string_single_common
end

state :string_single_literal do
rule %r(''') do
token Str::Single
Expand Down
8 changes: 8 additions & 0 deletions spec/visual/samples/sparql
Expand Up @@ -52,3 +52,11 @@ false
'''The librarian said, "Perhaps you would enjoy 'War and Peace'."'''
"""The librarian said, 'Perhaps you would enjoy "War and Peace".'"""
"\u4444 and \U88888888"

# `a` keyword
PREFIX : <http://example.org/#>
SELECT ?item ?itemLabel
WHERE
{
?item a :Test .
}

0 comments on commit c68336e

Please sign in to comment.