Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
\documentclass{article}
\usepackage[dvipsnames]{xcolor} % https://en.wikibooks.org/wiki/LaTeX/Colors
\definecolor{LightGray}{rgb}{0.97,0.97,0.97}
\usepackage{listings} % syntax highlighting
\lstdefinelanguage{SPARQL}{
basicstyle=\small\ttfamily,
backgroundcolor=\color{LightGray},
columns=fullflexible,
breaklines=false,
sensitive=true,
% --------------------------
frame=bt,
aboveskip=1em,
belowskip=1em,
xleftmargin=.5em,
xrightmargin=.5em,
framexleftmargin=.5em,
framextopmargin=.5em,
framexbottommargin=.5em,
framexrightmargin=.5em,
% --------------------------
tabsize = 2,
showstringspaces=false,
morecomment=[l][\color{gray}]{\#}, % comments
morecomment=[n][\color{blue}]{<http}{>}, % uris
morestring=[b][\color{OliveGreen}]{\"}, % strings
% -------------------------- variables
keywordsprefix=?,
classoffset=0,
keywordstyle=\color{Sepia},
morekeywords={},
% -------------------------- prefixes
classoffset=1,
keywordstyle=\color{Purple},
morekeywords={rdf,rdfs,owl,xsd,purl},
% -------------------------- keywords
classoffset=2,
keywordstyle=\color{MidnightBlue},
morekeywords={
SELECT,CONSTRUCT,DESCRIBE,ASK,WHERE,FROM,NAMED,PREFIX,BASE,OPTIONAL,
FILTER,GRAPH,LIMIT,OFFSET,SERVICE,UNION,EXISTS,NOT,BINDINGS,MINUS,a
}
}
\begin{document}
\begin{lstlisting}[language=SPARQL]
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
# this is a comment
SELECT ?url ?name
WHERE {
?url rdf:type java:Package .
?url rdfs:label ?name .
FILTER( match(?name, "hello" ))
}
\end{lstlisting}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.