[gedit-list] SPICE syntax highlighting



Hello

I have been searching for some SPICE syntax highighting on the Internet but I couldn't find anything close to my needs, I have tried Kate's but I find it very lacking, so I decided to make my own. I also slightly modified the kate.xml color scheme to fit the new requirements and the result is pretty close to what I had in mind. If these are useful to others, too, then here they are, attached. Bear in mind, though, that up until a week or two ago I never knew what PCRE means or does, so this will probably stir up some laughing. I also wanted something more complicated, but I think I was just plain greedy and overlooked my current knowledge of PCRE, so I gave up in the favor of the current one.

So, here they are, not imposing but merely presenting an option. Honestly, I don't know what others might think about this but, if it's working... try it and decide. I use Linux Mint 14 with Xfce, so I have gedit 2.30.4 by default, but I doubt there are any problems with other versions.


Vlad
<?xml version="1.0" encoding="UTF-8"?>
<language id="spice" _name="SPICE" version="2.0" _section="Scientific">

<!-- ***************************************************************************
 This is meant to be a syntax highlighting *.lang file working for gedit or other text editors usin this sort of filetype. The reference is LTspice, almost exclusively, but the program is compatible with SPICE3 syntax or with many other flavours of SPICE.
 LTspice can be set to have tabs or fixed font, but the color scheme is a very simple one: dark-green for comments, ref for concatenated line, blue for any dot-command and black for the rest. While this doesn't put strain on the eyes color-wise, it does have a tendency to make following certain aspects a tad harder, such as parameters in a large .param block or trying to find a .subckt in a netlist.
 The methods used here are simple enough not to make everything look like a rainbow but, at the same time, to not be too simple, while trying to emphasize some key words to make editing of netlists with a text editor easier. Thus, all ennumerated below share one colour each, common or not (configurable):
	- comments and in-line comments
	- elements' names, model names or attributes
	- values
	- dot-commands:
		* parameters, functions
		* simulation cards
		* subcircuits and models
		* other directives
	- subcircuit's or model's names
**************************************************************************** -->


<!-- The known netlist formats used by LTspice (and not only) -->
<metadata>
	<property name="mimetypes">text/x-cir;text/x-net;text/x-sp;text/x-sub;text/x-lib</property>
	<property name="globs">*.cir;*.net;*.sp;*.sub;*.lib</property>
</metadata>

<styles>
	<style id="preprocessor"	_name="Preprocessor"		map-to="def:preprocessor"/>
	<style id="statement"		_name="Statement"		map-to="def:statement"/>
	<style id="function"		_name="Function"		map-to="def:function"/>
	<style id="builtin"		_name="Builtin"			map-to="def:builtin"/>
	<style id="type"		_name="Data Type"		map-to="def:type"/>
	<style id="string"		_name="String"			map-to="def:string"/>
	<style id="attribute"		_name="Attribute"		map-to="xml:attribute-name"/>
	<style id="char"		_name="Character"		map-to="def:character"/>
	<style id="note"		_name="Note"			map-to="def:note"/>
	<style id="special-char"	_name="Special Character"	map-to="def:special-char"/>
	<style id="operator"		_name="Operator"		map-to="def:operator"/>
	<style id="constant"		_name="Constant"		map-to="def:constant"/>
	<style id="special-constant"	_name="Special constant"	map-to="def:special-constant"/>
	<style id="number"		_name="Number"			map-to="def:number"/>
	<style id="base-n-integer"	_name="Base N Integer"		map-to="def:base-n-integer"/>
	<style id="decimal"		_name="Decimal"			map-to="def:decimal"/>
	<style id="floating-point"	_name="Floating point"		map-to="def:floating-point"/>
	<style id="boolean"		_name="Boolean"			map-to="def:boolean"/>
	<style id="keyword"		_name="Keyword"			map-to="def:keyword"/>
	<style id="identifier"		_name="Attribute name"		map-to="def:identifier"/>
	<style id="comment"		_name="Comment"			map-to="def:comment"/>
	<style id="doc-comment"		_name="Comment"			map-to="def:doc-comment"/>
	<style id="error"		_name="Error"			map-to="def:error"/>
</styles>

<!-- Nothing is case-sensitive -->
<default-regex-options case-sensitive="false"/>

<definitions>
	<context id="spice">
		<include>

	<!--	Allowed characters in naming of elements or nets
Exotic names like C$@. or G?\ do work in testing, but they may not be recommended. Almost any non-word character works except {} or () or ' (interpreted as a replacement for { or }) or = (it is allowed but not followed by any other character, or in net names) or , or space-->
			<define-regex id="chars">[^\s{}(),;'=]+</define-regex>

	<!--	Commented line
Starts at line start with * and goes until EOL, can have spaces before -->
			<context id="commented-line" style-ref="comment">
				<start>^\s*\*</start>
				<end>$</end>
				<include>
					<context id="bar-exception" style-ref="attribute" extend-parent="false">
						<match>[|+\[\]&gt;&lt;\\/]</match>
					</context>
				</include>
			</context>

	<!--	In-line comment
Starts from character ; until EOL. There are exceptions in netlist elements where, even if it is interpreted as an in-line comment, the engine will give errors due to the syntax malforming -->
			<context id="inline-comment" style-ref="comment">
				<start>\;</start>
				<end>$</end>
			</context>

	<!--	Concatenated line
Active if the line starts with + (with or without spaces before). It differs from LTspice in that it keeps the rest of the line with the same colour as the parent line (normal), but italic, while signaling the break with a red + sign -->


			<context id="concat-line" style-ref="doc-comment">
				<start>^\s*(?=\+)</start>
				<end>$</end>
				<include>
					<context id="concat" style-ref="note">
						<match>^\s*\+\s+</match>
					</context>
					<context id="concat-values" style-ref="string">
						<match>([_][^\s&gt;&lt;&amp;(){};,=/+\-*\^]|[a-z])[^\s&gt;&lt;&amp;;,=/+\-*\^]*\s*\=(?!(\s*\=))</match>
					</context>
					<context id="concat-inline-comment" style-ref="comment">
						<match>\;.*</match>
					</context>
				</include>
			</context>


<!-- Errors first
Anything not starting with [A-Z] and having any of {}();'=, in the name is wrong -->
			<context id="id-error" style-ref="error">
				<match>^\s*[a-z^0-9_\W]\S*([{}();'=,])</match>
			</context>

	<!--	Elements
All elements start with [A-Z] and can have any allowed character afterwards, including none -->
			<context id="devices" style-ref="statement">
				<start>^[a-z]\S*</start>
				<end>\s</end>
			</context>

	<!--	A-devices model names
Useful to be highlighted since all share the same syntax of <ID net1 net2 ... net8 model parameters/attributes> and there is a small variety of them available-->
			<context id="A-models" style-ref="identifier">
				<prefix>\s</prefix>
				<suffix>\s(?!(\s*[=&lt;&gt;(*\-+/]))</suffix>
				<keyword>and</keyword>
				<keyword>buf</keyword>
				<keyword>dflop</keyword>
				<keyword>inv</keyword>
				<keyword>modulator</keyword>
				<keyword>xor</keyword>
				<keyword>or</keyword>
				<keyword>phasedet</keyword>
				<keyword>samplehold</keyword>
				<keyword>schmitbuf</keyword>
				<keyword>schmitinv</keyword>
				<keyword>schmitt</keyword>
				<keyword>srflop</keyword>
				<keyword>varistor</keyword>
			</context>

<!-- Old-style elements (E,G) attributes -->
			<context id="old-attributes" style-ref="function">
				<!--match>((^[EG].*)>?)(value|poly|freq|table)</match-->
				<prefix>\b</prefix>
				<suffix>\b</suffix>
				<keyword>value(?=(\s*\=))</keyword>
				<keyword>poly</keyword>
				<keyword>freq(?=(\s*\{))</keyword>
				<keyword>((\=\s*)>?)table</keyword>
			</context>


	<!-- Dot-commands -->

<!-- Parameters, functions -->
			<context id="functions" style-ref="builtin">
				<prefix>^[,.]</prefix>
				<suffix>\b</suffix>
				<keyword>funcs</keyword>
				<keyword>params</keyword>
				<keyword>func</keyword>
				<keyword>param</keyword>
			</context>

<!-- Directives -->
			<context id="directives" style-ref="operator">
				<prefix>^[,.]</prefix>
				<suffix>\b</suffix>
				<keyword>nodealias</keyword>
				<keyword>nodeset</keyword>
				<keyword>meas</keyword>
				<keyword>options</keyword>
				<keyword>option</keyword>
				<keyword>opts</keyword>
				<keyword>opt</keyword>
				<keyword>ic</keyword>
				<keyword>step</keyword>
				<keyword>lib</keyword>
				<keyword>include</keyword>
				<keyword>inc</keyword>
				<keyword>backanno</keyword>
				<keyword>savebias</keyword>
				<keyword>save</keyword>
				<keyword>loadbias</keyword>
				<keyword>load</keyword>
				<keyword>global</keyword>
				<keyword>temp</keyword>
				<keyword>ferret</keyword>
				<keyword>wave</keyword>
			</context>

<!-- Simulation cards -->
			<context id="simulation" style-ref="builtin">
				<prefix>^[,.]</prefix>
				<suffix>\b</suffix>
				<keyword>four</keyword>
				<keyword>dc</keyword>
				<keyword>ac</keyword>
				<keyword>tran</keyword>
				<keyword>op</keyword>
				<keyword>tf</keyword>
				<keyword>net</keyword>
			</context>

<!-- Subcircuits and models
 -->
			<!--context id="subckt-model" style-ref="keyword">
				<prefix>^[,.]</prefix>
				<suffix>\b</suffix>
				<keyword>ends?</keyword>
				<keyword>subckt</keyword>
				<keyword>model</keyword>
			</context-->


			<context id="subckt-model" style-ref="preprocessor">
				<start extended="true">
				^[,.](ends|model|subckt)\s+(?=(\%{chars})) |
				^\.end\b
				</start>
				<end>$|\s</end>
				<include>
					<context id="subckt-name" style-ref="note">
						<match>((ends|model|subckt)\s+)?\%{chars}(?=($|\s*?))</match>
					</context>
				</include>
			</context>

	<!--	Values
If the values don't start with an underscore then they must start with a letter, else there can be any of the previously defined characters; a single underscore is not allowed, either -->
			<context id="values" style-ref="string">
				<match extended="true">
				(
				([_][^\s&gt;&lt;&amp;(){};,=/+\-*\^]|[a-z])
				[^\s&gt;&lt;&amp;{};=/+\-*\^]* |
				([_][^\s&gt;&lt;&amp;(){};,=/+\-*\^]|[a-z])
				[^\s&gt;&lt;&amp;{};=/+\-*\^]*\([^()]+\)
				)
				\s*\=(?!(\s*\=))
				</match>
			</context>


		</include>
	</context>
</definitions>

</language>
<?xml version="1.0" encoding="UTF-8"?>
<!--

 Copyright (C) 2006-2007 GtkSourseView team
 Author: Yevgen Muntyan <muntyan tamu edu>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public
 License as published by the Free Software Foundation; either
 version 2 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Library General Public License for more details.

 You should have received a copy of the GNU Library General Public
 License along with this library; if not, write to the
 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.

***************

 It's a partly modified copy of kate.xml to fit the "spice.lang" file.

							Vlad
***************
-->
<style-scheme id="spice" _name="SPICE" version="1.0">
  <author>GtkSourceView team</author>
  <_description>Kate color scheme adapted for SPICE (spice.lang)</_description>

  <color name="white"				value="#FFFFFF"/>
  <color name="light-grey"			value="#BFBFBF"/>
  <color name="grey"				value="#7F7F7F"/>
  <color name="dark-grey"			value="#3F3F3F"/>
  <color name="red"				value="#FF0000"/>
  <color name="dark-red"			value="#7F0000"/>
  <color name="green"				value="#00FF00"/>
  <color name="dark-green"			value="#007F00"/>
  <color name="blue"				value="#0000FF"/>
  <color name="dark-blue"			value="#00007F"/>
  <color name="brown"				value="#7E3E00"/>
  <color name="yellow"				value="#FFFF00"/>
  <color name="orange"				value="#FF7F00"/>
  <color name="cyan"				value="#00FFFF"/>
  <color name="azure"				value="#007FFF"/>
  <color name="magenta"				value="#FF00FF"/>

  <style name="current-line"			background="#CCDDEE"/>
  <style name="right-margin"			background="#ADD4FF"/>
  <style name="bracket-match"			bold="true"/>
  <style name="bracket-mismatch"		background="red" bold="true"/>

  <!-- Search Matching -->
  <style name="search-match"			background="yellow"/>

  <!-- Bookmarks -->
  <style name="bookmark"			background="#E5E5FF"/>

  <!-- legacy styles for old lang files -->
  <style name="Others"				foreground="dark-red"/>
  <style name="Others 2"			bold="true"/>
  <style name="Others 3"			foreground="dark-green"/>

  <!-- Comments -->
  <style name="def:comment"			foreground="dark-green" italic="true" bold="false"/>
  <style name="def:shebang"/>
  <style name="def:doc-comment"			foreground="#545454" italic="true"/>
  <style name="def:doc-comment-element"		bold="true"/>

  <!-- Types -->
  <style name="def:type"			foreground="blue"/>

  <!-- Constants -->
  <style name="def:constant"			foreground="brown"/>
  <style name="def:decimal"			foreground="brown"/>
  <style name="def:base-n-integer"		foreground="brown"/>
  <style name="def:floating-point"		foreground="brown"/>
  <style name="def:complex"			foreground="brown"/>
  <style name="def:character"			foreground="brown"/>
  <style name="def:string"			foreground="red"/>
  <style name="def:special-char"		foreground="orange"/>
  <style name="def:builtin"			foreground="blue" bold="true" italic="true"/>
  <style name="def:operator"			foreground="blue" bold="true"/>

  <!-- Identifiers -->
  <style name="def:identifier"			foreground="azure"/>
  <style name="def:function"			foreground="azure"/>

  <!-- Statements -->
  <style name="def:statement"			bold="true"/>
  <style name="def:keyword"			bold="true" italic="true"/>

  <!-- Others -->
  <style name="preprocessor"			foreground="blue" bold="true"/>
  <style name="def:preprocessor"		foreground="blue" background="#F7E7E7" bold="true"/>
  <style name="def:note"			foreground="#BF0303" background="#F7E7E7" bold="true"/>
  <style name="def:error"			foreground="red" underline="true"/>
  <style name="def:underlined"			underline="true"/>

  <!-- Language specific styles -->
  <style name="c:preprocessor"			foreground="dark-green"/>
  <style name="c:included-file"			use-style="c:preprocessor"/>
  <style name="c:common-defines"		foreground="#0095FF" bold="true"/>

  <style name="diff:diff-file"			use-style="def:statement"/>
  <style name="diff:added-line"			use-style="def:decimal"/>
  <style name="diff:removed-line"		use-style="def:string"/>
  <style name="diff:changed-line"		use-style="c:preprocessor"/>
  <style name="diff:special-case"/>
  <style name="diff:location"			use-style="def:type"/>

  <style name="xml:attribute-name"		foreground="dark-green" italic="false"/>
  <style name="xml:element-name"		bold="true"/>
  <style name="xml:entity"			foreground="blue"/>
  <style name="xml:cdata-delim"			foreground="#008080" bold="true"/>
  <style name="xml:processing-instruction"	bold="true"/>
  <style name="xml:doctype"			foreground="dark-red" bold="true"/>

  <style name="docbook-element"			foreground="#004141" bold="true"/>
  <style name="docbook:header-elements"		use-style="docbook-element"/>
  <style name="docbook:formatting-elements"	use-style="docbook-element"/>
  <style name="docbook:gui-elements"		use-style="docbook-element"/>
  <style name="docbook:structural-elements"	use-style="docbook-element"/>

  <style name="js:object"			foreground="dark-green"/>
  <style name="js:constructors"			bold="true"/>

  <style name="mooscript:special-vars"		use-style="c:preprocessor"/>

  <style name="latex:display-math"		background="#C0FFC0"/>
  <style name="latex:inline-math"		foreground="#006400"/>
  <style name="latex:math-bound"		bold="true"/>
  <style name="latex:common-commands"		foreground="dark-red"/>
  <style name="latex:command"			foreground="#7000DF"/>
  <style name="latex:structure"			bold="true"/>
  <style name="latex:section"			foreground="#7000DF" bold="true"/>
  <style name="latex:include"			use-style="latex:common-commands"/>
  <style name="latex:use-package"		use-style="latex:common-commands"/>

  <style name="changelog:date"			use-style="def:type"/>
  <style name="changelog:email"			use-style="c:preprocessor"/>
  <style name="changelog:file"			use-style="def:function"/>
  <style name="changelog:bullet"		use-style="changelog:file"/>
  <style name="changelog:release"		foreground="#0095FF" bold="true"/>

  <style name="perl:pod"			foreground="grey"/>

  <style name="python:string-conversion"	background="#BEBEBE"/>
  <style name="python:module-handler"		use-style="def:character"/>
  <style name="python:special-variable"		use-style="def:type"/>
  <style name="python:builtin-constant"		use-style="def:type"/>
  <style name="python:builtin-object"		use-style="def:type"/>
  <style name="python:builtin-function"		use-style="def:type"/>
  <style name="python:boolean"			use-style="def:type"/>

  <style name="scheme:parens"			use-style="def:statement"/>
  <style name="scheme:any-function"		use-style="def:statement"/>

  <style name="sh:dollar"			foreground="dark-green" bold="true"/>

  <style name="makefile:trailing-tab"		background="#FFC0CB"/>

  <style name="t2t:italic"			italic="true"/>
  <style name="t2t:bold"			bold="true"/>
  <style name="t2t:verbatim"			background="#lightgrey"/>
  <style name="t2t:verbatim-block"		line-background="#lightgrey"/>
  <style name="t2t:comment"			foreground="dark-green"/>
  <style name="t2t:option"			foreground="dark-green"/>
</style-scheme>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]