Skip to content

Commit

Permalink
feat: Add Arduino support (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 authored Oct 11, 2023
1 parent 2084954 commit 03a5cbc
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 1 deletion.
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

0 comments on commit 03a5cbc

Please sign in to comment.