2008-12-05 22:34:25 -05:00
|
|
|
|
;;; fuel-syntax.el --- auxiliar definitions for factor code navigation.
|
|
|
|
|
|
2009-01-05 17:29:26 -05:00
|
|
|
|
;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz
|
2008-12-05 22:34:25 -05:00
|
|
|
|
;; See http://factorcode.org/license.txt for BSD license.
|
|
|
|
|
|
|
|
|
|
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
|
|
|
|
|
;; Keywords: languages
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; Auxiliar constants and functions to parse factor code.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(require 'thingatpt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Thing-at-point support for factor symbols:
|
|
|
|
|
|
|
|
|
|
(defun fuel-syntax--beginning-of-symbol ()
|
|
|
|
|
"Move point to the beginning of the current symbol."
|
2008-12-19 16:35:34 -05:00
|
|
|
|
(skip-syntax-backward "w_()"))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
2008-12-20 10:51:05 -05:00
|
|
|
|
(defsubst fuel-syntax--beginning-of-symbol-pos ()
|
2008-12-15 17:44:13 -05:00
|
|
|
|
(save-excursion (fuel-syntax--beginning-of-symbol) (point)))
|
|
|
|
|
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(defun fuel-syntax--end-of-symbol ()
|
|
|
|
|
"Move point to the end of the current symbol."
|
2008-12-19 16:35:34 -05:00
|
|
|
|
(skip-syntax-forward "w_()"))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
2008-12-20 10:51:05 -05:00
|
|
|
|
(defsubst fuel-syntax--end-of-symbol-pos ()
|
2008-12-15 17:44:13 -05:00
|
|
|
|
(save-excursion (fuel-syntax--end-of-symbol) (point)))
|
|
|
|
|
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(put 'factor-symbol 'end-op 'fuel-syntax--end-of-symbol)
|
|
|
|
|
(put 'factor-symbol 'beginning-op 'fuel-syntax--beginning-of-symbol)
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax-symbol-at-point ()
|
|
|
|
|
(let ((s (substring-no-properties (thing-at-point 'factor-symbol))))
|
|
|
|
|
(and (> (length s) 0) s)))
|
|
|
|
|
|
2008-12-15 17:44:13 -05:00
|
|
|
|
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
;;; Regexps galore:
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--parsing-words
|
2008-12-22 08:06:50 -05:00
|
|
|
|
'(":" "::" ";" "<<" "<PRIVATE" ">>"
|
2009-01-11 14:37:06 -05:00
|
|
|
|
"ABOUT:" "ALIAS:" "ARTICLE:"
|
2009-01-09 18:55:39 -05:00
|
|
|
|
"B" "BIN:"
|
|
|
|
|
"C:" "C-STRUCT:" "C-UNION:" "CHAR:" "CONSTANT:" "call-next-method"
|
|
|
|
|
"DEFER:"
|
|
|
|
|
"ERROR:" "EXCLUDE:"
|
|
|
|
|
"f" "FORGET:" "FROM:"
|
|
|
|
|
"GENERIC#" "GENERIC:"
|
2009-01-11 14:37:06 -05:00
|
|
|
|
"HELP:" "HEX:" "HOOK:"
|
2009-01-09 18:55:39 -05:00
|
|
|
|
"IN:" "initial:" "INSTANCE:" "INTERSECTION:"
|
2009-01-05 17:29:26 -05:00
|
|
|
|
"M:" "MACRO:" "MACRO::" "MAIN:" "MATH:" "MEMO:" "MEMO:" "METHOD:" "MIXIN:"
|
2009-01-09 18:55:39 -05:00
|
|
|
|
"OCT:"
|
|
|
|
|
"POSTPONE:" "PREDICATE:" "PRIMITIVE:" "PRIVATE>" "PROVIDE:"
|
|
|
|
|
"QUALIFIED-WITH:" "QUALIFIED:"
|
|
|
|
|
"read-only" "RENAME:" "REQUIRE:" "REQUIRES:"
|
|
|
|
|
"SINGLETON:" "SINGLETONS:" "SLOT:" "SYMBOL:" "SYMBOLS:"
|
2008-12-22 08:06:50 -05:00
|
|
|
|
"TUPLE:" "t" "t?" "TYPEDEF:"
|
2009-01-09 18:55:39 -05:00
|
|
|
|
"UNION:" "USE:" "USING:"
|
|
|
|
|
"VARS:"))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
2008-12-22 08:06:50 -05:00
|
|
|
|
(defconst fuel-syntax--parsing-words-regex
|
|
|
|
|
(regexp-opt fuel-syntax--parsing-words 'words))
|
|
|
|
|
|
2009-01-11 08:29:55 -05:00
|
|
|
|
(defconst fuel-syntax--bracers
|
|
|
|
|
'("B" "BV" "C" "CS" "H" "T" "V" "W"))
|
|
|
|
|
|
2008-12-22 08:06:50 -05:00
|
|
|
|
(defconst fuel-syntax--brace-words-regex
|
|
|
|
|
(format "%s{" (regexp-opt fuel-syntax--bracers t)))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--declaration-words
|
2009-01-09 18:55:39 -05:00
|
|
|
|
'("flushable" "foldable" "inline" "parsing" "recursive" "delimiter"))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--declaration-words-regex
|
2008-12-22 00:58:20 -05:00
|
|
|
|
(regexp-opt fuel-syntax--declaration-words 'words))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--second-word-regex (prefixes)
|
2009-01-15 19:14:56 -05:00
|
|
|
|
(format "%s +\\([^ \r\n]+\\)" (regexp-opt prefixes t)))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--method-definition-regex
|
|
|
|
|
"^M: +\\([^ ]+\\) +\\([^ ]+\\)")
|
|
|
|
|
|
2009-01-10 00:40:01 -05:00
|
|
|
|
(defconst fuel-syntax--integer-regex
|
|
|
|
|
"\\_<-?[0-9]+\\_>")
|
|
|
|
|
|
2009-01-13 20:25:31 -05:00
|
|
|
|
(defconst fuel-syntax--raw-float-regex
|
|
|
|
|
"[0-9]*\\.[0-9]*\\([eE][+-]?[0-9]+\\)?")
|
2009-01-10 00:40:01 -05:00
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--float-regex
|
2009-01-13 20:25:31 -05:00
|
|
|
|
(format "\\_<-?%s\\_>" fuel-syntax--raw-float-regex))
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--number-regex
|
|
|
|
|
(format "\\([0-9]+\\|%s\\)" fuel-syntax--raw-float-regex))
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--ratio-regex
|
|
|
|
|
(format "\\_<[+-]?%s/-?%s\\_>"
|
|
|
|
|
fuel-syntax--number-regex
|
|
|
|
|
fuel-syntax--number-regex))
|
2009-01-09 18:55:39 -05:00
|
|
|
|
|
2009-01-12 19:44:22 -05:00
|
|
|
|
(defconst fuel-syntax--bad-string-regex
|
2009-01-14 17:28:19 -05:00
|
|
|
|
"\\_<\"[^>]\\([^\"\n]\\|\\\\\"\\)*\n")
|
2009-01-12 19:44:22 -05:00
|
|
|
|
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(defconst fuel-syntax--word-definition-regex
|
2009-01-09 18:55:39 -05:00
|
|
|
|
(fuel-syntax--second-word-regex
|
|
|
|
|
'(":" "::" "GENERIC:" "DEFER:" "HOOK:" "MAIN:" "MATH:" "POSTPONE:"
|
|
|
|
|
"SYMBOL:" "RENAME:")))
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--alias-definition-regex
|
|
|
|
|
"^ALIAS: +\\(\\_<.+?\\_>\\) +\\(\\_<.+?\\_>\\)")
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--vocab-ref-regexp
|
|
|
|
|
(fuel-syntax--second-word-regex
|
|
|
|
|
'("IN:" "USE:" "FROM:" "EXCLUDE:" "QUALIFIED:" "QUALIFIED-WITH:")))
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--int-constant-def-regex
|
|
|
|
|
(fuel-syntax--second-word-regex '("CHAR:" "BIN:" "HEX:" "OCT:")))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--type-definition-regex
|
2009-01-09 18:55:39 -05:00
|
|
|
|
(fuel-syntax--second-word-regex '("MIXIN:" "TUPLE:" "SINGLETON:" "UNION:")))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
2009-01-14 15:51:01 -05:00
|
|
|
|
(defconst fuel-syntax--tuple-decl-regex
|
2009-01-14 18:05:52 -05:00
|
|
|
|
"^TUPLE: +\\([^ \n]+\\) +< +\\([^ \n]+\\)\\_>")
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--constructor-regex "<[^ >]+>")
|
|
|
|
|
|
2008-12-22 00:58:20 -05:00
|
|
|
|
(defconst fuel-syntax--getter-regex "\\(^\\|\\_<\\)[^ ]+?>>\\_>")
|
|
|
|
|
(defconst fuel-syntax--setter-regex "\\_<>>.+?\\_>")
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--symbol-definition-regex
|
|
|
|
|
(fuel-syntax--second-word-regex '("SYMBOL:" "VAR:")))
|
|
|
|
|
|
2009-01-14 15:51:01 -05:00
|
|
|
|
(defconst fuel-syntax--stack-effect-regex
|
|
|
|
|
"\\( ( .* )\\)\\|\\( (( .* ))\\)")
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--using-lines-regex "^USING: +\\([^;]+\\);")
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--use-line-regex "^USE: +\\(.*\\)$")
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--current-vocab-regex "^IN: +\\([^ \r\n\f]+\\)")
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--sub-vocab-regex "^<\\([^ \n]+\\) *$")
|
|
|
|
|
|
2009-01-12 06:13:21 -05:00
|
|
|
|
(defconst fuel-syntax--indent-def-starts '("" ":"
|
|
|
|
|
"FROM"
|
|
|
|
|
"INTERSECTION:"
|
|
|
|
|
"M" "MACRO" "MACRO:"
|
|
|
|
|
"MEMO" "MEMO:" "METHOD"
|
|
|
|
|
"PREDICATE" "PRIMITIVE"
|
|
|
|
|
"UNION"))
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--no-indent-def-starts '("SINGLETONS"
|
|
|
|
|
"SYMBOLS"
|
|
|
|
|
"TUPLE"
|
|
|
|
|
"VARS"))
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--indent-def-start-regex
|
|
|
|
|
(format "^\\(%s:\\) " (regexp-opt fuel-syntax--indent-def-starts)))
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--no-indent-def-start-regex
|
|
|
|
|
(format "^\\(%s:\\) " (regexp-opt fuel-syntax--no-indent-def-starts)))
|
|
|
|
|
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(defconst fuel-syntax--definition-start-regex
|
2009-01-12 06:13:21 -05:00
|
|
|
|
(format "^\\(%s:\\) " (regexp-opt (append fuel-syntax--no-indent-def-starts
|
|
|
|
|
fuel-syntax--indent-def-starts))))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--definition-end-regex
|
2008-12-22 00:58:20 -05:00
|
|
|
|
(format "\\(\\(^\\| +\\);\\( *%s\\)*\\($\\| +\\)\\)"
|
2008-12-05 22:34:25 -05:00
|
|
|
|
fuel-syntax--declaration-words-regex))
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--single-liner-regex
|
2009-01-15 19:14:56 -05:00
|
|
|
|
(regexp-opt '("ABOUT:"
|
|
|
|
|
"ARTICLE:"
|
|
|
|
|
"ALIAS:"
|
|
|
|
|
"CONSTANT:" "C:"
|
|
|
|
|
"DEFER:"
|
|
|
|
|
"FORGET:"
|
|
|
|
|
"GENERIC:" "GENERIC#"
|
|
|
|
|
"HELP:" "HEX:" "HOOK:"
|
|
|
|
|
"IN:" "INSTANCE:"
|
|
|
|
|
"MAIN:" "MATH:" "MIXIN:"
|
|
|
|
|
"OCT:"
|
|
|
|
|
"POSTPONE:" "PRIVATE>" "<PRIVATE"
|
|
|
|
|
"QUALIFIED-WITH:" "QUALIFIED:"
|
|
|
|
|
"RENAME:"
|
|
|
|
|
"SINGLETON:" "SLOT:" "SYMBOL:"
|
|
|
|
|
"USE:"
|
|
|
|
|
"VAR:")))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--begin-of-def-regex
|
2009-01-15 19:14:56 -05:00
|
|
|
|
(format "^USING: \\|\\(%s\\)\\|\\(^%s .*\\)"
|
2008-12-05 22:34:25 -05:00
|
|
|
|
fuel-syntax--definition-start-regex
|
|
|
|
|
fuel-syntax--single-liner-regex))
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--end-of-def-line-regex
|
|
|
|
|
(format "^.*%s" fuel-syntax--definition-end-regex))
|
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--end-of-def-regex
|
2009-01-15 19:14:56 -05:00
|
|
|
|
(format "\\(%s\\)\\|\\(^%s .*\\)"
|
2008-12-05 22:34:25 -05:00
|
|
|
|
fuel-syntax--end-of-def-line-regex
|
|
|
|
|
fuel-syntax--single-liner-regex))
|
2008-12-22 01:29:48 -05:00
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--defun-signature-regex
|
|
|
|
|
(format "\\(%s\\|%s\\)"
|
|
|
|
|
(format ":[^ ]* [^ ]+\\(%s\\)*" fuel-syntax--stack-effect-regex)
|
|
|
|
|
"M[^:]*: [^ ]+ [^ ]+"))
|
|
|
|
|
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
;;; Factor syntax table
|
|
|
|
|
|
2008-12-22 08:06:50 -05:00
|
|
|
|
(setq fuel-syntax--syntax-table
|
2008-12-22 00:58:20 -05:00
|
|
|
|
(let ((table (make-syntax-table)))
|
|
|
|
|
;; Default is word constituent
|
|
|
|
|
(dotimes (i 256)
|
|
|
|
|
(modify-syntax-entry i "w" table))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
2008-12-22 08:06:50 -05:00
|
|
|
|
;; Whitespace (TAB is not whitespace)
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(modify-syntax-entry ?\f " " table)
|
|
|
|
|
(modify-syntax-entry ?\r " " table)
|
2008-12-22 00:58:20 -05:00
|
|
|
|
(modify-syntax-entry ?\ " " table)
|
|
|
|
|
(modify-syntax-entry ?\n " " table)
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
2009-01-12 19:44:22 -05:00
|
|
|
|
;; Char quote
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(modify-syntax-entry ?\\ "/" table)
|
2008-12-22 08:06:50 -05:00
|
|
|
|
|
2008-12-22 00:58:20 -05:00
|
|
|
|
table))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defconst fuel-syntax--syntactic-keywords
|
2009-01-14 16:53:58 -05:00
|
|
|
|
`(;; CHARs:
|
|
|
|
|
("CHAR: \\(.\\)\\( \\|$\\)" (1 "w"))
|
|
|
|
|
;; Comments:
|
2008-12-27 11:36:12 -05:00
|
|
|
|
("\\_<\\(#?!\\) .*\\(\n\\|$\\)" (1 "<") (2 ">"))
|
2008-12-27 09:44:15 -05:00
|
|
|
|
("\\_<\\(#?!\\)\\(\n\\|$\\)" (1 "<") (2 ">"))
|
2009-01-12 19:44:22 -05:00
|
|
|
|
;; Strings
|
2009-01-15 08:00:39 -05:00
|
|
|
|
("\\_<\\(\"\\)\\([^\n\r\f\\\"]\\|\\\\\"\\)*\\(\"\\)\\_>" (1 "\"") (3 "\""))
|
2009-01-14 17:28:19 -05:00
|
|
|
|
("\\_<<\\(\"\\)\\_>" (1 "\""))
|
|
|
|
|
("\\_<\\(\"\\)>\\_>" (1 "\""))
|
2009-01-15 08:00:39 -05:00
|
|
|
|
;; Multiline constructs
|
|
|
|
|
("\\_<USING:\\( \\)" (1 "<b"))
|
|
|
|
|
("\\_<TUPLE: +\\w+? +< +\\w+? *\\( \\)" (1 "<b"))
|
|
|
|
|
("\\_<\\(TUPLE\\|SYMBOLS\\|VARS\\): +\\w+? *\\( \\)\\([^<]\\|\\_>\\)" (2 "<b"))
|
|
|
|
|
("\\(\n\\| \\);\\_>" (1 ">b"))
|
2008-12-27 11:36:12 -05:00
|
|
|
|
;; Let and lambda:
|
2008-12-22 18:34:43 -05:00
|
|
|
|
("\\_<\\(!(\\) .* \\()\\)" (1 "<") (2 ">"))
|
2008-12-19 08:54:18 -05:00
|
|
|
|
("\\(\\[\\)\\(let\\|wlet\\|let\\*\\)\\( \\|$\\)" (1 "(]"))
|
|
|
|
|
("\\(\\[\\)\\(|\\) +[^|]* \\(|\\)" (1 "(]") (2 "(|") (3 ")|"))
|
|
|
|
|
(" \\(|\\) " (1 "(|"))
|
|
|
|
|
(" \\(|\\)$" (1 ")"))
|
2008-12-27 11:36:12 -05:00
|
|
|
|
;; Opening brace words:
|
2009-01-11 08:29:55 -05:00
|
|
|
|
("\\_<\\w*\\({\\)\\_>" (1 "(}"))
|
2008-12-22 08:06:50 -05:00
|
|
|
|
("\\_<\\(}\\)\\_>" (1 "){"))
|
2008-12-27 11:36:12 -05:00
|
|
|
|
;; Parenthesis:
|
2008-12-22 08:06:50 -05:00
|
|
|
|
("\\_<\\((\\)\\_>" (1 "()"))
|
|
|
|
|
("\\_<\\()\\)\\_>" (1 ")("))
|
2008-12-27 11:36:12 -05:00
|
|
|
|
;; Quotations:
|
|
|
|
|
("\\_<'\\(\\[\\)\\_>" (1 "(]")) ; fried
|
2008-12-22 08:06:50 -05:00
|
|
|
|
("\\_<\\(\\[\\)\\_>" (1 "(]"))
|
|
|
|
|
("\\_<\\(\\]\\)\\_>" (1 ")["))))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Source code analysis:
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--brackets-depth ()
|
|
|
|
|
(nth 0 (syntax-ppss)))
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--brackets-start ()
|
|
|
|
|
(nth 1 (syntax-ppss)))
|
|
|
|
|
|
|
|
|
|
(defun fuel-syntax--brackets-end ()
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (fuel-syntax--brackets-start))
|
|
|
|
|
(condition-case nil
|
|
|
|
|
(progn (forward-sexp)
|
|
|
|
|
(1- (point)))
|
|
|
|
|
(error -1))))
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--indentation-at (pos)
|
|
|
|
|
(save-excursion (goto-char pos) (current-indentation)))
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--increased-indentation (&optional i)
|
|
|
|
|
(+ (or i (current-indentation)) factor-indent-width))
|
|
|
|
|
(defsubst fuel-syntax--decreased-indentation (&optional i)
|
|
|
|
|
(- (or i (current-indentation)) factor-indent-width))
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--at-begin-of-def ()
|
|
|
|
|
(looking-at fuel-syntax--begin-of-def-regex))
|
|
|
|
|
|
2009-01-12 06:13:21 -05:00
|
|
|
|
(defsubst fuel-syntax--at-begin-of-indent-def ()
|
|
|
|
|
(looking-at fuel-syntax--indent-def-start-regex))
|
|
|
|
|
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(defsubst fuel-syntax--at-end-of-def ()
|
|
|
|
|
(looking-at fuel-syntax--end-of-def-regex))
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--looking-at-emptiness ()
|
2008-12-19 08:54:18 -05:00
|
|
|
|
(looking-at "^[ ]*$\\|$"))
|
|
|
|
|
|
2009-01-11 12:01:52 -05:00
|
|
|
|
(defsubst fuel-syntax--is-last-char (pos)
|
2008-12-19 08:54:18 -05:00
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (1+ pos))
|
|
|
|
|
(fuel-syntax--looking-at-emptiness)))
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--line-offset (pos)
|
|
|
|
|
(- pos (save-excursion
|
|
|
|
|
(goto-char pos)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(point))))
|
|
|
|
|
|
|
|
|
|
(defun fuel-syntax--previous-non-blank ()
|
|
|
|
|
(forward-line -1)
|
|
|
|
|
(while (and (not (bobp)) (fuel-syntax--looking-at-emptiness))
|
|
|
|
|
(forward-line -1)))
|
|
|
|
|
|
2008-12-20 10:51:05 -05:00
|
|
|
|
(defun fuel-syntax--beginning-of-block-pos ()
|
2008-12-19 08:54:18 -05:00
|
|
|
|
(save-excursion
|
2008-12-19 16:35:34 -05:00
|
|
|
|
(if (> (fuel-syntax--brackets-depth) 0)
|
|
|
|
|
(fuel-syntax--brackets-start)
|
|
|
|
|
(fuel-syntax--beginning-of-defun)
|
|
|
|
|
(point))))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defun fuel-syntax--at-setter-line ()
|
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
2008-12-19 08:54:18 -05:00
|
|
|
|
(when (re-search-forward fuel-syntax--setter-regex
|
|
|
|
|
(line-end-position)
|
|
|
|
|
t)
|
|
|
|
|
(let* ((to (match-beginning 0))
|
2008-12-20 10:51:05 -05:00
|
|
|
|
(from (fuel-syntax--beginning-of-block-pos)))
|
2008-12-19 08:54:18 -05:00
|
|
|
|
(goto-char from)
|
|
|
|
|
(let ((depth (fuel-syntax--brackets-depth)))
|
|
|
|
|
(and (or (re-search-forward fuel-syntax--constructor-regex to t)
|
|
|
|
|
(re-search-forward fuel-syntax--setter-regex to t))
|
|
|
|
|
(= depth (fuel-syntax--brackets-depth))))))))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(defun fuel-syntax--at-constructor-line ()
|
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(re-search-forward fuel-syntax--constructor-regex (line-end-position) t)))
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--at-using ()
|
|
|
|
|
(looking-at fuel-syntax--using-lines-regex))
|
|
|
|
|
|
2008-12-17 18:49:01 -05:00
|
|
|
|
(defun fuel-syntax--in-using ()
|
|
|
|
|
(let ((p (point)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(and (re-search-backward "^USING: " nil t)
|
|
|
|
|
(re-search-forward " ;" nil t)
|
|
|
|
|
(< p (match-end 0))))))
|
|
|
|
|
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(defsubst fuel-syntax--beginning-of-defun (&optional times)
|
|
|
|
|
(re-search-backward fuel-syntax--begin-of-def-regex nil t times))
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--end-of-defun ()
|
|
|
|
|
(re-search-forward fuel-syntax--end-of-def-regex nil t))
|
|
|
|
|
|
2008-12-21 12:39:59 -05:00
|
|
|
|
(defsubst fuel-syntax--end-of-defun-pos ()
|
|
|
|
|
(save-excursion
|
|
|
|
|
(re-search-forward fuel-syntax--end-of-def-regex nil t)
|
|
|
|
|
(point)))
|
|
|
|
|
|
2008-12-20 10:51:05 -05:00
|
|
|
|
(defun fuel-syntax--beginning-of-body ()
|
|
|
|
|
(let ((p (point)))
|
|
|
|
|
(and (fuel-syntax--beginning-of-defun)
|
|
|
|
|
(re-search-forward fuel-syntax--defun-signature-regex p t)
|
|
|
|
|
(not (re-search-forward fuel-syntax--end-of-def-regex p t)))))
|
|
|
|
|
|
|
|
|
|
(defun fuel-syntax--beginning-of-sexp ()
|
|
|
|
|
(if (> (fuel-syntax--brackets-depth) 0)
|
|
|
|
|
(goto-char (fuel-syntax--brackets-start))
|
|
|
|
|
(fuel-syntax--beginning-of-body)))
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--beginning-of-sexp-pos ()
|
|
|
|
|
(save-excursion (fuel-syntax--beginning-of-sexp) (point)))
|
|
|
|
|
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
;;; USING/IN:
|
|
|
|
|
|
2008-12-15 20:09:18 -05:00
|
|
|
|
(make-variable-buffer-local
|
|
|
|
|
(defvar fuel-syntax--current-vocab-function 'fuel-syntax--find-in))
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--current-vocab ()
|
|
|
|
|
(funcall fuel-syntax--current-vocab-function))
|
|
|
|
|
|
|
|
|
|
(defun fuel-syntax--find-in ()
|
2008-12-30 19:31:03 -05:00
|
|
|
|
(save-excursion
|
|
|
|
|
(when (re-search-backward fuel-syntax--current-vocab-regex nil t)
|
|
|
|
|
(match-string-no-properties 1))))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
2008-12-15 20:09:18 -05:00
|
|
|
|
(make-variable-buffer-local
|
|
|
|
|
(defvar fuel-syntax--usings-function 'fuel-syntax--find-usings))
|
|
|
|
|
|
|
|
|
|
(defsubst fuel-syntax--usings ()
|
|
|
|
|
(funcall fuel-syntax--usings-function))
|
|
|
|
|
|
2009-01-08 12:47:17 -05:00
|
|
|
|
(defun fuel-syntax--file-has-private ()
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(and (re-search-forward "\\_<<PRIVATE\\_>" nil t)
|
|
|
|
|
(re-search-forward "\\_<PRIVATE>\\_>" nil t))))
|
|
|
|
|
|
2008-12-30 19:31:03 -05:00
|
|
|
|
(defun fuel-syntax--find-usings (&optional no-private)
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(save-excursion
|
2008-12-23 20:44:49 -05:00
|
|
|
|
(let ((usings))
|
2008-12-15 17:44:13 -05:00
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(while (re-search-backward fuel-syntax--using-lines-regex nil t)
|
|
|
|
|
(dolist (u (split-string (match-string-no-properties 1) nil t))
|
|
|
|
|
(push u usings)))
|
2009-01-08 12:47:17 -05:00
|
|
|
|
(when (and (not no-private) (fuel-syntax--file-has-private))
|
2008-12-30 19:31:03 -05:00
|
|
|
|
(goto-char (point-max))
|
|
|
|
|
(push (concat (fuel-syntax--find-in) ".private") usings))
|
2008-12-15 17:44:13 -05:00
|
|
|
|
usings)))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'fuel-syntax)
|
|
|
|
|
;;; fuel-syntax.el ends here
|