Browse Source

Use standard Turtle lexer in Pygments

A Turtle lexer was finally added in Pygments 2.1.
zrythm_meson
David Robillard 3 years ago
parent
commit
d2bd47c38b
  1. 60
      lv2specgen/lv2specgen.py
  2. 2
      plugins/eg-sampler.lv2/peaks.h
  3. 4
      plugins/eg-sampler.lv2/uris.h
  4. 2
      plugins/eg-scope.lv2/examploscope.c
  5. 4
      plugins/literasc.py

60
lv2specgen/lv2specgen.py

@ -59,9 +59,8 @@ except: @@ -59,9 +59,8 @@ except:
try:
import pygments
import pygments.lexers
import pygments.lexers.rdf
import pygments.formatters
from pygments.lexer import RegexLexer, include, bygroups
from pygments.token import Text, Comment, Operator, Keyword, Name, String, Literal, Punctuation
have_pygments = True
except ImportError:
print("Error importing pygments, syntax highlighting disabled")
@ -178,61 +177,6 @@ def getLabel(m, urinode): @@ -178,61 +177,6 @@ def getLabel(m, urinode):
else:
return ''
if have_pygments:
# Based on sw.py by Philip Cooper
class Notation3Lexer(RegexLexer):
"""
Lexer for N3 / Turtle / NT
"""
name = 'N3'
aliases = ['n3', 'turtle']
filenames = ['*.n3', '*.ttl', '*.nt']
mimetypes = ['text/rdf+n3','application/x-turtle','application/n3']
tokens = {
'comments': [
(r'(\s*#.*)', Comment)
],
'root': [
include('comments'),
(r'(\s*@(?:prefix|base|keywords)\s*)(\w*:\s+)?(<[^> ]*>\s*\.\s*)',bygroups(Keyword,Name.Variable,Name.Namespace)),
(r'\s*(<[^>]*\>)', Name.Class, ('triple','predObj')),
(r'(\s*[a-zA-Z_:][a-zA-Z0-9\-_:]*\s)', Name.Class, ('triple','predObj')),
(r'\s*\[\]\s*', Name.Class, ('triple','predObj')),
],
'triple' : [
(r'\s*\.\s*', Text, '#pop')
],
'predObj': [
include('comments'),
(r'\s*a\s*', Name.Keyword, 'object'),
(r'\s*[a-zA-Z_:][a-zA-Z0-9\-_:]*\b\s*', Name.Tag, 'object'),
(r'\s*(<[^>]*\>)', Name.Tag, 'object'),
(r'\s*\]\s*', Text, '#pop'),
(r'(?=\s*\.\s*)', Keyword, '#pop'),
],
'objList': [
include('comments'),
(r'\s*\)', Text, '#pop'),
include('object')
],
'object': [
include('comments'),
(r'\s*\[', Text, 'predObj'),
(r'\s*<[^> ]*>', Name.Tag),
(r'\s*("""(?:.|\n)*?""")(\@[a-z]{2-4}|\^\^<?[a-zA-Z0-9\-\:_#/\.]*>?)?\s*', bygroups(Literal.String,Text)),
(r'\s*".*?[^\\]"(?:\@[a-z]{2-4}|\^\^<?[a-zA-Z0-9\-\:_#/\.]*>?)?\s*', Literal.String),
(r'\s*[0-9]+\.[0-9]*\s*\n?', Literal.Number),
(r'\s*[0-9]+\s*\n?', Literal.Number),
(r'\s*[a-zA-Z0-9\-_\:]+\s*', Name.Tag),
(r'\s*\(', Text, 'objList'),
(r'\s*;\s*\n?', Punctuation, '#pop'),
(r'\s*,\s*\n?', Punctuation), # Added by drobilla so "," is not an error
(r'(?=\s*\])', Text, '#pop'),
(r'(?=\s*\.)', Text, '#pop'),
],
}
def linkify(string):
if linkmap == {}:
return string
@ -280,7 +224,7 @@ def getComment(m, urinode, classlist, proplist, instalist): @@ -280,7 +224,7 @@ def getComment(m, urinode, classlist, proplist, instalist):
match_str = xml.sax.saxutils.unescape(code.group(1))
code_str = pygments.highlight(
match_str,
Notation3Lexer(),
pygments.lexers.rdf.TurtleLexer(),
pygments.formatters.HtmlFormatter())
markup = code_rgx.sub(code_str, markup, 1)

2
plugins/eg-sampler.lv2/peaks.h

@ -120,7 +120,7 @@ peaks_sender_start(PeaksSender* sender, @@ -120,7 +120,7 @@ peaks_sender_start(PeaksSender* sender,
Forge a message which sends a range of peaks. Writes a peaks:PeakUpdate
object to `forge`, like:
[source,n3]
[source,turtle]
----
[]
a peaks:PeakUpdate ;

4
plugins/eg-sampler.lv2/uris.h

@ -73,7 +73,7 @@ map_sampler_uris(LV2_URID_Map* map, SamplerURIs* uris) @@ -73,7 +73,7 @@ map_sampler_uris(LV2_URID_Map* map, SamplerURIs* uris)
/**
Write a message like the following to `forge`:
[source,n3]
[source,turtle]
----
[]
a patch:Set ;
@ -102,7 +102,7 @@ write_set_file(LV2_Atom_Forge* forge, @@ -102,7 +102,7 @@ write_set_file(LV2_Atom_Forge* forge,
/**
Get the file path from `obj` which is a message like:
[source,n3]
[source,turtle]
----
[]
a patch:Set ;

2
plugins/eg-scope.lv2/examploscope.c

@ -168,7 +168,7 @@ connect_port(LV2_Handle handle, @@ -168,7 +168,7 @@ connect_port(LV2_Handle handle,
This function forges a message for sending a vector of raw data. The object
is a http://lv2plug.in/ns/ext/atom#Blank[Blank] with a few properties, like:
[source,n3]
[source,turtle]
--------
[]
a sco:RawAudio ;

4
plugins/literasc.py

@ -87,7 +87,7 @@ def format_ttl_source(filename, file): @@ -87,7 +87,7 @@ def format_ttl_source(filename, file):
chunk = line
else:
if is_comment:
output += format_code('n3', chunk)
output += format_code('turtle', chunk)
in_comment = True
chunk = line.strip().lstrip('# ') + ' \n'
else:
@ -96,7 +96,7 @@ def format_ttl_source(filename, file): @@ -96,7 +96,7 @@ def format_ttl_source(filename, file):
if in_comment:
return output + format_text(chunk)
else:
return output + format_code('n3', chunk)
return output + format_code('turtle', chunk)
def gen(out, filenames):
for filename in filenames:

Loading…
Cancel
Save