Skip to content

Commit 75fcbff

Browse files
jakubklimektancnle
andauthored
Fix SPARQL unicode names support (fix #1653) (#1654)
* Fix SPARQL unicode names support * Update lib/rouge/lexers/sparql.rb Co-authored-by: Tan Le <tan.le@hey.com> * Update lib/rouge/lexers/sparql.rb Co-authored-by: Tan Le <tan.le@hey.com> Co-authored-by: Tan Le <tan.le@hey.com>
1 parent 8229933 commit 75fcbff

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

lib/rouge/lexers/sparql.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,17 @@ def self.keywords
4141
rule %r('''), Str::Single, :string_single_literal
4242
rule %r('), Str::Single, :string_single
4343

44-
rule %r([$?]\w+), Name::Variable
45-
rule %r((\w*:)(\w+)?) do |m|
44+
rule %r([$?][[:word:]]+), Name::Variable
45+
rule %r(([[:word:]-]*)(:)([[:word:]-]+)?) do |m|
4646
token Name::Namespace, m[1]
47-
token Str::Symbol, m[2]
47+
token Operator, m[2]
48+
token Str::Symbol, m[3]
4849
end
4950
rule %r(<[^>]*>), Name::Namespace
5051
rule %r(true|false)i, Keyword::Constant
5152
rule %r/a\b/, Keyword
5253

53-
rule %r([A-Z]\w+\b)i do |m|
54+
rule %r([A-Z][[:word:]]+\b)i do |m|
5455
if self.class.builtins.include? m[0].upcase
5556
token Name::Builtin
5657
elsif self.class.keywords.include? m[0].upcase

spec/visual/samples/sparql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,20 @@ WHERE
6060
{
6161
?item a :Test .
6262
}
63+
64+
# unicode variable names
65+
SELECT ?název_44
66+
WHERE {
67+
ovm:00025593 schema:name ?název_44 .
68+
}
69+
70+
# unicode prefixed name
71+
PREFIX podmínky-užití: <https://data.gov.cz/slovník/podmínky-užití/>
72+
SELECT ?název
73+
WHERE {
74+
?distribuce a dcat:Distribution ;
75+
podmínky-užití:specifikace ?spec .
76+
77+
?spec a podmínky-užití:Specifikace ;
78+
podmínky-užití:databáze-chráněná-zvláštními-právy ?zvláštníPrávo .
79+
}

0 commit comments

Comments
 (0)