Skip to content

feat: Add Arduino support #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
- Add `Arduino` support

## 0.12.65 - 2023-10-10
- Fix `HLSL` highlighting
Expand Down
111 changes: 111 additions & 0 deletions queries/arduino/highlights.scm
Original file line number Diff line number Diff line change
@@ -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"))
1 change: 1 addition & 0 deletions repos/arduino
Submodule arduino added at db929f
3 changes: 2 additions & 1 deletion tree-sitter-langs-build.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tree-sitter-langs.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down