Skip to content

Commit

Permalink
[tools] Add syntax hilightning for Vim text editors.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Aug 11, 2017
1 parent e48a72f commit 78a0961
Show file tree
Hide file tree
Showing 8 changed files with 917 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Style specifications are provided for:
** LaTeX listing: link:./formatting-styles/latex/sarl-listing.sty[monochrom], link:./formatting-styles/latex/sarl-colorized-listing.sty[color]
** link:./formatting-styles/latex/sarl-beamer-listing.sty[LaTeX Beamer]
* link:./formatting-styles/pygments/sarlexer/sarl.py[Pygments]
* link:./formatting-styles/vim/sarl.vim[Vim]

== 3. P2 Repository

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,18 @@ For installing the SARL style, you should:
* call: `python setup.py install`


## Vim Editor

[Vim Editor](http://www.vim.org/) is is a highly configurable text editor built to make creating and
changing any kind of text very efficient.

The SARL style is available on [GitHub](https://raw.githubusercontent.com/sarl/sarl/master/formatting-styles/vim/sarl.vim)

For using the SARL style, you should:

* copy the SARL style into the folder `$HOME/.vim/ftdetect`.



[:Include:](../legal.inc)

9 changes: 9 additions & 0 deletions formatting-styles/vim/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1. MANUAL INSTALLATION

Fox Unix:
* Copy the content of the 'syntax' folder into $HOME/vimfiles/syntax
* Copy the content of the 'ftdetect' folder into $HOME/vimfiles/ftdetect

Fox Windows:
* Copy the content of the 'syntax' folder into $HOME/.vim/syntax
* Copy the content of the 'ftdetect' folder into $HOME/.vim/ftdetect
5 changes: 5 additions & 0 deletions formatting-styles/vim/ftdetect/sarl.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
" Vim filetype-detection file
" Language: SARL
" Version: 0.6

au BufRead,BufNewFile *.sarl set filetype=sarl
146 changes: 146 additions & 0 deletions formatting-styles/vim/syntax/sarl.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
" Vim syntax file
" Language: SARL
" Version: 0.6
"
" $Id$
"
" File is automatically generated by the Xtext language generator.
" Do not change it.
"
" SARL is an general-purpose agent programming language.
" More details on http://www.sarl.io
"
" Copyright (C) 2014-2017 the original authors or authors.
"
" Licensed under the Apache License, Version 2.0 (the "License");
" you may not use this file except in compliance with the License.
" You may obtain a copy of the License at
"
" http://www.apache.org/licenses/LICENSE-2.0
"
" Unless required by applicable law or agreed to in writing, software
" distributed under the License is distributed on an "AS IS" BASIS,
" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
" See the License for the specific language governing permissions and
" limitations under the License.
"


" Quit when a syntax file was already loaded
if !exists("main_syntax")
if exists("b:current_syntax")
finish
endif
" we define it here so that included files can test for it
let main_syntax='sarl'
syn region sarlFold start="{" end="}" transparent fold
endif

let s:cpo_save = &cpo
set cpo&vim

" don't use standard HiLink, it will not work with included syntax files
if version < 508
command! -nargs=+ SarlHiLink hi link <args>
else
command! -nargs=+ SarlHiLink hi def link <args>
endif

" some characters that cannot be in a SARL program (outside a string)
syn match sarlError "[\\`]"

" comments
syn region sarlComment start="/\*" end="\*/" contains=@Spell
syn match sarlCommentStar contained "^\s*\*[^/]"me=e-1
syn match sarlCommentStar contained "^\s*\*$"
syn match sarlLineComment "//.*" contains=@Spell
syn cluster sarlTop add=sarlComment,sarlLineComment
" match the special comment /**/
syn match sarlComment "/\*\*/"

" numerical constants
syn match sarlNumber "[0-9][0-9]*\.[0-9]\+([eE][0-9]\+)\?[fFdD]\?"
syn match sarlNumber "0[xX][0-9a-fA-F]\+"
syn match sarlNumber "[0-9]\+[lL]\?"
syn cluster sarlTop add=sarlNumber

" Strings constants
syn match sarlSpecialError contained "\\."
syn match sarlSpecialCharError contained "[^']"
syn match sarlSpecialChar contained +\\\([4-9]\d\|[0-3]\d\d\|["\\'ntbrf]\|u\x\{4\}\)+
syn region sarlString start='"' end='"' contains=sarlSpecialChar,sarlSpecialError,@Spell
syn region sarlString start="'" end="'" contains=sarlSpecialChar,sarlSpecialError,@Spell
syn cluster sarlTop add=sarlString

" annnotation
syn match sarlAnnotation "@[_a-zA-Z][_0-9a-zA-Z]*\([.$][_a-zA-Z][_0-9a-zA-Z]*\)*"
syn cluster sarlTop add=sarlAnnotation

" primitive types.
syn match sarlArrayDeclaration contained "\(\s*\[\s*\]\)*"
syn keyword sarlPrimitiveType boolean byte char double float int long short void nextgroup=sarlArrayDeclaration
syn cluster sarlTop add=sarlPrimitiveType

" keywords for the 'sarlLiteral' family.
syn keyword sarlLiteral false it null occurrence this true void
syn cluster sarlTop add=sarlLiteral

" keywords for the 'sarlSpecial' family.
syn keyword sarlSpecial import package
syn cluster sarlTop add=sarlSpecial

" keywords for the 'sarlTypeDeclaration' family.
syn keyword sarlTypeDeclaration agent annotation artifact behavior capacity class enum event interface skill space
syn cluster sarlTop add=sarlTypeDeclaration

" keywords for the 'sarlModifier' family.
syn keyword sarlModifier abstract def dispatch final native override private protected public static strictfp synchronized transient val var volatile
syn cluster sarlTop add=sarlModifier

" keywords for the 'sarlKeyword' family.
syn keyword sarlKeyword as break case catch default do else extends extension finally fires for if implements instanceof new on requires return super switch throw throws try typeof uses while with
syn cluster sarlTop add=sarlKeyword

" catch errors caused by wrong parenthesis
syn region sarlParenT transparent matchgroup=sarlParen start="(" end=")" contains=@sarlTop,sarlParenT1
syn region sarlParenT1 transparent matchgroup=sarlParen1 start="(" end=")" contains=@sarlTop,sarlParenT2 contained
syn region sarlParenT2 transparent matchgroup=sarlParen2 start="(" end=")" contains=@sarlTop,sarlParenT contained
syn match sarlParenError ")"
" catch errors caused by wrong square parenthesis
syn region sarlParenT transparent matchgroup=sarlParen start="\[" end="\]" contains=@sarlTop,sarlParenT1
syn region sarlParenT1 transparent matchgroup=sarlParen1 start="\[" end="\]" contains=@sarlTop,sarlParenT2 contained
syn region sarlParenT2 transparent matchgroup=sarlParen2 start="\[" end="\]" contains=@sarlTop,sarlParenT contained
syn match sarlParenError "\]"

SarlHiLink sarlParenError sarlError

if !exists("sarl_minlines")
let sarl_minlines = 10
endif
exec "syn sync ccomment sarlComment minlines=" . sarl_minlines

" The default highlighting.
SarlHiLink sarlComment Comment
SarlHiLink sarlNumber Constant
SarlHiLink sarlString Constant
SarlHiLink sarlTypeDeclaration Type
SarlHiLink sarlLineComment Comment
SarlHiLink sarlLiteral Identifier
SarlHiLink sarlKeyword Statement
SarlHiLink sarlAnnotation PreProc
SarlHiLink sarlArrayDeclaration Special
SarlHiLink sarlSpecial Special
SarlHiLink sarlPrimitiveType Special
SarlHiLink sarlModifier Statement

delcommand SarlHiLink

let b:current_syntax = "sarl"

if main_syntax == 'sarl'
unlet main_syntax
endif

let b:spell_options="contained"
let &cpo = s:cpo_save
unlet s:cpo_save
10 changes: 10 additions & 0 deletions main/coreplugins/io.sarl.lang.mwe2/GenerateSARL2.mwe2
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import io.sarl.lang.mwe2.externalspec.latex.*
import io.sarl.lang.mwe2.externalspec.gtk.*
import io.sarl.lang.mwe2.externalspec.gnusrchighlight.*
import io.sarl.lang.mwe2.externalspec.pygments.*
import io.sarl.lang.mwe2.externalspec.vim.*
import io.sarl.lang.mwe2.codebuilder.*
import io.sarl.lang.mwe2.codebuilder.config.*
import io.sarl.lang.mwe2.keywords.*
Expand Down Expand Up @@ -64,6 +65,7 @@ var latexToolPath = "${externalToolPath}/latex"
var gtkToolPath = "${externalToolPath}/gtk"
var srchighlightToolPath = "${externalToolPath}/source-highlight"
var pygmentsToolPath = "${externalToolPath}/pygments/sarllexer"
var vimToolPath = "${externalToolPath}/vim"

var file.extensions = "sarl"
var languageWebsite = "http://www.sarl.io"
Expand Down Expand Up @@ -124,6 +126,9 @@ Workflow {
component = DirectoryCleaner {
directory = "${pygmentsToolPath}"
}
component = DirectoryCleaner {
directory = "${vimToolPath}"
}

component = XtextGenerator auto-inject {
// Generation and configuration module for SARL
Expand Down Expand Up @@ -458,6 +463,11 @@ Workflow {
url = languageWebsite
}

// Generate the Vim style
fragment = VimGenerator2 auto-inject {
output = vimToolPath
}

// SARL specific bindings
fragment = InjectionFragment2 auto-inject {
comment = "Bindings provided by SARL API"
Expand Down
1 change: 1 addition & 0 deletions main/coreplugins/io.sarl.lang.mwe2/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ Export-Package: io.sarl.lang.mwe2,
io.sarl.lang.mwe2.externalspec.latex,
io.sarl.lang.mwe2.externalspec.prettify,
io.sarl.lang.mwe2.externalspec.pygments,
io.sarl.lang.mwe2.externalspec.vim,
io.sarl.lang.mwe2.keywords
Loading

0 comments on commit 78a0961

Please sign in to comment.