From 03a5cbc1369d5d4d98896002f3b04783a8b07e96 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Wed, 11 Oct 2023 09:36:05 -0700 Subject: [PATCH] feat: Add Arduino support (#202) --- .gitmodules | 6 ++ CHANGELOG.md | 1 + queries/arduino/highlights.scm | 111 +++++++++++++++++++++++++++++++++ repos/arduino | 1 + tree-sitter-langs-build.el | 3 +- tree-sitter-langs.el | 2 + 6 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 queries/arduino/highlights.scm create mode 160000 repos/arduino diff --git a/.gitmodules b/.gitmodules index b0f395be..1fc65101 100644 --- a/.gitmodules +++ b/.gitmodules @@ -466,3 +466,9 @@ branch = master update = none ignore = dirty +[submodule "repos/arduino"] + path = repos/arduino + url = https://github.com/ObserverOfTime/tree-sitter-arduino + branch = master + update = none + ignore = dirty diff --git a/CHANGELOG.md b/CHANGELOG.md index 1eff3f82..3688380a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +- Add `Arduino` support ## 0.12.65 - 2023-10-10 - Fix `HLSL` highlighting diff --git a/queries/arduino/highlights.scm b/queries/arduino/highlights.scm new file mode 100644 index 00000000..a4e74ae8 --- /dev/null +++ b/queries/arduino/highlights.scm @@ -0,0 +1,111 @@ +; inherits: cpp + +((identifier) @function.builtin + (#any-of? @function.builtin + ; Digital I/O + "digitalRead" + "digitalWrite" + "pinMode" + ; Analog I/O + "analogRead" + "analogReference" + "analogWrite" + ; Zero, Due & MKR Family + "analogReadResolution" + "analogWriteResolution" + ; Advanced I/O + "noTone" + "pulseIn" + "pulseInLong" + "shiftIn" + "shiftOut" + "tone" + ; Time + "delay" + "delayMicroseconds" + "micros" + "millis" + ; Math + "abs" + "constrain" + "map" + "max" + "min" + "pow" + "sq" + "sqrt" + ; Trigonometry + "cos" + "sin" + "tan" + ; Characters + "isAlpha" + "isAlphaNumeric" + "isAscii" + "isControl" + "isDigit" + "isGraph" + "isHexadecimalDigit" + "isLowerCase" + "isPrintable" + "isPunct" + "isSpace" + "isUpperCase" + "isWhitespace" + ; Random Numbers + "random" + "randomSeed" + ; Bits and Bytes + "bit" + "bitClear" + "bitRead" + "bitSet" + "bitWrite" + "highByte" + "lowByte" + ; External Interrupts + "attachInterrupt" + "detachInterrupt" + ; Interrupts + "interrupts" + "noInterrupts" + )) + +((identifier) @type.builtin + (#any-of? @type.builtin + "Serial" + "SPI" + "Stream" + "Wire" + "Keyboard" + "Mouse" + "String" + )) + +((identifier) @constant.builtin + (#any-of? @constant.builtin + "HIGH" + "LOW" + "INPUT" + "OUTPUT" + "INPUT_PULLUP" + "LED_BUILTIN" + )) + +(function_definition + (function_declarator + declarator: (identifier) @function.builtin) + (#any-of? @function.builtin "loop" "setup")) + +(call_expression + function: (primitive_type) @function.builtin) + +(call_expression + function: (identifier) @constructor + (#any-of? @constructor "SPISettings" "String")) + +(declaration + (type_identifier) @type.builtin + (function_declarator + declarator: (identifier) @constructor) + (#eq? @type.builtin "SPISettings")) diff --git a/repos/arduino b/repos/arduino new file mode 160000 index 00000000..db929fc6 --- /dev/null +++ b/repos/arduino @@ -0,0 +1 @@ +Subproject commit db929fc6822b9b9e1211678d508f187894ce0345 diff --git a/tree-sitter-langs-build.el b/tree-sitter-langs-build.el index f416e9fc..de094249 100644 --- a/tree-sitter-langs-build.el +++ b/tree-sitter-langs-build.el @@ -247,7 +247,8 @@ infrequent (grammar-only changes). It is different from the version of "List of suffixes for shared libraries that define tree-sitter languages.") (defconst tree-sitter-langs--langs-with-deps - '( cpp + '( arduino + cpp commonlisp hlsl glsl diff --git a/tree-sitter-langs.el b/tree-sitter-langs.el index 667de2ee..4ec9fcc7 100644 --- a/tree-sitter-langs.el +++ b/tree-sitter-langs.el @@ -101,6 +101,7 @@ See `tree-sitter-langs-repos'." '((ada-mode . ada) (agda-mode . agda) (agda2-mode . agda) + (arduino-mode . arduino) (fasm-mode . asm) (masm-mode . asm) (nasm-mode . asm) @@ -220,6 +221,7 @@ Return nil if there are no bundled patterns." ;; TODO: Make this less ad-hoc. (dolist (sym (cons lang-symbol (pcase lang-symbol + ('arduino '(cpp c)) ('cpp '(c)) ('hlsl '(cpp c)) ('typescript '(javascript))