I will say you have to do the same as syntax highlighter does for other language, SPARQL is nothing but a Query Language, with its keywords from W3.org we can identify the keywords that is required to highlight,
For Example Simple Query:
SELECT ?title
WHERE
{
<http://example.org/book/book1> <http://purl.org/dc/elements/1.1/title> ?title .
}
Here we need to highlight SELECT
?title
that is twice there and where
with opening and closing braces {
with }
, so that should do in this case,
so create list on bases of language keywords and that will help you finish the task :)
I hope this will help..