FUEL: Add UNION-STRUCT: to syntax highlighting.

db4
Erik Charlebois 2010-02-21 16:42:31 -08:00
parent 9b8fd8d160
commit 52a8c3ebc9
1 changed files with 456 additions and 456 deletions

View File

@ -1,456 +1,456 @@
;;; fuel-syntax.el --- auxiliar definitions for factor code navigation. ;;; fuel-syntax.el --- auxiliar definitions for factor code navigation.
;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz ;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz
;; See http://factorcode.org/license.txt for BSD license. ;; See http://factorcode.org/license.txt for BSD license.
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org> ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
;; Keywords: languages ;; Keywords: languages
;;; Commentary: ;;; Commentary:
;; Auxiliar constants and functions to parse factor code. ;; Auxiliar constants and functions to parse factor code.
;;; Code: ;;; Code:
(require 'thingatpt) (require 'thingatpt)
;;; Thing-at-point support for factor symbols: ;;; Thing-at-point support for factor symbols:
(defun fuel-syntax--beginning-of-symbol () (defun fuel-syntax--beginning-of-symbol ()
"Move point to the beginning of the current symbol." "Move point to the beginning of the current symbol."
(skip-syntax-backward "w_()")) (skip-syntax-backward "w_()"))
(defsubst fuel-syntax--beginning-of-symbol-pos () (defsubst fuel-syntax--beginning-of-symbol-pos ()
(save-excursion (fuel-syntax--beginning-of-symbol) (point))) (save-excursion (fuel-syntax--beginning-of-symbol) (point)))
(defun fuel-syntax--end-of-symbol () (defun fuel-syntax--end-of-symbol ()
"Move point to the end of the current symbol." "Move point to the end of the current symbol."
(skip-syntax-forward "w_()")) (skip-syntax-forward "w_()"))
(defsubst fuel-syntax--end-of-symbol-pos () (defsubst fuel-syntax--end-of-symbol-pos ()
(save-excursion (fuel-syntax--end-of-symbol) (point))) (save-excursion (fuel-syntax--end-of-symbol) (point)))
(put 'factor-symbol 'end-op 'fuel-syntax--end-of-symbol) (put 'factor-symbol 'end-op 'fuel-syntax--end-of-symbol)
(put 'factor-symbol 'beginning-op 'fuel-syntax--beginning-of-symbol) (put 'factor-symbol 'beginning-op 'fuel-syntax--beginning-of-symbol)
(defsubst fuel-syntax-symbol-at-point () (defsubst fuel-syntax-symbol-at-point ()
(let ((s (substring-no-properties (thing-at-point 'factor-symbol)))) (let ((s (substring-no-properties (thing-at-point 'factor-symbol))))
(and (> (length s) 0) s))) (and (> (length s) 0) s)))
;;; Regexps galore: ;;; Regexps galore:
(defconst fuel-syntax--parsing-words (defconst fuel-syntax--parsing-words
'(":" "::" ";" "&:" "<<" "<PRIVATE" ">>" '(":" "::" ";" "&:" "<<" "<PRIVATE" ">>"
"ABOUT:" "ALIAS:" "ALIEN:" "ARTICLE:" "ABOUT:" "ALIAS:" "ALIEN:" "ARTICLE:"
"B" "BIN:" "B" "BIN:"
"C:" "CALLBACK:" "C-ENUM:" "C-STRUCT:" "C-TYPE:" "C-UNION:" "CHAR:" "CONSTANT:" "call-next-method" "C:" "CALLBACK:" "C-ENUM:" "C-STRUCT:" "C-TYPE:" "C-UNION:" "CHAR:" "CONSTANT:" "call-next-method"
"DEFER:" "DEFER:"
"EBNF:" ";EBNF" "ERROR:" "EXCLUDE:" "EBNF:" ";EBNF" "ERROR:" "EXCLUDE:"
"f" "FORGET:" "FROM:" "FUNCTION:" "f" "FORGET:" "FROM:" "FUNCTION:"
"GAME:" "GENERIC#" "GENERIC:" "GAME:" "GENERIC#" "GENERIC:"
"GLSL-SHADER:" "GLSL-PROGRAM:" "GLSL-SHADER:" "GLSL-PROGRAM:"
"HELP:" "HEX:" "HOOK:" "HELP:" "HEX:" "HOOK:"
"IN:" "initial:" "INSTANCE:" "INTERSECTION:" "IN:" "initial:" "INSTANCE:" "INTERSECTION:"
"LIBRARY:" "LIBRARY:"
"M:" "M::" "MACRO:" "MACRO::" "MAIN:" "MATH:" "M:" "M::" "MACRO:" "MACRO::" "MAIN:" "MATH:"
"MEMO:" "MEMO:" "METHOD:" "MIXIN:" "MEMO:" "MEMO:" "METHOD:" "MIXIN:"
"OCT:" "OCT:"
"POSTPONE:" "PREDICATE:" "PRIMITIVE:" "PRIVATE>" "PROVIDE:" "POSTPONE:" "PREDICATE:" "PRIMITIVE:" "PRIVATE>" "PROVIDE:"
"QUALIFIED-WITH:" "QUALIFIED:" "QUALIFIED-WITH:" "QUALIFIED:"
"read-only" "RENAME:" "REQUIRE:" "REQUIRES:" "read-only" "RENAME:" "REQUIRE:" "REQUIRES:"
"SINGLETON:" "SINGLETONS:" "SLOT:" "SPECIALIZED-ARRAY:" "SPECIALIZED-ARRAYS:" "STRING:" "STRUCT:" "SYMBOL:" "SYMBOLS:" "SYNTAX:" "SINGLETON:" "SINGLETONS:" "SLOT:" "SPECIALIZED-ARRAY:" "SPECIALIZED-ARRAYS:" "STRING:" "STRUCT:" "SYMBOL:" "SYMBOLS:" "SYNTAX:"
"TUPLE:" "t" "t?" "TYPEDEF:" "TYPED:" "TYPED::" "TUPLE:" "t" "t?" "TYPEDEF:" "TYPED:" "TYPED::"
"UNIFORM-TUPLE:" "UNION:" "USE:" "USING:" "UNIFORM-TUPLE:" "UNION:" "UNION-STRUCT:" "USE:" "USING:"
"VARS:" "VERTEX-FORMAT:")) "VARS:" "VERTEX-FORMAT:"))
(defconst fuel-syntax--parsing-words-regex (defconst fuel-syntax--parsing-words-regex
(regexp-opt fuel-syntax--parsing-words 'words)) (regexp-opt fuel-syntax--parsing-words 'words))
(defconst fuel-syntax--bracers (defconst fuel-syntax--bracers
'("B" "BV" "C" "CS" "H" "T" "V" "W")) '("B" "BV" "C" "CS" "H" "T" "V" "W"))
(defconst fuel-syntax--brace-words-regex (defconst fuel-syntax--brace-words-regex
(format "%s{" (regexp-opt fuel-syntax--bracers t))) (format "%s{" (regexp-opt fuel-syntax--bracers t)))
(defconst fuel-syntax--declaration-words (defconst fuel-syntax--declaration-words
'("flushable" "foldable" "inline" "parsing" "recursive" "delimiter")) '("flushable" "foldable" "inline" "parsing" "recursive" "delimiter"))
(defconst fuel-syntax--declaration-words-regex (defconst fuel-syntax--declaration-words-regex
(regexp-opt fuel-syntax--declaration-words 'words)) (regexp-opt fuel-syntax--declaration-words 'words))
(defsubst fuel-syntax--second-word-regex (prefixes) (defsubst fuel-syntax--second-word-regex (prefixes)
(format "%s +\\([^ \r\n]+\\)" (regexp-opt prefixes t))) (format "%s +\\([^ \r\n]+\\)" (regexp-opt prefixes t)))
(defconst fuel-syntax--method-definition-regex (defconst fuel-syntax--method-definition-regex
"^M::? +\\([^ ]+\\) +\\([^ ]+\\)") "^M::? +\\([^ ]+\\) +\\([^ ]+\\)")
(defconst fuel-syntax--integer-regex (defconst fuel-syntax--integer-regex
"\\_<-?[0-9]+\\_>") "\\_<-?[0-9]+\\_>")
(defconst fuel-syntax--raw-float-regex (defconst fuel-syntax--raw-float-regex
"[0-9]*\\.[0-9]*\\([eE][+-]?[0-9]+\\)?") "[0-9]*\\.[0-9]*\\([eE][+-]?[0-9]+\\)?")
(defconst fuel-syntax--float-regex (defconst fuel-syntax--float-regex
(format "\\_<-?%s\\_>" fuel-syntax--raw-float-regex)) (format "\\_<-?%s\\_>" fuel-syntax--raw-float-regex))
(defconst fuel-syntax--number-regex (defconst fuel-syntax--number-regex
(format "\\([0-9]+\\|%s\\)" fuel-syntax--raw-float-regex)) (format "\\([0-9]+\\|%s\\)" fuel-syntax--raw-float-regex))
(defconst fuel-syntax--ratio-regex (defconst fuel-syntax--ratio-regex
(format "\\_<[+-]?%s/-?%s\\_>" (format "\\_<[+-]?%s/-?%s\\_>"
fuel-syntax--number-regex fuel-syntax--number-regex
fuel-syntax--number-regex)) fuel-syntax--number-regex))
(defconst fuel-syntax--bad-string-regex (defconst fuel-syntax--bad-string-regex
"\\_<\"[^>]\\([^\"\n]\\|\\\\\"\\)*\n") "\\_<\"[^>]\\([^\"\n]\\|\\\\\"\\)*\n")
(defconst fuel-syntax--word-definition-regex (defconst fuel-syntax--word-definition-regex
(format "\\_<\\(%s\\)?: +\\_<\\(\\w+\\)\\_>" (format "\\_<\\(%s\\)?: +\\_<\\(\\w+\\)\\_>"
(regexp-opt (regexp-opt
'(":" "GENERIC" "DEFER" "HOOK" "MAIN" "MATH" "POSTPONE" '(":" "GENERIC" "DEFER" "HOOK" "MAIN" "MATH" "POSTPONE"
"SYMBOL" "SYNTAX" "TYPED" "RENAME")))) "SYMBOL" "SYNTAX" "TYPED" "RENAME"))))
(defconst fuel-syntax--alias-definition-regex (defconst fuel-syntax--alias-definition-regex
"^ALIAS: +\\(\\_<.+?\\_>\\) +\\(\\_<.+?\\_>\\)") "^ALIAS: +\\(\\_<.+?\\_>\\) +\\(\\_<.+?\\_>\\)")
(defconst fuel-syntax--vocab-ref-regexp (defconst fuel-syntax--vocab-ref-regexp
(fuel-syntax--second-word-regex (fuel-syntax--second-word-regex
'("IN:" "USE:" "FROM:" "EXCLUDE:" "QUALIFIED:" "QUALIFIED-WITH:"))) '("IN:" "USE:" "FROM:" "EXCLUDE:" "QUALIFIED:" "QUALIFIED-WITH:")))
(defconst fuel-syntax--int-constant-def-regex (defconst fuel-syntax--int-constant-def-regex
(fuel-syntax--second-word-regex '("ALIEN:" "CHAR:" "BIN:" "HEX:" "OCT:"))) (fuel-syntax--second-word-regex '("ALIEN:" "CHAR:" "BIN:" "HEX:" "OCT:")))
(defconst fuel-syntax--type-definition-regex (defconst fuel-syntax--type-definition-regex
(fuel-syntax--second-word-regex (fuel-syntax--second-word-regex
'("C-STRUCT:" "C-UNION:" "MIXIN:" "TUPLE:" "SINGLETON:" "SPECIALIZED-ARRAY:" "STRUCT:" "UNION:"))) '("C-STRUCT:" "C-UNION:" "MIXIN:" "TUPLE:" "SINGLETON:" "SPECIALIZED-ARRAY:" "STRUCT:" "UNION:" "UNION-STRUCT:")))
(defconst fuel-syntax--tuple-decl-regex (defconst fuel-syntax--tuple-decl-regex
"^TUPLE: +\\([^ \n]+\\) +< +\\([^ \n]+\\)\\_>") "^TUPLE: +\\([^ \n]+\\) +< +\\([^ \n]+\\)\\_>")
(defconst fuel-syntax--constructor-regex "<[^ >]+>") (defconst fuel-syntax--constructor-regex "<[^ >]+>")
(defconst fuel-syntax--getter-regex "\\(^\\|\\_<\\)[^ ]+?>>\\_>") (defconst fuel-syntax--getter-regex "\\(^\\|\\_<\\)[^ ]+?>>\\_>")
(defconst fuel-syntax--setter-regex "\\_<>>.+?\\_>") (defconst fuel-syntax--setter-regex "\\_<>>.+?\\_>")
(defconst fuel-syntax--symbol-definition-regex (defconst fuel-syntax--symbol-definition-regex
(fuel-syntax--second-word-regex '("&:" "SYMBOL:" "VAR:"))) (fuel-syntax--second-word-regex '("&:" "SYMBOL:" "VAR:")))
(defconst fuel-syntax--stack-effect-regex (defconst fuel-syntax--stack-effect-regex
"\\( ( [^\n]* )\\)\\|\\( (( [^\n]* ))\\)") "\\( ( [^\n]* )\\)\\|\\( (( [^\n]* ))\\)")
(defconst fuel-syntax--using-lines-regex "^USING: +\\([^;]+\\);") (defconst fuel-syntax--using-lines-regex "^USING: +\\([^;]+\\);")
(defconst fuel-syntax--use-line-regex "^USE: +\\(.*\\)$") (defconst fuel-syntax--use-line-regex "^USE: +\\(.*\\)$")
(defconst fuel-syntax--current-vocab-regex "^IN: +\\([^ \r\n\f]+\\)") (defconst fuel-syntax--current-vocab-regex "^IN: +\\([^ \r\n\f]+\\)")
(defconst fuel-syntax--sub-vocab-regex "^<\\([^ \n]+\\) *$") (defconst fuel-syntax--sub-vocab-regex "^<\\([^ \n]+\\) *$")
(defconst fuel-syntax--alien-function-regex (defconst fuel-syntax--alien-function-regex
"\\_<FUNCTION: \\(\\w+\\) \\(\\w+\\)") "\\_<FUNCTION: \\(\\w+\\) \\(\\w+\\)")
(defconst fuel-syntax--alien-callback-regex (defconst fuel-syntax--alien-callback-regex
"\\_<CALLBACK: \\(\\w+\\) \\(\\w+\\)") "\\_<CALLBACK: \\(\\w+\\) \\(\\w+\\)")
(defconst fuel-syntax--indent-def-starts '("" ":" (defconst fuel-syntax--indent-def-starts '("" ":"
"C-ENUM" "C-STRUCT" "C-UNION" "C-ENUM" "C-STRUCT" "C-UNION"
"FROM" "FUNCTION:" "FROM" "FUNCTION:"
"INTERSECTION:" "INTERSECTION:"
"M" "M:" "MACRO" "MACRO:" "M" "M:" "MACRO" "MACRO:"
"MEMO" "MEMO:" "METHOD" "MEMO" "MEMO:" "METHOD"
"SYNTAX" "SYNTAX"
"PREDICATE" "PRIMITIVE" "PREDICATE" "PRIMITIVE"
"STRUCT" "TAG" "TUPLE" "STRUCT" "TAG" "TUPLE"
"TYPED" "TYPED:" "TYPED" "TYPED:"
"UNIFORM-TUPLE" "UNIFORM-TUPLE"
"UNION-STRUCT" "UNION" "UNION-STRUCT" "UNION"
"VERTEX-FORMAT")) "VERTEX-FORMAT"))
(defconst fuel-syntax--no-indent-def-starts '("ARTICLE" (defconst fuel-syntax--no-indent-def-starts '("ARTICLE"
"HELP" "HELP"
"SINGLETONS" "SINGLETONS"
"SPECIALIZED-ARRAYS" "SPECIALIZED-ARRAYS"
"SYMBOLS" "SYMBOLS"
"VARS")) "VARS"))
(defconst fuel-syntax--indent-def-start-regex (defconst fuel-syntax--indent-def-start-regex
(format "^\\(%s:\\)\\( \\|\n\\)" (regexp-opt fuel-syntax--indent-def-starts))) (format "^\\(%s:\\)\\( \\|\n\\)" (regexp-opt fuel-syntax--indent-def-starts)))
(defconst fuel-syntax--definition-start-regex (defconst fuel-syntax--definition-start-regex
(format "^\\(%s:\\) " (regexp-opt (append fuel-syntax--no-indent-def-starts (format "^\\(%s:\\) " (regexp-opt (append fuel-syntax--no-indent-def-starts
fuel-syntax--indent-def-starts)))) fuel-syntax--indent-def-starts))))
(defconst fuel-syntax--definition-end-regex (defconst fuel-syntax--definition-end-regex
(format "\\(\\(^\\| +\\);\\( *%s\\)*\\($\\| +\\)\\)" (format "\\(\\(^\\| +\\);\\( *%s\\)*\\($\\| +\\)\\)"
fuel-syntax--declaration-words-regex)) fuel-syntax--declaration-words-regex))
(defconst fuel-syntax--single-liner-regex (defconst fuel-syntax--single-liner-regex
(regexp-opt '("ABOUT:" (regexp-opt '("ABOUT:"
"ALIAS:" "ALIAS:"
"CONSTANT:" "C:" "C-TYPE:" "CONSTANT:" "C:" "C-TYPE:"
"DEFER:" "DEFER:"
"FORGET:" "FORGET:"
"GAME:" "GENERIC:" "GENERIC#" "GLSL-PROGRAM:" "GAME:" "GENERIC:" "GENERIC#" "GLSL-PROGRAM:"
"HEX:" "HOOK:" "HEX:" "HOOK:"
"IN:" "INSTANCE:" "IN:" "INSTANCE:"
"LIBRARY:" "LIBRARY:"
"MAIN:" "MATH:" "MIXIN:" "MAIN:" "MATH:" "MIXIN:"
"OCT:" "OCT:"
"POSTPONE:" "PRIVATE>" "<PRIVATE" "POSTPONE:" "PRIVATE>" "<PRIVATE"
"QUALIFIED-WITH:" "QUALIFIED:" "QUALIFIED-WITH:" "QUALIFIED:"
"RENAME:" "RENAME:"
"SINGLETON:" "SLOT:" "SPECIALIZED-ARRAY:" "SYMBOL:" "SINGLETON:" "SLOT:" "SPECIALIZED-ARRAY:" "SYMBOL:"
"TYPEDEF:" "TYPEDEF:"
"USE:" "USE:"
"VAR:"))) "VAR:")))
(defconst fuel-syntax--begin-of-def-regex (defconst fuel-syntax--begin-of-def-regex
(format "^USING: \\|\\(%s\\)\\|\\(^%s .*\\)" (format "^USING: \\|\\(%s\\)\\|\\(^%s .*\\)"
fuel-syntax--definition-start-regex fuel-syntax--definition-start-regex
fuel-syntax--single-liner-regex)) fuel-syntax--single-liner-regex))
(defconst fuel-syntax--end-of-def-line-regex (defconst fuel-syntax--end-of-def-line-regex
(format "^.*%s" fuel-syntax--definition-end-regex)) (format "^.*%s" fuel-syntax--definition-end-regex))
(defconst fuel-syntax--end-of-def-regex (defconst fuel-syntax--end-of-def-regex
(format "\\(%s\\)\\|\\(^%s .*\\)" (format "\\(%s\\)\\|\\(^%s .*\\)"
fuel-syntax--end-of-def-line-regex fuel-syntax--end-of-def-line-regex
fuel-syntax--single-liner-regex)) fuel-syntax--single-liner-regex))
(defconst fuel-syntax--word-signature-regex (defconst fuel-syntax--word-signature-regex
(format ":[^ ]* \\([^ ]+\\)\\(%s\\)*" fuel-syntax--stack-effect-regex)) (format ":[^ ]* \\([^ ]+\\)\\(%s\\)*" fuel-syntax--stack-effect-regex))
(defconst fuel-syntax--defun-signature-regex (defconst fuel-syntax--defun-signature-regex
(format "\\(%s\\|%s\\)" (format "\\(%s\\|%s\\)"
fuel-syntax--word-signature-regex fuel-syntax--word-signature-regex
"M[^:]*: [^ ]+ [^ ]+")) "M[^:]*: [^ ]+ [^ ]+"))
(defconst fuel-syntax--constructor-decl-regex (defconst fuel-syntax--constructor-decl-regex
"\\_<C: +\\(\\w+\\) +\\(\\w+\\)\\( .*\\)?$") "\\_<C: +\\(\\w+\\) +\\(\\w+\\)\\( .*\\)?$")
(defconst fuel-syntax--typedef-regex (defconst fuel-syntax--typedef-regex
"\\_<TYPEDEF: +\\(\\w+\\) +\\(\\w+\\)\\( .*\\)?$") "\\_<TYPEDEF: +\\(\\w+\\) +\\(\\w+\\)\\( .*\\)?$")
(defconst fuel-syntax--rename-regex (defconst fuel-syntax--rename-regex
"\\_<RENAME: +\\(\\w+\\) +\\(\\w+\\) +=> +\\(\\w+\\)\\( .*\\)?$") "\\_<RENAME: +\\(\\w+\\) +\\(\\w+\\) +=> +\\(\\w+\\)\\( .*\\)?$")
;;; Factor syntax table ;;; Factor syntax table
(setq fuel-syntax--syntax-table (setq fuel-syntax--syntax-table
(let ((table (make-syntax-table))) (let ((table (make-syntax-table)))
;; Default is word constituent ;; Default is word constituent
(dotimes (i 256) (dotimes (i 256)
(modify-syntax-entry i "w" table)) (modify-syntax-entry i "w" table))
;; Whitespace (TAB is not whitespace) ;; Whitespace (TAB is not whitespace)
(modify-syntax-entry ?\f " " table) (modify-syntax-entry ?\f " " table)
(modify-syntax-entry ?\r " " table) (modify-syntax-entry ?\r " " table)
(modify-syntax-entry ?\ " " table) (modify-syntax-entry ?\ " " table)
(modify-syntax-entry ?\n " " table) (modify-syntax-entry ?\n " " table)
table)) table))
(defconst fuel-syntax--syntactic-keywords (defconst fuel-syntax--syntactic-keywords
`(;; Strings and chars `(;; Strings and chars
("\\_<<\\(\"\\)\\_>" (1 "<b")) ("\\_<<\\(\"\\)\\_>" (1 "<b"))
("\\_<\\(\"\\)>\\_>" (1 ">b")) ("\\_<\\(\"\\)>\\_>" (1 ">b"))
("\\( \\|^\\)\\(DLL\\|P\\|SBUF\\)?\\(\"\\)\\(\\([^\n\r\f\"\\]\\|\\\\.\\)*\\)\\(\"\\)" ("\\( \\|^\\)\\(DLL\\|P\\|SBUF\\)?\\(\"\\)\\(\\([^\n\r\f\"\\]\\|\\\\.\\)*\\)\\(\"\\)"
(3 "\"") (6 "\"")) (3 "\"") (6 "\""))
("CHAR: \\(\"\\) [^\\\"]*?\\(\"\\)\\([^\\\"]\\|\\\\.\\)*?\\(\"\\)" ("CHAR: \\(\"\\) [^\\\"]*?\\(\"\\)\\([^\\\"]\\|\\\\.\\)*?\\(\"\\)"
(1 "w") (2 "<b") (4 ">b")) (1 "w") (2 "<b") (4 ">b"))
("\\(CHAR:\\|\\\\\\) \\(\\w\\|!\\)\\( \\|$\\)" (2 "w")) ("\\(CHAR:\\|\\\\\\) \\(\\w\\|!\\)\\( \\|$\\)" (2 "w"))
;; Comments ;; Comments
("\\_<\\(#?!\\) .*\\(\n\\|$\\)" (1 "<") (2 ">")) ("\\_<\\(#?!\\) .*\\(\n\\|$\\)" (1 "<") (2 ">"))
("\\_<\\(#?!\\)\\(\n\\|$\\)" (1 "<") (2 ">")) ("\\_<\\(#?!\\)\\(\n\\|$\\)" (1 "<") (2 ">"))
;; postpone ;; postpone
("\\_<POSTPONE:\\( \\).*\\(\n\\)" (1 "<b") (2 ">b")) ("\\_<POSTPONE:\\( \\).*\\(\n\\)" (1 "<b") (2 ">b"))
;; Multiline constructs ;; Multiline constructs
("\\_<\\(E\\)BNF:\\( \\|\n\\)" (1 "<b")) ("\\_<\\(E\\)BNF:\\( \\|\n\\)" (1 "<b"))
("\\_<;EBN\\(F\\)\\_>" (1 ">b")) ("\\_<;EBN\\(F\\)\\_>" (1 ">b"))
("\\_<\\(U\\)SING: \\(;\\)" (1 "<b") (2 ">b")) ("\\_<\\(U\\)SING: \\(;\\)" (1 "<b") (2 ">b"))
("\\_<USING:\\( \\)" (1 "<b")) ("\\_<USING:\\( \\)" (1 "<b"))
("\\_<\\(C\\)-ENUM: \\(;\\)" (1 "<b") (2 ">b")) ("\\_<\\(C\\)-ENUM: \\(;\\)" (1 "<b") (2 ">b"))
("\\_<C-ENUM:\\( \\|\n\\)" (1 "<b")) ("\\_<C-ENUM:\\( \\|\n\\)" (1 "<b"))
("\\_<TUPLE: +\\w+? +< +\\w+? *\\( \\|\n\\)\\([^;]\\|$\\)" (1 "<b")) ("\\_<TUPLE: +\\w+? +< +\\w+? *\\( \\|\n\\)\\([^;]\\|$\\)" (1 "<b"))
("\\_<TUPLE: +\\w+? *\\( \\|\n\\)\\([^;<\n]\\|\\_>\\)" (1 "<b")) ("\\_<TUPLE: +\\w+? *\\( \\|\n\\)\\([^;<\n]\\|\\_>\\)" (1 "<b"))
("\\_<\\(SYMBOLS\\|VARS\\|SPECIALIZED-ARRAYS\\|SINGLETONS\\): *?\\( \\|\n\\)\\([^;\n]\\|\\_>\\)" ("\\_<\\(SYMBOLS\\|VARS\\|SPECIALIZED-ARRAYS\\|SINGLETONS\\): *?\\( \\|\n\\)\\([^;\n]\\|\\_>\\)"
(2 "<b")) (2 "<b"))
("\\(\n\\| \\);\\_>" (1 ">b")) ("\\(\n\\| \\);\\_>" (1 ">b"))
;; Let and lambda: ;; Let and lambda:
("\\_<\\(!(\\) .* \\()\\)" (1 "<") (2 ">")) ("\\_<\\(!(\\) .* \\()\\)" (1 "<") (2 ">"))
("\\(\\[\\)\\(let\\|let\\*\\)\\( \\|$\\)" (1 "(]")) ("\\(\\[\\)\\(let\\|let\\*\\)\\( \\|$\\)" (1 "(]"))
("\\(\\[\\)\\(|\\) +[^|]* \\(|\\)" (1 "(]") (2 "(|") (3 ")|")) ("\\(\\[\\)\\(|\\) +[^|]* \\(|\\)" (1 "(]") (2 "(|") (3 ")|"))
(" \\(|\\) " (1 "(|")) (" \\(|\\) " (1 "(|"))
(" \\(|\\)$" (1 ")")) (" \\(|\\)$" (1 ")"))
;; Opening brace words: ;; Opening brace words:
("\\_<\\w*\\({\\)\\_>" (1 "(}")) ("\\_<\\w*\\({\\)\\_>" (1 "(}"))
("\\_<\\(}\\)\\_>" (1 "){")) ("\\_<\\(}\\)\\_>" (1 "){"))
;; Parenthesis: ;; Parenthesis:
("\\_<\\((\\)\\_>" (1 "()")) ("\\_<\\((\\)\\_>" (1 "()"))
("\\_<\\w*\\((\\)\\_>" (1 "()")) ("\\_<\\w*\\((\\)\\_>" (1 "()"))
("\\_<\\()\\)\\_>" (1 ")(")) ("\\_<\\()\\)\\_>" (1 ")("))
("\\_<(\\((\\)\\_>" (1 "()")) ("\\_<(\\((\\)\\_>" (1 "()"))
("\\_<\\()\\))\\_>" (1 ")(")) ("\\_<\\()\\))\\_>" (1 ")("))
;; Quotations: ;; Quotations:
("\\_<'\\(\\[\\)\\_>" (1 "(]")) ; fried ("\\_<'\\(\\[\\)\\_>" (1 "(]")) ; fried
("\\_<$\\(\\[\\)\\_>" (1 "(]")) ; parse-time ("\\_<$\\(\\[\\)\\_>" (1 "(]")) ; parse-time
("\\_<\\(\\[\\)\\_>" (1 "(]")) ("\\_<\\(\\[\\)\\_>" (1 "(]"))
("\\_<\\(\\]\\)\\_>" (1 ")[")))) ("\\_<\\(\\]\\)\\_>" (1 ")["))))
;;; Source code analysis: ;;; Source code analysis:
(defsubst fuel-syntax--brackets-depth () (defsubst fuel-syntax--brackets-depth ()
(nth 0 (syntax-ppss))) (nth 0 (syntax-ppss)))
(defsubst fuel-syntax--brackets-start () (defsubst fuel-syntax--brackets-start ()
(nth 1 (syntax-ppss))) (nth 1 (syntax-ppss)))
(defun fuel-syntax--brackets-end () (defun fuel-syntax--brackets-end ()
(save-excursion (save-excursion
(goto-char (fuel-syntax--brackets-start)) (goto-char (fuel-syntax--brackets-start))
(condition-case nil (condition-case nil
(progn (forward-sexp) (progn (forward-sexp)
(1- (point))) (1- (point)))
(error -1)))) (error -1))))
(defsubst fuel-syntax--indentation-at (pos) (defsubst fuel-syntax--indentation-at (pos)
(save-excursion (goto-char pos) (current-indentation))) (save-excursion (goto-char pos) (current-indentation)))
(defsubst fuel-syntax--increased-indentation (&optional i) (defsubst fuel-syntax--increased-indentation (&optional i)
(+ (or i (current-indentation)) factor-indent-width)) (+ (or i (current-indentation)) factor-indent-width))
(defsubst fuel-syntax--decreased-indentation (&optional i) (defsubst fuel-syntax--decreased-indentation (&optional i)
(- (or i (current-indentation)) factor-indent-width)) (- (or i (current-indentation)) factor-indent-width))
(defsubst fuel-syntax--at-begin-of-def () (defsubst fuel-syntax--at-begin-of-def ()
(looking-at fuel-syntax--begin-of-def-regex)) (looking-at fuel-syntax--begin-of-def-regex))
(defsubst fuel-syntax--at-begin-of-indent-def () (defsubst fuel-syntax--at-begin-of-indent-def ()
(looking-at fuel-syntax--indent-def-start-regex)) (looking-at fuel-syntax--indent-def-start-regex))
(defsubst fuel-syntax--at-end-of-def () (defsubst fuel-syntax--at-end-of-def ()
(looking-at fuel-syntax--end-of-def-regex)) (looking-at fuel-syntax--end-of-def-regex))
(defsubst fuel-syntax--looking-at-emptiness () (defsubst fuel-syntax--looking-at-emptiness ()
(looking-at "^[ ]*$\\|$")) (looking-at "^[ ]*$\\|$"))
(defsubst fuel-syntax--is-last-char (pos) (defsubst fuel-syntax--is-last-char (pos)
(save-excursion (save-excursion
(goto-char (1+ pos)) (goto-char (1+ pos))
(looking-at-p "[ ]*$"))) (looking-at-p "[ ]*$")))
(defsubst fuel-syntax--line-offset (pos) (defsubst fuel-syntax--line-offset (pos)
(- pos (save-excursion (- pos (save-excursion
(goto-char pos) (goto-char pos)
(beginning-of-line) (beginning-of-line)
(point)))) (point))))
(defun fuel-syntax--previous-non-blank () (defun fuel-syntax--previous-non-blank ()
(forward-line -1) (forward-line -1)
(while (and (not (bobp)) (fuel-syntax--looking-at-emptiness)) (while (and (not (bobp)) (fuel-syntax--looking-at-emptiness))
(forward-line -1))) (forward-line -1)))
(defun fuel-syntax--beginning-of-block-pos () (defun fuel-syntax--beginning-of-block-pos ()
(save-excursion (save-excursion
(if (> (fuel-syntax--brackets-depth) 0) (if (> (fuel-syntax--brackets-depth) 0)
(fuel-syntax--brackets-start) (fuel-syntax--brackets-start)
(fuel-syntax--beginning-of-defun) (fuel-syntax--beginning-of-defun)
(point)))) (point))))
(defun fuel-syntax--at-setter-line () (defun fuel-syntax--at-setter-line ()
(save-excursion (save-excursion
(beginning-of-line) (beginning-of-line)
(when (re-search-forward fuel-syntax--setter-regex (when (re-search-forward fuel-syntax--setter-regex
(line-end-position) (line-end-position)
t) t)
(let* ((to (match-beginning 0)) (let* ((to (match-beginning 0))
(from (fuel-syntax--beginning-of-block-pos))) (from (fuel-syntax--beginning-of-block-pos)))
(goto-char from) (goto-char from)
(let ((depth (fuel-syntax--brackets-depth))) (let ((depth (fuel-syntax--brackets-depth)))
(and (or (re-search-forward fuel-syntax--constructor-regex to t) (and (or (re-search-forward fuel-syntax--constructor-regex to t)
(re-search-forward fuel-syntax--setter-regex to t)) (re-search-forward fuel-syntax--setter-regex to t))
(= depth (fuel-syntax--brackets-depth)))))))) (= depth (fuel-syntax--brackets-depth))))))))
(defun fuel-syntax--at-constructor-line () (defun fuel-syntax--at-constructor-line ()
(save-excursion (save-excursion
(beginning-of-line) (beginning-of-line)
(re-search-forward fuel-syntax--constructor-regex (line-end-position) t))) (re-search-forward fuel-syntax--constructor-regex (line-end-position) t)))
(defsubst fuel-syntax--at-using () (defsubst fuel-syntax--at-using ()
(looking-at fuel-syntax--using-lines-regex)) (looking-at fuel-syntax--using-lines-regex))
(defun fuel-syntax--in-using () (defun fuel-syntax--in-using ()
(let ((p (point))) (let ((p (point)))
(save-excursion (save-excursion
(and (re-search-backward "^USING: " nil t) (and (re-search-backward "^USING: " nil t)
(re-search-forward " ;" nil t) (re-search-forward " ;" nil t)
(< p (match-end 0)))))) (< p (match-end 0))))))
(defsubst fuel-syntax--beginning-of-defun (&optional times) (defsubst fuel-syntax--beginning-of-defun (&optional times)
(re-search-backward fuel-syntax--begin-of-def-regex nil t times)) (re-search-backward fuel-syntax--begin-of-def-regex nil t times))
(defsubst fuel-syntax--end-of-defun () (defsubst fuel-syntax--end-of-defun ()
(re-search-forward fuel-syntax--end-of-def-regex nil t)) (re-search-forward fuel-syntax--end-of-def-regex nil t))
(defsubst fuel-syntax--end-of-defun-pos () (defsubst fuel-syntax--end-of-defun-pos ()
(save-excursion (save-excursion
(re-search-forward fuel-syntax--end-of-def-regex nil t) (re-search-forward fuel-syntax--end-of-def-regex nil t)
(point))) (point)))
(defun fuel-syntax--beginning-of-body () (defun fuel-syntax--beginning-of-body ()
(let ((p (point))) (let ((p (point)))
(and (fuel-syntax--beginning-of-defun) (and (fuel-syntax--beginning-of-defun)
(re-search-forward fuel-syntax--defun-signature-regex p t) (re-search-forward fuel-syntax--defun-signature-regex p t)
(not (re-search-forward fuel-syntax--end-of-def-regex p t))))) (not (re-search-forward fuel-syntax--end-of-def-regex p t)))))
(defun fuel-syntax--beginning-of-sexp () (defun fuel-syntax--beginning-of-sexp ()
(if (> (fuel-syntax--brackets-depth) 0) (if (> (fuel-syntax--brackets-depth) 0)
(goto-char (fuel-syntax--brackets-start)) (goto-char (fuel-syntax--brackets-start))
(fuel-syntax--beginning-of-body))) (fuel-syntax--beginning-of-body)))
(defsubst fuel-syntax--beginning-of-sexp-pos () (defsubst fuel-syntax--beginning-of-sexp-pos ()
(save-excursion (fuel-syntax--beginning-of-sexp) (point))) (save-excursion (fuel-syntax--beginning-of-sexp) (point)))
;;; USING/IN: ;;; USING/IN:
(make-variable-buffer-local (make-variable-buffer-local
(defvar fuel-syntax--current-vocab-function 'fuel-syntax--find-in)) (defvar fuel-syntax--current-vocab-function 'fuel-syntax--find-in))
(defsubst fuel-syntax--current-vocab () (defsubst fuel-syntax--current-vocab ()
(funcall fuel-syntax--current-vocab-function)) (funcall fuel-syntax--current-vocab-function))
(defun fuel-syntax--find-in () (defun fuel-syntax--find-in ()
(save-excursion (save-excursion
(when (re-search-backward fuel-syntax--current-vocab-regex nil t) (when (re-search-backward fuel-syntax--current-vocab-regex nil t)
(match-string-no-properties 1)))) (match-string-no-properties 1))))
(make-variable-buffer-local (make-variable-buffer-local
(defvar fuel-syntax--usings-function 'fuel-syntax--find-usings)) (defvar fuel-syntax--usings-function 'fuel-syntax--find-usings))
(defsubst fuel-syntax--usings () (defsubst fuel-syntax--usings ()
(funcall fuel-syntax--usings-function)) (funcall fuel-syntax--usings-function))
(defun fuel-syntax--file-has-private () (defun fuel-syntax--file-has-private ()
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(and (re-search-forward "\\_<<PRIVATE\\_>" nil t) (and (re-search-forward "\\_<<PRIVATE\\_>" nil t)
(re-search-forward "\\_<PRIVATE>\\_>" nil t)))) (re-search-forward "\\_<PRIVATE>\\_>" nil t))))
(defun fuel-syntax--find-usings (&optional no-private) (defun fuel-syntax--find-usings (&optional no-private)
(save-excursion (save-excursion
(let ((usings)) (let ((usings))
(goto-char (point-max)) (goto-char (point-max))
(while (re-search-backward fuel-syntax--using-lines-regex nil t) (while (re-search-backward fuel-syntax--using-lines-regex nil t)
(dolist (u (split-string (match-string-no-properties 1) nil t)) (dolist (u (split-string (match-string-no-properties 1) nil t))
(push u usings))) (push u usings)))
(when (and (not no-private) (fuel-syntax--file-has-private)) (when (and (not no-private) (fuel-syntax--file-has-private))
(goto-char (point-max)) (goto-char (point-max))
(push (concat (fuel-syntax--find-in) ".private") usings)) (push (concat (fuel-syntax--find-in) ".private") usings))
usings))) usings)))
(provide 'fuel-syntax) (provide 'fuel-syntax)
;;; fuel-syntax.el ends here ;;; fuel-syntax.el ends here