[lisppaste-requests] Erlang Syntax

kaz at kazmier.com kaz at kazmier.com
Thu Jun 15 00:55:06 UTC 2006


Just trying to submit my erlang syntax patch again.  It's been several
months since I first submitted it.  Hopefully someone can get around to
applying the patch.

Thanks,
Pete

-------------- next part --------------
Index: coloring-css.lisp
===================================================================
RCS file: /project/lisppaste/cvsroot/lisppaste2/coloring-css.lisp,v
retrieving revision 1.6
diff -u -r1.6 coloring-css.lisp
--- coloring-css.lisp	25 Sep 2004 20:20:27 -0000	1.6
+++ coloring-css.lisp	15 Jun 2006 00:42:22 -0000
@@ -12,6 +12,11 @@
 .keyword { color : #770000; background-color : inherit; }
 .comment { color : #007777; background-color : inherit; }
 .string { color : #777777; background-color : inherit; }
+.atom { color : #00AA50; background-color : inherit; }
+.macro { color : #CC8050; background-color : inherit; }
+.variable { color : #5500AA; background-color : inherit; }
+.function { color : #000099; background-color : inherit; font-weight: bold; }
+.attribute { color : #CC8050; background-color : inherit; font-weight: bold; }
 .character { color : #0055AA; background-color : inherit; }
 .syntaxerror { color : #FF0000; background-color : inherit; }
 span.paren1:hover { color : inherit; background-color : #BAFFFF; }
Index: coloring-types.lisp
===================================================================
RCS file: /project/lisppaste/cvsroot/lisppaste2/coloring-types.lisp,v
retrieving revision 1.17
diff -u -r1.17 coloring-types.lisp
--- coloring-types.lisp	6 Jun 2006 16:15:22 -0000	1.17
+++ coloring-types.lisp	15 Jun 2006 00:42:22 -0000
@@ -494,6 +494,180 @@
 	(setf is-keyword (not is-keyword))))))))
 
 
+(defvar *erlang-open-parens* "([{")
+(defvar *erlang-close-parens* ")]}")
+
+(defvar *erlang-reserved-words*
+  '("after" "andalso" "begin" "catch" "case" "end" "fun" "if" "of" "orelse"
+    "receive" "try" "when" "query" "is_atom" "is_binary" "is_constant"
+    "is_float" "is_function" "is_integer" "is_list" "is_number" "is_pid"
+    "is_port" "is_reference" "is_tuple" "is_record" "abs" "element" "float"
+    "hd" "tl" "length" "node" "round" "self" "size" "trunc" "alive" "apply"
+    "atom_to_list" "binary_to_list" "binary_to_term" "concat_binary"
+    "date" "disconnect_node" "erase" "exit" "float_to_list" "garbage_collect"
+    "get" "get_keys" "group_leader" "halt" "integer_to_list" "internal_bif"
+    "link" "list_to_atom" "list_to_binary" "list_to_float" "list_to_integer"
+    "make_ref" "node_link" "node_unlink" "notalive" "open_port" "pid_to_list"
+    "process_flag" "process_info" "processes" "put" "register" "registered"
+    "setelement" "spawn" "spawn_link" "split_binary" "statistics"
+    "term_to_binary" "time" "throw" "trace" "trunc" "tuple_to_list"
+    "unlink" "unregister" "whereis"))
+
+(defparameter *erlang-begin-word* "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789")
+(defparameter *erlang-begin-fun* "abcdefghijklmnopqrstuvwxyz")
+(defparameter *erlang-begin-var* "ABCDEFGHIJKLMNOPQRSTUVWXYZ_")
+(defparameter *erlang-terminators* '(#\space #\return #\tab #\newline #\. #\; #\, #\/ #\- #\* #\+ #\( #\) #\' #\" #\[ #\] #\< #\> #\{ #\}))
+
+(define-coloring-type :erlang "Erlang"
+  :modes (:first-char-on-line :normal :char :comment :word-ish :variable :atom  :paren-ish :string :single-escape :attribute :function :macro)
+  :default-mode :first-char-on-line
+  :transitions
+  (((:normal :paren-ish)
+    ((scan "%")
+     (set-mode :comment
+               :until (scan #\newline)))
+    ((scan-any *erlang-begin-var*)
+     (set-mode :variable
+               :until (scan-any *erlang-terminators*)
+               :advancing nil))
+    ((scan-any *erlang-begin-word*)
+     (set-mode :word-ish
+               :until (scan-any *erlang-terminators*)
+               :advancing nil))
+    ((or
+      (scan-any *erlang-open-parens*)
+      (scan-any *erlang-close-parens*))
+     (set-mode :paren-ish
+               :until (advance 1)
+               :advancing nil))
+    ((scan #\")
+     (set-mode :string
+               :until (scan #\")))
+    ((scan #\')
+     (set-mode :atom
+               :until (scan #\')))
+    ((scan #\?)
+     (set-mode :macro
+               :until (scan-any *erlang-terminators*)))
+    ((scan #\$)
+     (set-mode :char
+               :until (scan-any *erlang-terminators*)))
+    ((scan #\newline)
+     (set-mode :first-char-on-line)))
+   
+   ((:function :attribute)
+    ((or
+      (scan-any *erlang-open-parens*)
+      (scan-any *erlang-close-parens*))
+     (set-mode :paren-ish
+               :until (advance 1)
+               :advancing nil))
+    ((scan-any *erlang-terminators*)
+     (set-mode :normal
+               :until (scan #\newline))))
+   
+   (:first-char-on-line
+    ((scan "%")
+     (set-mode :comment
+               :until (scan #\newline)))
+    ((scan-any *erlang-begin-fun*)
+     (set-mode :function
+               :until (scan #\newline)
+               :advancing nil))
+    ((scan "-")
+     (set-mode :attribute
+               :until (scan #\newline)
+               :advancing nil))
+    ((advance 1)
+     (set-mode :normal
+               :until (scan #\newline))))
+   (:string
+    ((scan #\\)
+     (set-mode :single-escape
+               :until (advance 1)))))
+  :formatter-variables
+  ((paren-counter 0))
+  :formatter-after-hook (lambda nil
+                          (format nil "~{~A~}"
+                                  (loop for i from paren-counter downto 1
+                                        collect "</span></span>")))
+  :formatters
+  (((:normal :first-char-on-line)
+    (lambda (type s)
+      (declare (ignore type))
+      s))
+   (:comment
+    (lambda (type s)
+      (declare (ignore type))
+      (format nil "<span class=\"comment\">~A</span>"
+              s)))
+   (:string
+    (lambda (type s)
+      (declare (ignore type))
+      (format nil "<span class=\"string\">~A</span>"
+              s)))
+   (:variable
+    (lambda (type s)
+      (declare (ignore type))
+      (format nil "<span class=\"variable\">~A</span>"
+              s)))
+   (:function
+    (lambda (type s)
+      (declare (ignore type))
+      (format nil "<span class=\"function\">~A</span>"
+              s)))
+   (:attribute
+    (lambda (type s)
+      (declare (ignore type))
+      (format nil "<span class=\"attribute\">~A</span>"
+              s)))
+   (:macro
+    (lambda (type s)
+      (declare (ignore type))
+      (format nil "<span class=\"macro\">~A</span>"
+              s)))
+   (:atom
+    (lambda (type s)
+      (declare (ignore type))
+      (format nil "<span class=\"atom\">~A</span>"
+              s)))
+   (:char
+    (lambda (type s)
+      (declare (ignore type))
+      (format nil "<span class=\"character\">~A</span>"
+              s)))
+   (:single-escape
+    (lambda (type s)
+      (call-formatter (cdr type) s)))
+   (:paren-ish
+    (lambda (type s)
+      (declare (ignore type))
+      (let ((open nil)
+            (count 0))
+        (if (eql (length s) 1)
+            (progn
+              (when (member (elt s 0) (coerce *erlang-open-parens* 'list))
+                (setf open t)
+                (setf count (mod paren-counter 6))
+                (incf paren-counter))
+              (when (member (elt s 0) (coerce *erlang-close-parens* 'list))
+                (setf open nil)
+                (decf paren-counter)
+                (setf count (mod paren-counter 6)))
+              (if open
+                  (format nil "<span class=\"paren~A\">~A<span class=\"~A\">"
+                          (1+ count) s *css-background-class*)
+                  (format nil "</span>~A</span>"
+                          s)))
+            s))))
+   (:word-ish
+    (lambda (type s)
+      (declare (ignore type))
+      (if (member s *erlang-reserved-words* :test #'string=)
+          (format nil "<span class=\"symbol\">~A</span>" s)
+          s)))
+   ))
+
 (defvar *python-reserved-words*
   '("and"       "assert"        "break"         "class"         "continue"
     "def"       "del"           "elif"          "else"          "except"


More information about the lisppaste-requests mailing list