[gtksourceview/cherry-pick-b129161a] Merge branch 'master' into 'master'
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/cherry-pick-b129161a] Merge branch 'master' into 'master'
- Date: Tue, 19 Oct 2021 22:18:24 +0000 (UTC)
commit cb4264566b01f3d10152577b0574643055dba56b
Author: Christian Hergert <christian hergert me>
Date: Tue Oct 19 22:18:05 2021 +0000
Merge branch 'master' into 'master'
SPICE netlist
See merge request GNOME/gtksourceview!214
(cherry picked from commit b129161ada19e8982f9cb32953d8e843e6ff2a28)
af912ff5 spice.lang: add SPICE language spec
data/language-specs/spice.lang | 327 +++++++++++++++++++++++++++++++++++++
tests/syntax-highlighting/file.cir | 149 +++++++++++++++++
2 files changed, 476 insertions(+)
---
diff --git a/data/language-specs/spice.lang b/data/language-specs/spice.lang
new file mode 100644
index 00000000..daa8dc03
--- /dev/null
+++ b/data/language-specs/spice.lang
@@ -0,0 +1,327 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+ Author: Vlad Ionescu
+ Copyright (C) 2013 Vlad Ionescu <imbvlad gmail com>
+
+ 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.
+
+***
+
+ This is meant to be a syntax highlighting *.lang file working for gedit or other text editors using 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, red 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
+ - variables
+ - dot-commands:
+ * parameters, functions
+ * simulation cards
+ * subcircuits and models
+ * other directives
+ - subcircuit's or model's names
+
+2013.06.15 - A-devices model names are now detected within concatenated lines.
+2013.06.17 - Functions are detected "by the book" (.func f(x) {...}) with matching curled braces.
+2013.11.21 - Added COUNTER to A-devices.
+2014.04.08 - Corrected variable detection with opened parenthesis behing and no space: (Ron=...)
+2014.04.22 - Only variables are now highlighted, without "="
+ - Corrected highlighting of "table()"
+ - Added *.mod to the extension list (model files)
+2014.04.25 - Elements are correctly marked when preceeded by spaces.
+ - Subcircuits ending in a simple ".ends" are now correctly detected.
+2014.05.29 - Added markup for "params:" within a ".subckt" line.
+2014.05.31 - Improved markup for "VALUE" syntax in E or G sources.
+2014.06.23 - Added markup for old-style "Laplace" in E or G sources.
+2015.04.30 - Added markup for "params:" in a concatenated .subckt line.
+2015.11.02 - Added upper-case extension recognition.
+2015.11.27 - Added OTA to A-devices.
+2015.12.26 - Added exception for coupling coefficient k
+2018.12.19 - Added markup for ".parma".
+ - Added support for the state-machine.
+ - Corrected keyword "xor" (zor) and added "ota" to A-devices.
+ - Fixed highlighting of variables without "=" afterwards. TODO
+ - Made functions highlight the name only, without the parenthesis and within.
+2019.01.02 - Added markup for ".text"
+2021.07.31 - Modified the mimetypes and globs section
+2021.10.10 - Corrected the state machine id and style
+
+********************************************************************************
+
+ There is also a colour scheme, spice.xml, which makes the highlighting resemble LTspice's editor, see:
+
+http://ltspicegoodies.ltwiki.org/useful.php
+
+for an html preview. It's completely optional, but it can't be hosted in the GtkSourceView's repository. The
file can be downloaded from the same page.
+
+********************************************************************************
+
+-->
+
+<language id="spice" name="SPICE" version="2.0" _section="Scientific">
+
+
+<!-- The known netlist formats used by LTspice (and not only): *.sp, *.net, *.cir, *.sub, *.lib, *.mod -->
+<metadata>
+ <property name="globs">*.cir;*.CIR;*.Cir</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="string" name="String" map-to="def:string"/>
+ <style id="attribute" name="Attribute" map-to="xml:attribute-name"/>
+ <style id="note" name="Note" map-to="def:note"/>
+ <style id="operator" name="Operator" map-to="def:operator"/>
+ <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"/>
+ <style id="state-machine" name="State machine" map-to="t2t:italic"/>
+</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="comment-exceptions" style-ref="attribute" extend-parent="false">
+ <match>[|+\[\]><\\/]</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 extended="true">
+ (\s[^\s><&(){};,=/+\-*\^]+|
+ (?![({])\s*[^\s><&(){};,=/+\-*\^]+)
+ (?=(\s*\=(?!(\s*\=))))
+ </match>
+ </context>
+ <context id="concat-inline-comment" style-ref="comment">
+ <match>\;.*</match>
+ </context>
+ <context id="A-devices" style-ref="identifier">
+
<match>\b(and|buf|counter|dflop|inv|modulator|xor|or|phasedet|samplehold|schmitbuf|schmitinv|schmitt|srflop|varistor|ota)\b</match>
+ </context>
+ <context id="subckt-params-concat" style-ref="builtin">
+ <match>params\:</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-jl-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>^\s*[a-jl-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*)?)\s</prefix>
+ <suffix>\b(?!(\s*[=<>(*\-+/]))</suffix>
+ <keyword>and</keyword>
+ <keyword>buf</keyword>
+ <keyword>counter</keyword>
+ <keyword>dflop</keyword>
+ <keyword>inv</keyword>
+ <keyword>modulator</keyword>
+ <keyword>xor</keyword>
+ <keyword>or</keyword>
+ <keyword>ota</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">
+ <prefix>\b</prefix>
+ <suffix>\b</suffix>
+ <keyword>value(?=(\s*[={]))</keyword>
+ <keyword>poly</keyword>
+ <keyword>laplace(?=(\s*[=({]))(?!(\s*\=))</keyword>
+ <keyword>freq(?=(\s*\{))</keyword>
+ <keyword>(?!(\=\s*))table</keyword>
+ </context>
+
+
+ <!-- Dot-commands and coupling coefficient k-->
+
+<!-- Parameters, functions -->
+ <context id="parameters" style-ref="builtin">
+ <prefix>^\s*([,.]|\.\.)</prefix>
+ <suffix>\b</suffix>
+ <keyword>funcs</keyword>
+ <keyword>func</keyword>
+ <keyword>params</keyword>
+ <keyword>param</keyword>
+ <keyword>parma</keyword>
+ <keyword>text</keyword>
+ </context>
+
+<!-- Coupling coefficient k -->
+ <context id="coupling" style-ref="builtin">
+ <prefix>^\s*</prefix>
+ <suffix>[a-z0-9_]*\b</suffix>
+ <keyword>k</keyword>
+ </context>
+
+<!-- Parameters within .subckt, on the same line, with colon -->
+ <context id="subckt-params" style-ref="builtin">
+ <prefix>\s</prefix>
+ <suffix>[:]</suffix>
+ <keyword>params</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>
+ <!-- State-machine begin/end keywords are treated the same as directives -->
+ <keyword>mach</keyword>
+ <keyword>machine</keyword>
+ <keyword>endmach</keyword>
+ <keyword>endmachine</keyword>
+ </context>
+
+<!-- State-machine commands are still blue, but normal and italic, for distinction from directives -->
+ <context id="state-machine" style-ref="state-machine">
+ <prefix>^[,.]</prefix>
+ <suffix>\b</suffix>
+ <keyword>state</keyword>
+ <keyword>rule</keyword>
+ <keyword>output</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>
+
+ <context id="subckt-model" style-ref="preprocessor">
+ <start extended="true">
+ ^[,.] ( end\b | (ends|subckt|model)\s+(?=(\%{chars})) )
+ </start>
+ <end>$|\s</end>
+ <include>
+ <context id="subckt-name" style-ref="note">
+ <match>((ends|model|subckt)\s+)?\%{chars}(?=($|\s*?))</match>
+ </context>
+ </include>
+ </context>
+
+<!-- Simulation cards -->
+ <context id="end-subckt" style-ref="preprocessor">
+ <prefix>^[,.]</prefix>
+ <suffix>\b</suffix>
+ <keyword>ends</keyword>
+ </context>
+
+ <context id="variables" style-ref="string">
+ <match extended="true">
+ (\s[^\s><&(){};,=/+\-*\^]+|
+ (?![({])\s*[^\s><&(){};,=/+\-*\^]+)
+ (?=(\s*\=(?!(\s*\=))))
+ </match>
+ </context>
+
+<!-- Functions highlighted without the parenthesis -->
+ <context id="funcs" style-ref="string">
+ <match extended="true">
+ ((^\s*[.](funcs|func))?)
+ \s+[^\s><&(){};,=/+\-*\^]+\s*(?=(\([^()]*\))\s+(\{))
+ </match>
+ </context>
+
+ </include>
+ </context>
+</definitions>
+
+</language>
diff --git a/tests/syntax-highlighting/file.cir b/tests/syntax-highlighting/file.cir
new file mode 100644
index 00000000..f20d1d86
--- /dev/null
+++ b/tests/syntax-highlighting/file.cir
@@ -0,0 +1,149 @@
+* Z:\home\user\Desktop\swcad\_models\_ALL_STARS\All_stars.asc
+
+..params a1=2 c3 = f( a1 )
+,func _1#quant( x, y, z) { x+ y - 1/z }
+,param number 1
+.params other 2
+
+A1 {0 *2} 2 3 4 5 y x 0 AND td=1n
+A51 + - 0 s1 0 y x 0 AND vt=0
+A2 1 {a<= b} 0 0 0 y x 0 BUF td=1n
+A#3 a {if(a,1,0)} { b/ 2 } N001 3 0 x 0 BUF vhigh=1 vlow=0 td=1n ref=0 trise=1n tfall=0 rout=1 cout=1
+A4 D 0 clk pre clr y x 0 DFLOP td=1n
+A5 + - 0 s1 0 y x 0 SCHMITT vt=0
+A6 + - 0 0 0 0 x 0 9 SCHMITT
+A7 + - 0 0 0 y 0 0 {9} SCHMITT vt=0 vh=0
+A8 1 0 0 0 0 x 0 0 BUF td=1n
+A9 1 2 3 4 5 y x 0 OR td=1n
+A10 { if( b, 2, 0 ) } 2 0 0 0 0 x 0 PHASEDET td=1n
+A11 1 0 0 0 0 y x 0 SCHMITT td=1n vt=0 vh=1
+A12) 1 0 0 0 0 0 x 0 SCHMITT td=1n ref=0
+A13 1 0 0 0 0 y 0 0 SCHMITT vh=0 vt=1
+A14 s r 0 0 0 y x 0 SRFLOP td=1n
+A15 1 2 3 4 5 y x 0 XOR td=1n
+A16 { if( {a}==f(b), 1, {a*b}) } am 0 0 0 0 x 0 MODULATOR mark=1 space=0
+A17 fm am 0 0 0 y x 0 MODULATOR mark=1 space=0
+A18 + - clk sh 0 0 x 0 SAMPLEHOLD td=1n
+A19< 1 2 3 3 3 3 4 3 VARISTOR rclamp=1
+
+B {if( a, {a*b}, 2)} {a <=b } V=f(time) tripdt=1 tripdv = 1
+B 1 {if( a, 1, 2)} 3 V=f(time) tripdv = 1 tripdt=1
+B2~,. 0 1 ic = 2 I=f(time)*{a} rpar=1
+B2! 0 1= V = f(time*{a/{b}}) *{a} rpar=1
+B2~,. 0 1 I=f(time)*{a}
+B21 1 2 rpar=1 I= a+ ( tripdt= =1) tripdt={tripdt} tripdv=1
+B23 1 2 rpar=1 I = a+ tripdt tripdv=1 tripdt=1u ic=1
+B_#3 1 2 2
+B2! 0 1 Laplace = s *{a} rpar=1 ic=0
+B21 1 2 window=1 nfft=1 Laplace= 1/s ic =1
+B51{ 0 1 i=1 rpar = 1
+
+Cerr 1 {if ( a, 1, 2)} 4 1.2
+C1 {if ( a, 1, 2)} 1 1
+C2 1 {if ( a, 1, 2)} 1.
+C3 1 {if ( a, 1, 2)} 1.44
+C4 {a<{b } } {if ( a, 1, 2)} .44
+C3 1 {if ( a, 1, 2)} 1.44e-12
+C1 {if ( a, 1, 2)} 1 13u ic = 1
+C5 1 {if ( a, 1, 2)} {1.2}
+C2 1 {if ( a, 1, 2)} {3.} Lser=1 _ = 2
+C4 1 {if ( a, 1, 2)} 1.44 rpar>=1
+C2 {a> = {b} } {if ( a, 1, 2)} {3.} Lser=1
+C2 {a >= {b} } {if ( a, 1, 2)} {3.}
+C2 { a= = {b} } {if ( a, 1, 2)} .1nF
+C55 2 { _a== b } Q = x* { pi + ( m = =1) }
+C5 2 1 Q = x* {pi} m= 3 rpar=1
+C6 2 1 2 m= 3 ic=1
+C8 1 {2} { a } Rpar =1 Cpar = 1 ic = 0
+C#@^% 2 1 Q = x* { pi + ( m ==1) } m= 3 ic =1
+
+D1 s1 2 D
+D2 1 2 1N4148 m=1 n=2
+
+E1 2 {a * 1} table {v(a)} (1,1 2,2)
+E_1 2 {a * 1} b { a-{b }} table (1,1 1)
+;E11 { a } { b } tbl{ 0, 0, 1, 1}
+E2 1 2 value = { 1 }
+E3 3 4 nfft = 2048 Laplace = (s^2+1)/(s^2+2*s +{ a }) window=1024
+Eee 13 13 13 13 laplace { 1/(s+1)}
+E1 2 0 1 0 1
+F1 1 0 V1 1
+L1 1 2 1
+G1 0 2 1 0 1
+G_1 2 {a * 1} freq {v(b)} (1,1 1) (2,2,2)
+G@543 1 {1 * 2 } poly(2) {v(1),v(2)} 1 2 3 4 5
+G_x 0 1 2 3 Laplace (s)
+G_y 2 3 {s} {laplace} laplace = s^2+1
+H1 1 0 V1 1
+W1 1 2 V1 CSW off
+I1 1 0 22222
+L2 1 2 { g ( 1, 2*3, 5) = = 1 }
+Q1 3 1 2 0 NPN
+J1 3 1 2 PJF
+M1 3 1 2 2 PMOS
+Q2 3 1 2 0 PNP
+R1 1 0 R=time
+R2 0 1 {11}
+S1 2 0 0 1 SW
+T1 1 0 2 0 Td=50n Z0=50
+V1 1 0 1
+O1 1 0 2 0 LTRA
+XU1 dut+ dut- bias resistance capacitance capometer current=1m freq=3Meg C=.5� Q=.25
+.param a=1 b = a c = f(1) and=1 inv=1 ;nihil
++ x = 2 y= x *3 z =f( x** y ) ;abracadabra inv dflop
++dflop =1 _1= pi value=f(1)
++f(x,y)=2
+.func f(x)=x**2
+.func table( x, y, z) = table(x,y,1,z,2)
+.model D D
+.lib Z:\opt\Progs\LTspiceIV\lib\cmp\standard.dio
+.model NPN NPN
+.model PNP PNP
+.lib Z:\opt\Progs\LTspiceIV\lib\cmp\standard.bjt
+.model NJF NJF
+.model PJF PJF
+.lib Z:\opt\Progs\LTspiceIV\lib\cmp\standard.jft
+.model NMOS NMOS
+.model PMOS PMOS
+.lib Z:\opt\Progs\LTspiceIV\lib\cmp\standard.mos
+.tran 0 1 0 1m steady startup nodiscard uic
+.model d d
+.model csw csw
+.model sw sw
+.model ltra ltra len=1 r=1 l=1 c=1
+.op
+.four 1k 25 v(1)
+.ferret
+.global 1 999
+.ic v(2)=2
+.inc capometer.sub
+.lib ltc.lib
+.loadbias .\load.bias
+.savebias .\save.bias
+*** state machine ; line comment
+.mach ; both are
+.machine ; highlighted
+.state s0 1
+,state s1 0 ; comma instead of dot
+.rule s0 s1 nothing ; there are no checks for correctnes ...
+.output (node) state ; ... or nodenames & co -- it's up to the user
+.endmachine ; both are
+,endmach ; highlighted
+*** end state machine
+.meas xxx param x
+.net v(1) v(2)
+.nodeset v(4)=1
+.options numdgt=16
+.opt gshunt=1p
+.opts reltol=1m
+.option cshunt=1p
+.save v(2)
+.step param b 1 10 2
+.subckt @1xxx s[1] _1 2 a x1 x2 params: a=2
+r1 1 2 {a}
+r2 2 0 2k
+,ends @1xxx
+.temp 10 20
+.wave .\snd.wav 16 48k v(1) v(2)
+.backanno
+.end
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]