1. Toby Inkster
  2. misc-scite-n3

Commits

Toby Inkster  committed 5e18168

N3 syntax highlighting in SciTE.

  • Participants
  • Branches scite-n3

Comments (0)

Files changed (3)

File SciTE.properties

View file
+file.patterns.n3=*.ttl;*.n3;*.nt;*.turtle
+extension.$(file.patterns.n3)=n3.lexer.lua
+lexer.$(file.patterns.n3)=script_n3
+
+# Punctuation
+style.script_n3.1=$(font.text),fore:#990000,bold
+# @keywords
+style.script_n3.2=$(font.text),fore:#000000,bold
+# Comment
+style.script_n3.3=$(font.text),fore:#669933,italics
+# Invalid
+style.script_n3.9=$(font.text),fore:#ffff00,back:#660000,bold
+# URI
+style.script_n3.10=$(font.text),fore:#0000cc
+# CURIE
+style.script_n3.20=$(font.text),fore:#000099,bold
+# BNode
+style.script_n3.21=$(font.text),fore:#009900,bold
+# rdf:type
+style.script_n3.22=$(font.text),fore:#000099,bold,italics
+# Literal
+style.script_n3.25=$(font.text),fore:#cc00cc
+# Long literal
+style.script_n3.26=$(font.text),fore:#cc00cc,back:#ffddff,italics
+# Lang
+style.script_n3.27=$(font.text),fore:#ff0000
+# Numbers
+style.script_n3.28=$(font.text),fore:#cc00cc,bold
+# true/false
+style.script_n3.29=$(font.text),fore:#cc00cc,bold,italics
+
+# Go = show N-Triples ; Build = show XML ; Compile = save XML
+command.go.$(file.patterns.n3)=trapper -i turtle $(FileNameExt)
+command.build.$(file.patterns.n3)=trapper -o rdfxml -i turtle $(FileNameExt)
+command.compile.$(file.patterns.n3)=trapper -o rdfxml -i turtle $(FileNameExt) >$(FileName).rdf
+
+# Additional commands
+command.name.0.$(file.patterns.n3)=Prefix.CC
+command.0.$(file.patterns.n3)=* GET 'http://prefix.cc/$(1).ttl.plain'
+
+# Comments
+comment.block.script_n3=#

File example.ttl

View file
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix dc: <http://purl.org/dc/terms/> .
+@prefix ex: <http://example.org/stuff/1.0/> .
+
+<http://www.w3.org/TR/rdf-syntax-grammar>
+  dc:title "RDF/XML Syntax Specification (Revised)"@en ;
+  ex:size 193.4 ;
+  ex:good TRUE ;
+  ex:editor [
+    ex:fullname "Dave \"dajobe\" Beckett";
+    ex:homePage <http://purl.org/net/dajobe/>
+  ] . #comment, how are you?
+

File n3.lexer.lua

View file
+-- -*- coding: utf-8 -*-
+
+function OnStyle(styler)
+	S_DEFAULT = 0
+	S_PUNC = 1
+	S_KEYWORD = 2
+	S_COMMENT = 3
+	S_URI = 10
+	S_CURIE = 20
+	S_BNODE = 21
+	S_RDFTYPE = 22
+	S_LITERAL = 25
+	S_LONGLITERAL = 26
+	S_LANG = 27
+	S_NUM = 28
+	S_BOOL = 29
+	S_INVALID = 9
+	
+	identifierCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_:"
+	identifierStartCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_:"
+	langCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_@"
+	numericCharacters = "0123456789.eE"
+	numericStartCharacters = "0123456789+-"
+
+	styler:StartStyling(styler.startPos, styler.lengthDoc, styler.initStyle)
+	while styler:More() do
+
+		-- Exit state if needed
+		if styler:State() == S_CURIE then
+			if not identifierCharacters:find(styler:Current(), 1, true) then
+				identifier = styler:Token()
+				if identifier:sub(1,2) == "_:" then
+					styler:ChangeState(S_BNODE)
+				elseif identifier == "a" then
+					styler:ChangeState(S_RDFTYPE)
+				elseif identifier:lower() == "true" or identifier:lower() == "false" then
+					styler:ChangeState(S_BOOL)
+				elseif not identifier:find(":") then
+					styler:ChangeState(S_INVALID)
+				end
+				styler:SetState(S_DEFAULT)
+			end
+		elseif styler:State() == S_NUM then
+			if not numericCharacters:find(styler:Current(), 1, true) then
+				styler:SetState(S_DEFAULT)
+			end
+		elseif styler:State() == S_KEYWORD then
+			if not identifierCharacters:find(styler:Current(), 1, true) then
+				styler:SetState(S_DEFAULT)
+			end
+		elseif styler:State() == S_COMMENT then
+			if styler:Match("\n") or styler:Match("\r") then
+				styler:SetState(S_DEFAULT)
+			end
+		elseif styler:State() == S_LANG then
+			if not langCharacters:find(styler:Current(), 1, true) then
+				styler:SetState(S_DEFAULT)
+			end
+		elseif styler:State() == S_URI then
+			if styler:Match(">") then
+				styler:ForwardSetState(S_DEFAULT)
+			end
+		elseif styler:State() == S_LITERAL then
+			literal = styler:Token()
+			if styler:Match("\\\\") or styler:Match("\\\"") or styler:Match("\\\'") then
+				styler:Forward()
+				styler:Forward()
+			elseif styler:Match( literal:sub(1,1) ) then
+				styler:ForwardSetState(S_DEFAULT)
+			end
+		elseif styler:State() == S_LONGLITERAL then
+			literal = styler:Token()
+			if styler:Match('"') and literal:sub(-2, -1)=='""' and literal:len() >= 6 then
+				styler:ForwardSetState(S_DEFAULT)
+			end
+		elseif styler:State() == S_PUNC then
+			if styler:Match(".") or styler:Match(";") or styler:Match(",") or styler:Match("\[") or styler:Match("]") or styler:Match("(") or styler:Match(")") or styler:Match("^") then
+				styler:SetState(S_PUNC)
+			else
+				styler:SetState(S_DEFAULT)
+			end
+		end
+
+		-- Enter state if needed
+		if styler:State() == S_DEFAULT then
+			if styler:Match("<") then
+				styler:SetState(S_URI)
+			elseif styler:Match("@prefix") or styler:Match("@base") or styler:Match("@keywords") then
+				styler:SetState(S_KEYWORD)
+			elseif styler:Match("@") and not (styler:Match("@prefix") or styler:Match("@base") or styler:Match("@keywords")) then
+				styler:SetState(S_LANG)
+			elseif styler:Match('"""') then
+				styler:SetState(S_LONGLITERAL)
+			elseif styler:Match("'") or styler:Match('"') then
+				styler:SetState(S_LITERAL)
+			elseif styler:Match(".") or styler:Match(";") or styler:Match(",") or styler:Match("\[") or styler:Match("]") or styler:Match("(") or styler:Match(")") or styler:Match("^") then
+				styler:SetState(S_PUNC)
+			elseif numericStartCharacters:find(styler:Current(), 1, true) then
+				styler:SetState(S_NUM)
+			elseif identifierStartCharacters:find(styler:Current(), 1, true) then
+				styler:SetState(S_CURIE)
+			elseif styler:Match("#") then
+				styler:SetState(S_COMMENT)
+			end
+		end
+
+		styler:Forward()
+	end
+	styler:EndStyling()
+end