Skip to content

Commit

Permalink
Added RDF Turtle/TriG language (#2012)
Browse files Browse the repository at this point in the history
This adds support for the RDF Turtle/TriG language.
  • Loading branch information
jakubklimek authored and RunDevelopment committed Aug 6, 2019
1 parent 7cb65ee commit 508d57a
Show file tree
Hide file tree
Showing 16 changed files with 781 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,14 @@
"require": ["clike", "markup-templating"],
"owner": "gflohr"
},
"turtle": {
"title": "Turtle",
"alias": ["trig"],
"aliasTitles": {
"trig": "TriG"
},
"owner": "jakubklimek"
},
"twig": {
"title": "Twig",
"require": "markup",
Expand Down
54 changes: 54 additions & 0 deletions components/prism-turtle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Prism.languages.turtle = {
'comment': {
pattern: /#.*/,
greedy: true
},
'multiline-string': {
pattern: /"""(?:[^"]"?"?)*"""|'''(?:[^']'?'?)*'''/,
greedy: true,
alias: 'string',
inside: {
'comment': /#.*/
}
},
'string': {
pattern: /"(?:[^\\"\r\n]|\\.)*"|'(?:[^\\'\r\n]|\\.)*'/,
greedy: true
},
'url': {
pattern: /<[^\s<>]*>/,
greedy: true,
inside: {
'punctuation': /[<>]/
}
},
'function': {
pattern: /(?:(?![-.\d\xB7])[-.\w\xB7\xC0-\uFFFD]+)?:(?:(?![-.])(?:[-.:\w\xC0-\uFFFD]|%[\da-f]{2}|\\.)+)?/i,
inside: {
'local-name': {
pattern: /([^:]*:)[\s\S]+/,
lookbehind: true
},
'prefix': {
pattern: /[\s\S]+/,
inside: {
'punctuation': /:/
}
}
}
},
'number': /[+-]?\b\d+\.?\d*(?:e[+-]?\d+)?/i,
'punctuation': /[{}.,;()[\]]|\^\^/,
'boolean': /\b(?:true|false)\b/,
'keyword': [
/(?:\ba|@prefix|@base)\b|=/,
/\b(?:graph|base|prefix)\b|=/i
],
'tag': {
'pattern': /@[a-z]+(?:-[a-z\d]+)*/i,
inside: {
'punctuation': /@/
}
}
};
Prism.languages.trig = Prism.languages['turtle'];
1 change: 1 addition & 0 deletions components/prism-turtle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions examples/prism-turtle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h2>Full example</h2>
<pre><code>@base &lt;http://example.org/&gt; .
@prefix rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
@prefix rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; .
@prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt; .
@prefix rel: &lt;http://www.perceive.net/schemas/relationship/&gt; .

GRAPH &lt;urn:myGraph&gt; {
&lt;#green-goblin&gt;
rel:enemyOf &lt;#spiderman&gt; ;
a foaf:Person ; # in the context of the Marvel universe
foaf:name "Green Goblin" .

&lt;#spiderman&gt;
rel:enemyOf &lt;#green-goblin&gt; ;
a foaf:Person ;
foaf:name "Spiderman", "Человек-паук"@ru .
}</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"px": "pcaxis",
"py": "python",
"rb": "ruby",
"trig": "turtle",
"ts": "typescript",
"t4": "t4-cs",
"vb": "visual-basic",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"tap": "TAP",
"toml": "TOML",
"tt2": "Template Toolkit 2",
"trig": "TriG",
"ts": "TypeScript",
"t4-cs": "T4 Text Templates (C#)",
"t4": "T4 Text Templates (C#)",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions tests/languages/turtle/blank-node_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<http://www.w3.org/TR/rdf-syntax-grammar> <http://purl.org/dc/elements/1.1/title> "RDF/XML Syntax Specification (Revised)" .
<http://www.w3.org/TR/rdf-syntax-grammar> <http://example.org/stuff/1.0/editor> _:bnode .
_:bnode <http://example.org/stuff/1.0/fullname> "Dave Beckett" .
_:bnode <http://example.org/stuff/1.0/homePage> <http://purl.org/net/dajobe/> .

----------------------------------------------------

[
["url", [
["punctuation", "<"],
"http://www.w3.org/TR/rdf-syntax-grammar",
["punctuation", ">"]
]],
["url", [
["punctuation", "<"],
"http://purl.org/dc/elements/1.1/title",
["punctuation", ">"]
]],
["string", "\"RDF/XML Syntax Specification (Revised)\""],
["punctuation", "."],
["url", [
["punctuation", "<"],
"http://www.w3.org/TR/rdf-syntax-grammar",
["punctuation", ">"]
]],
["url", [
["punctuation", "<"],
"http://example.org/stuff/1.0/editor",
["punctuation", ">"]
]],
["function", [
["prefix", [
"_",
["punctuation", ":"]
]],
["local-name", "bnode"]
]],
["punctuation", "."],
["function", [
["prefix", [
"_",
["punctuation", ":"]
]],
["local-name", "bnode"]
]],
["url", [
["punctuation", "<"],
"http://example.org/stuff/1.0/fullname",
["punctuation", ">"]
]],
["string", "\"Dave Beckett\""],
["punctuation", "."],
["function", [
["prefix", [
"_",
["punctuation", ":"]
]],
["local-name", "bnode"]
]],
["url", [
["punctuation", "<"],
"http://example.org/stuff/1.0/homePage",
["punctuation", ">"]
]],
["url", [
["punctuation", "<"],
"http://purl.org/net/dajobe/",
["punctuation", ">"]
]],
["punctuation", "."]
]

----------------------------------------------------

Checks blank node underscore prefixes.
Loading

0 comments on commit 508d57a

Please sign in to comment.