SWAN Syntax Highlighting for emacs
Copy the following lines into your .emacs file to enable the highlighting of SWAN keywords in DML files.
;; SWAN DML syntax hilighting:
(define-generic-mode 'dml-mode '("#")
'("model" "Model" "MODEL"
"Host" "host" "HOST"
"network" "Network" "NETWORK"
"arena" "Arena" "ARENA"
"interface" "Interface" "INTERFACE"
"ProtocolSession" "protocolsession"
"graph" "Graph" "GRAPH"
"global" "Global" "GLOBAL"
"mobility" "Mobility" "MOBILITY"
"report" "Report" "REPORT"
"metric" "Metric" "METRIC"
"propagation" "Propagation" "PROPAGATION")
'(("[0-9]+" . 'font-lock-variable-name-face)
("_\\(schema\\|find\\|extends\\)" . 'font-lock-constant-face))
'(".dml\\'")
nil
"Major mode for editing dml files.")
(Semi)automatic extraction of DML keywords
The source code repository contains a Ruby script that can parse the SWAN source code for DML keywords and automatically generate a syntax definition for Emacs. The script is ruby/extractdml.rb.
To extract DML keywords from the SWAN source code:
- Run the script:
extractdml.rb [source directory]
The script takes one argument: the path to the SWAN source code. If run in the script's directory, this is normally ../src, meaning the script can be run by typing:extractdml.rb ../src
- The script will output a file called emacs in the current directory. This file will contain a syntax definition for Emacs. Copy the contents of this file to ~/.emacs to enable this highlighting. (Delete any old DML syntax definitions you may have in your .emacs file.)
Variable bindings
One possible problem with the script is that it generates a lot of keywords—currently, 678. By default, GNU Emacs' Lisp interpreter only allows bindings for up to 600 variables, as noted in the GNU Emacs Lisp reference manual. This value is set by the max-specpdl-size variable.
To work around this issue, the syntax definition sets the max-specpdl-size value with the first line of the script:
(setq max-specpdl-size $value)
where $value is a dynamically-calculated number from the Ruby script. More information can be found in the comments for [26].
