Sublime Forum

Desperatly need help to create a Syntax Definition for SAMCEF code

#1

Hello everybody,

I am trying to understand and create a Syntax Definition for SAMCEF code. But until now I failed, so I am asking for your help.
I would like to adapt the following Notepad++ Syntax (udl xml) to Sublime text. I am sure it is simple but I cannot figure it out…

<NotepadPlus> <UserLang name="SAMCEF" ext="dat" udlVersion="2.1"> <Settings> <Global caseIgnored="no" allowFoldOfComments="no" foldCompact="yes" forcePureLC="0" decimalSeparator="0" /> <Prefix Keywords1="yes" Keywords2="yes" Keywords3="no" Keywords4="yes" Keywords5="yes" Keywords6="no" Keywords7="yes" Keywords8="no" /> </Settings> <KeywordLists> <Keywords name="Comments">00! 01 02 03 04</Keywords> <Keywords name="Numbers, prefix1"></Keywords> <Keywords name="Numbers, prefix2"></Keywords> <Keywords name="Numbers, extras1"></Keywords> <Keywords name="Numbers, extras2"></Keywords> <Keywords name="Numbers, suffix1">.</Keywords> <Keywords name="Numbers, suffix2"></Keywords> <Keywords name="Numbers, range">E</Keywords> <Keywords name="Operators1">+ - : *</Keywords> <Keywords name="Operators2"></Keywords> <Keywords name="Folders in code1, open"></Keywords> <Keywords name="Folders in code1, middle"></Keywords> <Keywords name="Folders in code1, close"></Keywords> <Keywords name="Folders in code2, open"></Keywords> <Keywords name="Folders in code2, middle"></Keywords> <Keywords name="Folders in code2, close"></Keywords> <Keywords name="Folders in comment, open">#IF</Keywords> <Keywords name="Folders in comment, middle">#ELSEIF #ELSE THEN</Keywords> <Keywords name="Folders in comment, close">#ENDIF</Keywords> <Keywords name="Keywords1">.NOE&#x000D;&#x000A;.MAI&#x000D;&#x000A;.UNI&#x000D;&#x000A;.STOP&#x000D;&#x000A;.MAT&#x000D;&#x000A;.FRAM&#x000D;&#x000A;.3POI&#x000D;&#x000A;.FCT&#x000D;&#x000A;.PURGE&#x000D;&#x000A;.PHP&#x000D;&#x000A;.HYP&#x000D;&#x000A;.AEL&#x000D;&#x000A;.SEL&#x000D;&#x000A;.PEAU&#x000D;&#x000A;.AXL&#x000D;&#x000A;.CLM&#x000D;&#x000A;.LIA&#x000D;&#x000A;.MCC&#x000D;&#x000A;.MCE&#x000D;&#x000A;.DES&#x000D;&#x000A;.MCT&#x000D;&#x000A;.GEL&#x000D;&#x000A;.SAI&#x000D;&#x000A;.SUB&#x000D;&#x000A;.CLT&#x000D;&#x000A;.APS&#x000D;&#x000A;.RBE&#x000D;&#x000A;.STI&#x000D;&#x000A;.BOLT&#x000D;&#x000A;.MNT&#x000D;&#x000A;.ALGO&#x000D;&#x000A;.SAM&#x000D;&#x000A;.OPT&#x000D;&#x000A;.LOOP1</Keywords> <Keywords name="Keywords2">NOM&#x000D;&#x000A;GROUP&#x000D;&#x000A;THEN&#x000D;&#x000A;TYPE &#x000D;&#x000A;CART&#x000D;&#x000A;ORI&#x000D;&#x000A;GRO&#x000D;&#x000A;COM&#x000D;&#x000A;BOITE&#x000D;&#x000A;STRU&#x000D;&#x000A;NOE&#x000D;&#x000A;UNION&#x000D;&#x000A;IDEN&#x000D;&#x000A;MAI&#x000D;&#x000A;TRAN&#x000D;&#x000A;FACE&#x000D;&#x000A;MOINS&#x000D;&#x000A;GTAR&#x000D;&#x000A;CREE&#x000D;&#x000A;THIC&#x000D;&#x000A;NEXCE&#x000D;&#x000A;MAT&#x000D;&#x000A;DEGRE&#x000D;&#x000A;VOLU&#x000D;&#x000A;TOUT&#x000D;&#x000A;PURGE&#x000D;&#x000A;COUPLE&#x000D;&#x000A;BLOC&#x000D;&#x000A;XIT&#x000D;&#x000A;VON&#x000D;&#x000A;CAUCHY&#x000D;&#x000A;VAL&#x000D;&#x000A;ABS&#x000D;&#x000A;ORDO&#x000D;&#x000A;MAP&#x000D;&#x000A;ATT&#x000D;&#x000A;IMPOSE&#x000D;&#x000A;ARCH&#x000D;&#x000A;STYP&#x000D;&#x000A;NDIST&#x000D;&#x000A;MACRO&#x000D;&#x000A;ELEM&#x000D;&#x000A;PART&#x000D;&#x000A;CHA&#x000D;&#x000A;PRES&#x000D;&#x000A;TFX&#x000D;&#x000A;DEP&#x000D;&#x000A;FIX</Keywords> <Keywords name="Keywords3">OR&#x000D;&#x000A;AND&#x000D;&#x000A;GT&#x000D;&#x000A;LT&#x000D;&#x000A;NE&#x000D;&#x000A;EQ&#x000D;&#x000A;GE&#x000D;&#x000A;LE&#x000D;&#x000A;V1&#x000D;&#x000A;V2&#x000D;&#x000A;V3&#x000D;&#x000A;A&#x000D;&#x000A;I&#x000D;&#x000A;J&#x000D;&#x000A;K&#x000D;&#x000A;M&#x000D;&#x000A;YT&#x000D;&#x000A;NT&#x000D;&#x000A;MM&#x000D;&#x000A;X&#x000D;&#x000A;Y&#x000D;&#x000A;Z&#x000D;&#x000A;NLIM&#x000D;&#x000A;CF&#x000D;&#x000A;CFNF&#x000D;&#x000A;RMAX&#x000D;&#x000A;U&#x000D;&#x000A;KSMO&#x000D;&#x000A;XI&#x000D;&#x000A;XS&#x000D;&#x000A;YI&#x000D;&#x000A;YS&#x000D;&#x000A;ZI&#x000D;&#x000A;ZS&#x000D;&#x000A;OPT&#x000D;&#x000A;N&#x000D;&#x000A;NF&#x000D;&#x000A;V&#x000D;&#x000A;MECA&#x000D;&#x000A;REAC&#x000D;&#x000A;CIBLE&#x000D;&#x000A;IPRO&#x000D;&#x000A;RESO&#x000D;&#x000A;LINK&#x000D;&#x000A;PRCR&#x000D;&#x000A;PRCE&#x000D;&#x000A;IA16&#x000D;&#x000A;IA4&#x000D;&#x000A;IA19&#x000D;&#x000A;HMIN&#x000D;&#x000A;HMAX&#x000D;&#x000A;DTI0&#x000D;&#x000A;ITMA&#x000D;&#x000A;ILNS&#x000D;&#x000A;PAS&#x000D;&#x000A;UN3&#x000D;&#x000A;UN2&#x000D;&#x000A;UN1&#x000D;&#x000A;PEAU&#x000D;&#x000A;METH&#x000D;&#x000A;L1&#x000D;&#x000A;NOP1&#x000D;&#x000A;NOP2&#x000D;&#x000A;NOP3&#x000D;&#x000A;NOP4&#x000D;&#x000A;NOP5&#x000D;&#x000A;NOP6&#x000D;&#x000A;MF&#x000D;&#x000A;METHODE&#x000D;&#x000A;IRELIEF&#x000D;&#x000A;IMPRI&#x000D;&#x000A;CYLIND&#x000D;&#x000A;RAYONS&#x000D;&#x000A;ANGLES</Keywords> <Keywords name="Keywords4">/</Keywords> <Keywords name="Keywords5">INPUT&#x000D;&#x000A;APPEND&#x000D;&#x000A;RETURN&#x000D;&#x000A;CLOSE&#x000D;&#x000A;NAME</Keywords> <Keywords name="Keywords6">ECHO&#x000D;&#x000A;SUPPR&#x000D;&#x000A;MEAN&#x000D;&#x000A;FRAME&#x000D;&#x000A;FRE1&#x000D;&#x000A;CONT&#x000D;&#x000A;SPR1&#x000D;&#x000A;MAPP&#x000D;&#x000A;&#x000D;&#x000A;</Keywords> <Keywords name="Keywords7">.DEL.*&#x000D;&#x000A;#INQ&#x000D;&#x000A;EXIT&#x000D;&#x000A;&#x000D;&#x000A;</Keywords> <Keywords name="Keywords8">GRAP INIT&#x000D;&#x000A;MODE PREC&#x000D;&#x000A;MODE LECT&#x000D;&#x000A;MODE ERR&#x000D;&#x000A;ABRE&#x000D;&#x000A;TIME&#x000D;&#x000A;TEMP&#x000D;&#x000A;$&#x000D;&#x000A;EVAL&#x000D;&#x000A;NC</Keywords> <Keywords name="Delimiters">00( 01 02) 03&quot; 04 05&quot; 06&apos;&apos; 07 08&apos; 09[ 10 11] 12&apos; 13 14&apos; 15 16 17 18 19 20 21 22 23</Keywords> </KeywordLists> <Styles> <WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="COMMENTS" fgColor="008000" bgColor="C0C0C0" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="LINE COMMENTS" fgColor="28641A" bgColor="C0C0C0" fontName="" fontStyle="1" nesting="65536" /> <WordsStyle name="NUMBERS" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="0" /> <WordsStyle name="KEYWORDS1" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="5" nesting="0" /> <WordsStyle name="KEYWORDS2" fgColor="800000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="10" nesting="0" /> <WordsStyle name="KEYWORDS3" fgColor="EA7500" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="KEYWORDS4" fgColor="0000A0" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="KEYWORDS5" fgColor="8000FF" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="KEYWORDS6" fgColor="008080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="KEYWORDS7" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="KEYWORDS8" fgColor="FF00FF" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="OPERATORS" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="10" nesting="0" /> <WordsStyle name="FOLDER IN CODE1" fgColor="0000A0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="FOLDER IN CODE2" fgColor="FF00FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="FOLDER IN COMMENT" fgColor="400080" bgColor="FFFFFF" fontName="" fontStyle="7" nesting="0" /> <WordsStyle name="DELIMITERS1" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="117699839" /> <WordsStyle name="DELIMITERS2" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="17036543" /> <WordsStyle name="DELIMITERS3" fgColor="FF8040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="117701887" /> <WordsStyle name="DELIMITERS4" fgColor="FF0080" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="117701887" /> <WordsStyle name="DELIMITERS5" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="4" nesting="117702655" /> <WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> </Styles> </UserLang> </NotepadPlus>

0 Likes

#2

nobody has an idea?

0 Likes

#3

Before people do it for you, what did you try so far?

0 Likes

#4

read http://udl20.weebly.com/introduction.html and http://www.sublimetext.com/docs/3/syntax.html and you’ll see that UDL 2.0 XML, as used by Notepad++, is context-less and based purely on detecting “keywords”, either with word boundaries / white space surrounding them or without. So if you want to emulate it, you can just create a simple .sublime-syntax file with some long regexes with lots of alternations and assign the appropriate keyword, constant.numeric or comment scopes

0 Likes

#5

Yes, defining detection, without context would be enough for this language.
Samcef is a finite element code, which does not present sentences, loops, or complex structures.
An example:
> .MCT GROUP “BLABLA” GTAR “BLABLA2” OPT 2 OPCO 2 OPFR 2 KSMO 1
> .NOE I 29990001 X -1063.5 Y 0 Z 0 ! commment
> .NOE I 29990002 X -1063.5 Y 25.182 Z 557.47
> I 29990003 X -1063.5 Y 72.003 Z 553.37
> .AXL I 29990002 J 29990003 FRAME 20000001
To detect in the example: functions (starting with .), integer, float, text (delimited by " "), option (list of keyword), comment (!)

I do not whish to learn the YAML structure or all the complexity of the context detection. But I cannot find simple example of different keyword detection, all examples are directly too complex for my understanding.

0 Likes

#6

here’s a simple example to get you started:

%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
scope: source.samcef
contexts:
  main:
    # Functions begin with .
    - match: \.[A-Z]+
      scope: variable.function.samcef

    # Strings begin and end with quotes
    - match: (")[^"]*(")
      scope: string.quoted.double.samcef
      captures:
        1: punctuation.definition.string.begin.samcef
        2: punctuation.definition.string.end.samcef

    # Comments begin with an exclamation mark and finish at the end of the line
    - match: \!
      scope: punctuation.definition.comment.samcef
      push: line_comment

    # Numbers
    - match: '\b(-)?[0-9.]+\b'
      scope: constant.numeric.samcef

    # keywords are everything else
    - match: '\b([A-Z]+)\b'
      scope: keyword.samcef

  line_comment:
    - meta_scope: comment.line.samcef
    - match: $
      pop: true
0 Likes

#7

thx a lot, I swear I started to read http://www.sublimetext.com/docs/3/syntax.html
but as English not my first language, I couldn’t understand all…

0 Likes

#8

Hello again.
I cannot find where to put this .sublime-syntax file, or how to install it via menu.
And I hope my last question, how do I associate .dat file with this syntax?

0 Likes

#9

add the following above the scope: line

file_extensions:
  - dat

Preferences menu -> Browse Packages -> User folder

0 Likes

#10

Thank you KING!

0 Likes

#11

Hello again to all,

I do not manage to use the shortcut Ctrl+/ for commenting line with this Syntax.
Do I have to specify in some other way that ‘!’ define a comment?

# Comments begin with an exclamation mark and finish at the end of the line
- match: \!
  scope: punctuation.definition.comment.samcef
  push: line_comment

line_comment:
- meta_scope: comment.line.samcef
- match: $
pop: true

0 Likes

#12

Yes you do need to specify somewhere else that ! begins a comment - you can follow the advice/instructions here :slight_smile:

0 Likes

#13

Perfect.
For the record I did:

  • create the file Miscellaneous.tmPreferences in SublimeTextPortable\App\64-bit\Data\Packages\User
    containing:
 <?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
	<key>name</key>
	<string>Miscellaneous</string>
	<key>scope</key>
	<string>source.samcef</string>
	<key>settings</key>
	<dict>
		<key>shellVariables</key>
		<array>
			<dict>
				<key>name</key>
				<string>TM_COMMENT_START</string>
				<key>value</key>
				<string>! </string>
			</dict>
		</array>
	</dict>
</dict>
</plist>
0 Likes