Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lutils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
verimag
synchrone
lutils
Commits
d35866c6
Commit
d35866c6
authored
1 month ago
by
erwan
Browse files
Options
Downloads
Patches
Plain Diff
refactor: rewrite rif and lutin emacs mode
parent
c8fa1405
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
emacs/lutin.el
+85
-84
85 additions, 84 deletions
emacs/lutin.el
emacs/rif.el
+60
-57
60 additions, 57 deletions
emacs/rif.el
with
145 additions
and
141 deletions
emacs/lutin.el
+
85
−
84
View file @
d35866c6
;;; lutin.el - Major mode for editing lustre source in Emacs
;;; lutin.el - Major mode for editing lustre source in Emacs
;;; lutin-mode.el --- Major mode for the Lutin language
(
require
'font-lock
)
;;; Code:
; version of lutin-mode
(
defvar
lutin-mode-hook
nil
)
(
defconst
lutin-mode-version
"0.0"
)
(
defvar
lutin-mode-map
(
let
((
map
(
make-sparse-keymap
)))
;;; Hooks
(
define-key
map
"|"
'tuareg-electric
)
map
)
(
defvar
lutin-mode-hook
nil
"Keymap for `lutin-mode'."
)
"functions called when entering Lutin Mode."
)
;;; Key-map for Lutin-mode
;;; Définir les groupes de mots-clés du langage Lutin
(
defvar
lutin-mode-map
nil
(
defconst
lutin-keywords-control
"Keymap for lutin major mode."
)
'
(
"loop"
"fby"
"raise"
"try"
"trap"
"catch"
"do"
)
"Mots-clés de contrôle (loop, fby, raise, etc.)."
)
;;; Font-lock -----------------------------------------------------
(
defconst
lutin-keywords-decl
'
(
"let"
"const"
"extern"
"node"
"run"
"include"
"returns"
"type"
)
(
defvar
lutin-font-lock-keywords
nil
"Mots-clés liés à la déclaration (const, extern, node, etc.)."
)
"Regular expression used by Font-lock mode."
)
(
defconst
lutin-keywords-scope
(
setq
lutin-font-lock-keywords
'
(
"assert"
"exist"
"in"
"if"
"then"
"else"
)
'
(
"Mots-clés conditionnels et d'affectation (let, assert, if, etc.)."
)
(
"--.*$"
.
font-lock-comment-face
)
(
"\\<\\(loop\\|fby\\||raise\\|try\\|trap\\|catch\\|do\\)\\>"
.
font-lock-builtin-face
)
(
defconst
lutin-keywords-logic-truth
(
"\\<\\(const\\|extern\\|node\\|run\\|include\\|returns\\|type\\)\\>"
.
font-lock-keyword-face
)
'
(
"true"
"and"
"or"
"not"
"false"
)
(
"\\<\\(let\\|assert\\|exist\\|in\\|if\\|then\\|else\\)\\>"
.
font-lock-keyword-face
)
"Mots-clés logiques (true, false, and, or, etc.)."
)
(
"\\<\\(true\\|and\\|or\\|not\\|false\\)\\>"
.
font-lock-reference-face
)
(
"\\<\\(trace\\|bool\\|int\\|ref\\|real\\)\\(\\^.+\\)?\\>"
.
font-lock-type-face
)
(
defconst
lutin-keywords-types
(
"\\<\\(pre\\)\\>"
.
font-lock-constant-face
)
'
(
"trace"
"bool"
"int"
"ref"
"real"
)
))
"Types (trace, bool, int, etc.)."
)
;;; Définir la coloration syntaxique
(
defconst
lutin-font-lock-keywords
(
defun
lutin-font-mode
()
(
let*
((
control-do-regexp
(
regexp-opt
lutin-keywords-control
'words
))
"Initialisation of font-lock for Lutin mode."
(
decl-regexp
(
regexp-opt
lutin-keywords-decl
'words
))
(
make-local-variable
'font-lock-defaults
)
(
scope-regexp
(
regexp-opt
lutin-keywords-scope
'words
))
(
setq
font-lock-defaults
(
logic-truth-regexp
(
regexp-opt
lutin-keywords-logic-truth
'words
))
'
(
lutin-font-lock-keywords
t
)))
(
types-regexp
(
regexp-opt
lutin-keywords-types
'words
)))
`
((
,
control-do-regexp
.
font-lock-keyword-face
)
; font-lock isn't used if in a console
(
,
decl-regexp
.
font-lock-constant-face
)
(
if
window-system
(
,
scope-regexp
.
font-lock-variable-name-face
)
(
prog2
(
,
logic-truth-regexp
.
font-lock-builtin-face
)
;; Couleur pour les mots-clés logiques
(
add-hook
'lutin-mode-hook
(
,
types-regexp
.
font-lock-type-face
)))
;; Couleur pour les types
'turn-on-font-lock
)
"Définition des expressions régulières pour la coloration syntaxique de Lutin."
)
(
add-hook
'lutin-mode-hook
'lutin-font-mode
)))
(
defvar
lutin-mode-syntax-table
(
make-syntax-table
)
"Syntax table used in the Lutin mode."
)
(
defun
lutin-line-is-comment
(
&optional
arg
)
"non-nil means line is only a commentary."
; `_' is also in words.
(
interactive
)
(
modify-syntax-entry
?\_
"w"
lutin-mode-syntax-table
)
(
save-excursion
; comment line finisher:
(
beginning-of-line
arg
)
(
modify-syntax-entry
?\n
">"
lutin-mode-syntax-table
)
(
skip-chars-forward
" \t"
)
; comment start if double,
(
looking-at
"--"
)))
; punct. otherwise.
(
modify-syntax-entry
?\-
". 12"
lutin-mode-syntax-table
)
(
setq
comment-start
"(*"
)
;; multiline comments (is this the right syntax?):
(
setq
comment-end
"*)"
)
; beg of multiline comment starter
(
modify-syntax-entry
?\(
"()1b"
lutin-mode-syntax-table
)
; beg of multiline comment finisher
(
setq
comment-start
"-- "
)
(
modify-syntax-entry
?\)
")(4b"
lutin-mode-syntax-table
)
(
setq
comment-end
""
)
; end & beg of multiline comment starter
; & finisher.
;;; Major-mode
(
modify-syntax-entry
?\*
". 23b"
lutin-mode-syntax-table
)
(
defun
lutin-mode
()
"Major mode for editing Lutin files.
;;; Définir le mode majeur Lutin
(
define-derived-mode
lutin-mode
prog-mode
"lutin"
Only keywords colaraition for the moment...
"Major mode for editing Lutin code."
"
:syntax-table
nil
(
setq
font-lock-defaults
'
(
lutin-font-lock-keywords
))
(
interactive
)
(
kill-all-local-variables
)
(
setq
major-mode
'lutin-mode
)
(
setq
mode-name
"Lutin"
)
(
use-local-map
lutin-mode-map
)
(
use-local-map
lutin-mode-map
)
(
run-hooks
'lutin-mode-hook
))
(
setq-local
comment-start
"--"
)
(
setq-local
comment-end
""
)
)
;;; Associating lutin-mode with .lutin files
(
add-to-list
'auto-mode-alist
'
(
"\\.lut\\'"
.
lutin-mode
))
;;; Fournir le mode
(
provide
'lutin-mode
)
; (require 'lutin-mode)
(
provide
'lutin
)
;;; lutin .el ends here...
;
;;; lutin .el ends here...
This diff is collapsed.
Click to expand it.
emacs/rif.el
+
60
−
57
View file @
d35866c6
;;; rif.el - Major mode for rif files in Emacs
;;; rif.el - Major mode for editing lustre source in Emacs
;;
;; Very very basic: provides only colors for keywords
;;;; to put in your .emacs:
;;; rif-mode.el --- Major mode for the Rif language
; (autoload 'rif-mode
; "rif" "Major mode for editing rif file." t)
(
require
'font-lock
)
;;; Code:
(
defvar
rif-mode-hook
nil
)
; version of rif-mode
(
defvar
rif-mode-map
(
defconst
rif-mode-version
"0.3"
)
(
let
((
map
(
make-sparse-keymap
)))
(
define-key
map
"|"
'tuareg-electric
)
map
)
"Keymap for `rif-mode'."
)
(
defvar
rif-mode-map
nil
"Keymap for rif major mode."
)
;;; Font-lock -----------------------------------------------------
;;; Définir les groupes de mots-clés du langage Rif
(
defconst
rif-keywords-pragma
'
(
"inputs"
"outputs"
"in"
"outs"
"step"
"locs"
)
"Pragmas"
)
(
defvar
rif-font-lock-keywords
nil
(
defconst
rif-keywords-logic
"Regular expression used by Font-lock mode."
)
'
(
"true"
"t"
"f"
"FALSE"
"TRUE"
"T"
"F"
"0"
"1"
"false"
)
"bool values"
)
(
setq
rif-font-lock-keywords
(
defconst
rif-keywords-types
'
((
"--.*$"
.
font-lock-comment-face
)
'
(
"bool"
"int"
"real"
)
"Types"
)
(
"\\<\\(inputs\\|step\\|locs\\|outs\\|inputs\\|outputs\\)\\>"
.
font-lock-string-face
)
(
"[][#]\\.?\\|\\.\\."
.
font-lock-function-name-face
)
(
"\\<\\(true\\|T\\|F\\|f\\|t\\|false\\)\\>"
.
font-lock-reference-face
)
(
"\\<\\(bool\\|int\\|real\\|float\\)\\(\\^.+\\)?\\>"
.
font-lock-variable-name-face
)
(
"\\(\\<\\(xxx\\|yyy\\)\\>\\|->\\)"
.
;;; Définir la coloration syntaxique
font-lock-function-name-face
)))
(
defconst
rif-font-lock-keywords
(
let*
((
pragma-do-regexp
(
regexp-opt
rif-keywords-pragma
'words
))
(
logic-regexp
(
regexp-opt
rif-keywords-logic
'words
))
(
types-regexp
(
regexp-opt
rif-keywords-types
'words
)))
`
((
,
pragma-do-regexp
.
font-lock-keyword-face
)
(
,
logic-regexp
.
font-lock-builtin-face
)
(
,
types-regexp
.
font-lock-type-face
)))
"Définition des expressions régulières pour la coloration syntaxique de Rif."
)
(
defvar
rif-mode-syntax-table
(
make-syntax-table
)
"Syntax table used in the Rif mode."
)
(
defun
rif-font-mode
()
; `_' is also in words.
"Initialisation of font-lock for Rif mode."
(
modify-syntax-entry
?\_
"w"
rif-mode-syntax-table
)
(
make-local-variable
'font-lock-defaults
)
; comment line finisher:
(
setq
font-lock-defaults
(
modify-syntax-entry
?\n
">"
rif-mode-syntax-table
)
'
(
rif-font-lock-keywords
t
)))
; comment start if double,
; punct. otherwise.
(
modify-syntax-entry
?\-
". 12"
rif-mode-syntax-table
)
; font-lock isn't used if in a console
;; multiline comments (is this the right syntax?):
(
if
window-system
; beg of multiline comment starter
(
prog2
(
modify-syntax-entry
?\(
"()1b"
rif-mode-syntax-table
)
(
add-hook
'rif-mode-hook
; beg of multiline comment finisher
'turn-on-font-lock
)
(
modify-syntax-entry
?\)
")(4b"
rif-mode-syntax-table
)
(
add-hook
'rif-mode-hook
; end & beg of multiline comment starter
'rif-font-mode
)))
; & finisher.
(
modify-syntax-entry
?\*
". 23b"
rif-mode-syntax-table
)
;;; Major-mode
;;; Définir le mode majeur Rif
(
define-derived-mode
rif-mode
prog-mode
"rif"
"Major mode for editing Rif code."
:syntax-table
nil
(
setq
font-lock-defaults
'
(
rif-font-lock-keywords
))
(
use-local-map
rif-mode-map
)
(
setq-local
comment-start
"# "
)
(
setq-local
comment-end
""
)
)
(
add-to-list
'auto-mode-alist
'
(
"\\.rif$"
.
rif-mode
))
;;; Associating rif-mode with .rif files
(
add-to-list
'auto-mode-alist
'
(
"\\.lut\\'"
.
rif-mode
))
;;; Fournir le mode
(
provide
'rif-mode
)
; (require 'rif-mode)
(
defun
rif-mode
()
" emacs mode for rif programs "
(
interactive
)
; ;;; rif.el ends here...
(
kill-all-local-variables
)
(
setq
major-mode
'rif-mode
)
(
setq
mode-name
"Rif"
)
(
use-local-map
rif-mode-map
)
(
make-local-variable
'indent-line-function
)
(
setq
indent-line-function
'electric-lustre-tab
)
(
run-hooks
'rif-mode-hook
)
)
(
setq
comment-start
"#"
)
(
provide
'rif
)
;;; rif .el ends here...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment