[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode a22f053c2b 7/9: Add macro declaration
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode a22f053c2b 7/9: Add macro declaration |
Date: |
Sat, 30 Sep 2023 07:01:20 -0400 (EDT) |
branch: elpa/swift-mode
commit a22f053c2b707c84250a6ae275cab79da9d1b0fd
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>
Add macro declaration
---
swift-mode-beginning-of-defun.el | 5 +++--
swift-mode-font-lock.el | 20 ++++++++++----------
swift-mode-imenu.el | 10 +++++-----
swift-mode-indent.el | 2 +-
swift-mode-lexer.el | 14 ++++++++------
.../beginning-of-defun/beginning-of-defun.swift | 12 ++++++++++++
test/swift-files/imenu/imenu-expected.eld | 3 ++-
test/swift-files/imenu/imenu.swift | 2 ++
test/swift-files/indent/declarations.swift | 18 ++++++++++++++++++
test/swift-files/indent/identifiers.swift | 3 +++
10 files changed, 64 insertions(+), 25 deletions(-)
diff --git a/swift-mode-beginning-of-defun.el b/swift-mode-beginning-of-defun.el
index 7b99f075e2..f972ee7235 100644
--- a/swift-mode-beginning-of-defun.el
+++ b/swift-mode-beginning-of-defun.el
@@ -169,7 +169,8 @@ The cursor must be at the beginning of a statement."
(defun-keywords
'("import" "typealias" "associatedtype"
"enum" "struct" "actor" "protocol" "extension"
- "func" "init" "deinit" "subscript" "get" "set" "willSet" "didSet"
+ "func" "init" "deinit" "subscript" "macro"
+ "get" "set" "willSet" "didSet"
"prefix" "postfix" "infix" "precedencegroup"
"var" "let"
"case"))
@@ -1441,7 +1442,7 @@ of ancestors."
name-token
(cond
((member keyword-text
- '("typealias" "associatedtype" "precedencegroup" "func"
+ '("typealias" "associatedtype" "precedencegroup" "func"
"macro"
"class" "enum" "struct" "actor" "protocol" "extension"))
(swift-mode:forward-token))
diff --git a/swift-mode-font-lock.el b/swift-mode-font-lock.el
index e9a36b117e..9092327ca4 100644
--- a/swift-mode-font-lock.el
+++ b/swift-mode-font-lock.el
@@ -32,6 +32,7 @@
(require 'swift-mode-standard-types)
(require 'seq)
+(require 'subr-x)
;;; Customizations
@@ -194,7 +195,12 @@ This function does not search beyond LIMIT."
(and
(< (point) limit)
(looking-at
-
"\\<\\(func\\|enum\\|struct\\|class\\|protocol\\|extension\\|actor\\)\\>")))
+ (concat
+ "\\<\\("
+ (string-join
+ '("func" "enum" "struct" "class" "protocol" "extension" "actor" "macro")
+ "\\|")
+ "\\)\\>"))))
(defun swift-mode:property-access-pos-p (pos limit)
"Return t if POS is just before the property name of a member expression.
@@ -513,19 +519,12 @@ Return nil otherwise."
'("true" "false" "nil")
"Keywords used as constants.")
-(defconst swift-mode:preprocessor-keywords
- '("#available" "#colorLiteral" "#column" "#dsohandle" "#else" "#elseif"
- "#endif" "#error" "#file" "#filePath" "#fileLiteral" "#function" "#if"
- "#imageLiteral" "#keyPath" "#line" "#selector" "#sourceLocation"
- "#unavailable" "#warning")
- "Keywords that begin with a number sign (#).")
-
(defconst swift-mode:declaration-keywords
'("associatedtype" "class" "deinit" "enum" "extension" "fileprivate" "func"
"import" "init" "inout" "internal" "let" "open" "operator" "package"
"private" "protocol" "public" "any" "some" "static" "struct" "subscript"
"typealias" "var" "actor" "nonisolated" "isolated" "distributed"
- "borrowing" "consuming")
+ "borrowing" "consuming" "macro")
"Keywords used in declarations.")
(defconst swift-mode:statement-keywords
@@ -590,7 +589,8 @@ Excludes true, false, and keywords begin with a number
sign.")
.
'swift-mode:constant-keyword-face)
- (,(regexp-opt swift-mode:preprocessor-keywords 'symbols)
+ ;; Preprocessor keywords
+ (,"#\\(\\sw\\|\\s_\\)*"
.
'swift-mode:preprocessor-keyword-face)
diff --git a/swift-mode-imenu.el b/swift-mode-imenu.el
index 643f16bd87..ac7a2101e5 100644
--- a/swift-mode-imenu.el
+++ b/swift-mode-imenu.el
@@ -185,9 +185,9 @@ Return found declarations in reverse order."
(swift-mode:declaration (intern next-text) name-token nil)
declarations)))
- ((member next-text '("func" "init" "subscript"))
+ ((member next-text '("func" "init" "subscript" "macro"))
(setq last-class-token nil)
- (unless (equal next-text "func")
+ (unless (member next-text '("func" "macro"))
(goto-char (swift-mode:token:start next-token)))
(let ((declaration-type (intern next-text))
(names (swift-mode:scan-function-name-and-parameter-names)))
@@ -324,11 +324,11 @@ TYPE is one of `case', `let', or `var'."
items))
(defun swift-mode:scan-function-name-and-parameter-names ()
- "Parse function name and parameter names.
+ "Parse function/macro name and parameter names.
-The point is assumed to be before a function name.
+The point is assumed to be before a function/macro name.
-Return tokens of function names and parameter names.
+Return tokens of function/macro names and parameter names.
For example, given the following code, this return tokens \"foo\", \"a\",
and \"c\".
diff --git a/swift-mode-indent.el b/swift-mode-indent.el
index 1d286bc150..9df93bd40a 100644
--- a/swift-mode-indent.el
+++ b/swift-mode-indent.el
@@ -1644,7 +1644,7 @@ It is a Generic parameter list if:
\;
{ } \( \) \[ \]
"true" "false"
- "class" "struct" "actor" "enum" "extension" "func" "operator"
+ "class" "struct" "actor" "enum" "extension" "func" "operator" "macro"
"try" "try?" "try!"
"as" "as?" "as!"
"is"
diff --git a/swift-mode-lexer.el b/swift-mode-lexer.el
index 2bf04cb94b..080a9043bb 100644
--- a/swift-mode-lexer.el
+++ b/swift-mode-lexer.el
@@ -694,7 +694,8 @@ return non-nil."
;; Suppress implicit semicolon after declaration starters.
((member (swift-mode:token:text previous-token)
'("class" "struct" "actor" "protocol" "enum" "extension" "func"
- "typealias" "associatedtype" "precedencegroup" "operator"))
+ "typealias" "associatedtype" "precedencegroup" "operator"
+ "macro"))
nil)
;; Insert implicit semicolon before modifiers.
@@ -765,7 +766,7 @@ return non-nil."
;; `protocol' is handled by the next rule
((member (swift-mode:token:text next-token)
'("class" "struct" "actor" "enum" "extension" "func" "typealias"
- "associatedtype" "precedencegroup"))
+ "associatedtype" "precedencegroup" "macro"))
t)
;; Inserts implicit semicolon before protocol unless it is followed by <.
@@ -842,7 +843,7 @@ return non-nil."
(t t))))
(defun swift-mode:function-parameter-clause-p ()
- "Return t if the cursor is before a function parameter clause.
+ "Return t if the cursor is before a function/macro parameter clause.
Return nil otherwise."
(save-excursion
@@ -856,8 +857,8 @@ Return nil otherwise."
(progn (swift-mode:try-backward-generic-parameters) (point)))
(swift-mode:function-parameter-clause-p)))
((eq previous-type 'identifier)
- (equal (swift-mode:token:text (swift-mode:backward-token-simple))
- "func"))
+ (member (swift-mode:token:text (swift-mode:backward-token-simple))
+ '("func" "macro")))
(t nil)))))
(defun swift-mode:supertype-colon-p ()
@@ -948,7 +949,8 @@ Return nil otherwise."
(or (member (swift-mode:token:text (swift-mode:backward-token-simple))
'("init" "subscript"))
(member (swift-mode:token:text (swift-mode:backward-token-simple))
- '("typealias" "func" "enum" "struct" "actor" "class"
"init")))))
+ '("typealias" "func" "enum" "struct" "actor" "class" "init"
+ "macro")))))
(defun swift-mode:fix-operator-type (token)
"Return new operator token with proper token type.
diff --git a/test/swift-files/beginning-of-defun/beginning-of-defun.swift
b/test/swift-files/beginning-of-defun/beginning-of-defun.swift
index 01a5a327be..4ce4bd2630 100644
--- a/test/swift-files/beginning-of-defun/beginning-of-defun.swift
+++ b/test/swift-files/beginning-of-defun/beginning-of-defun.swift
@@ -299,6 +299,18 @@ public
}/*}*/
}/*}*/
+// /*[*/Macro declaratoins/*]*/
+/*{*/macro foo() = #bar/*}*/
+
+/*{*/@Foo
+macro
+ foo<T>()
+ =
+ #bar
+ where
+ T: A,
+ T == B/*}*/
+
// /*[*/Multiple declaratoins in single line/*]*/
/*{*/func foo(){};/*}*/ /*{*/func foo(){/*{*/func foo(){}/*}*/};/*}*//*{*/func
foo(){} ;/*}*/ /*{*/func foo() {} /* */ ;/*}*/ /*{*//* */ func foo() {}/*}*/
diff --git a/test/swift-files/imenu/imenu-expected.eld
b/test/swift-files/imenu/imenu-expected.eld
index 0da371b939..9aedce5fdc 100644
--- a/test/swift-files/imenu/imenu-expected.eld
+++ b/test/swift-files/imenu/imenu-expected.eld
@@ -1,4 +1,5 @@
-((precedencegroup (identifier "precedenceGroup" 2759 2774) nil)
+((macro (identifier "fooMacro(x:)" 2866 2874) nil)
+ (precedencegroup (identifier "precedenceGroup" 2759 2774) nil)
(operator (identifier "*****" 2719 2724) nil)
(operator (identifier "-----" 2679 2684) nil)
(operator (identifier "+++++" 2640 2645) nil)
diff --git a/test/swift-files/imenu/imenu.swift
b/test/swift-files/imenu/imenu.swift
index a9be705e15..b2faffee0d 100644
--- a/test/swift-files/imenu/imenu.swift
+++ b/test/swift-files/imenu/imenu.swift
@@ -124,3 +124,5 @@ precedencegroup precedenceGroup {
associativity: left
assignment: true
}
+
+macro fooMacro<T>(x: Foo) = #bar
diff --git a/test/swift-files/indent/declarations.swift
b/test/swift-files/indent/declarations.swift
index 461ba218f7..2c8a304e6b 100644
--- a/test/swift-files/indent/declarations.swift
+++ b/test/swift-files/indent/declarations.swift
@@ -870,3 +870,21 @@ func constrain<each S: Sequence>(
.Element
) == (Int, String) {
}
+
+
+// Macro declaration
+
+@Foo
+@freestanding(expression)
+macro
+ foo<T>(_: T)
+ ->
+ (T, String)
+ =
+ #externalMacro(
+ module: "A",
+ type: "B"
+ )
+ where
+ T: AAA,
+ T == Foo
diff --git a/test/swift-files/indent/identifiers.swift
b/test/swift-files/indent/identifiers.swift
index d36eeda560..5519c5c645 100644
--- a/test/swift-files/indent/identifiers.swift
+++ b/test/swift-files/indent/identifiers.swift
@@ -127,6 +127,9 @@ func foo() {
foo(
isolated: 1
)
+ foo(
+ macro: 1
+ )
// Keywords used in statements
foo(
- [nongnu] elpa/swift-mode updated (2b2e8581ba -> e58417ec87), ELPA Syncer, 2023/09/30
- [nongnu] elpa/swift-mode 6194d9578d 2/9: Add `borrowing` and `consuming` modifiers and `copy` operator, ELPA Syncer, 2023/09/30
- [nongnu] elpa/swift-mode 221863c4e2 1/9: Add `consume` operator, ELPA Syncer, 2023/09/30
- [nongnu] elpa/swift-mode 6b19157def 3/9: Add `package` modifier, ELPA Syncer, 2023/09/30
- [nongnu] elpa/swift-mode 1339e24d23 4/9: Add `discard self`, ELPA Syncer, 2023/09/30
- [nongnu] elpa/swift-mode 1178d72a37 5/9: Add init accessors, ELPA Syncer, 2023/09/30
- [nongnu] elpa/swift-mode ef36acf2c5 6/9: Add value and type parameter packs, ELPA Syncer, 2023/09/30
- [nongnu] elpa/swift-mode a22f053c2b 7/9: Add macro declaration,
ELPA Syncer <=
- [nongnu] elpa/swift-mode 73d20b686f 8/9: Open .swiftinterface files in Swift mode, ELPA Syncer, 2023/09/30
- [nongnu] elpa/swift-mode e58417ec87 9/9: Bump version to 9.1.0, ELPA Syncer, 2023/09/30