From d87629647614b779fb2aad8f0042fe2864253ea6 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 19 Nov 2023 04:10:52 -0500 Subject: feat: add Linkerscript (#5693) --- queries/linkerscript/folds.scm | 6 ++ queries/linkerscript/highlights.scm | 146 ++++++++++++++++++++++++++++++++++++ queries/linkerscript/indents.scm | 11 +++ queries/linkerscript/injections.scm | 2 + queries/linkerscript/locals.scm | 15 ++++ 5 files changed, 180 insertions(+) create mode 100644 queries/linkerscript/folds.scm create mode 100644 queries/linkerscript/highlights.scm create mode 100644 queries/linkerscript/indents.scm create mode 100644 queries/linkerscript/injections.scm create mode 100644 queries/linkerscript/locals.scm (limited to 'queries/linkerscript') diff --git a/queries/linkerscript/folds.scm b/queries/linkerscript/folds.scm new file mode 100644 index 000000000..0fc77b1a7 --- /dev/null +++ b/queries/linkerscript/folds.scm @@ -0,0 +1,6 @@ +[ + (sections_command) + (output_section) + (memory_command) + (phdrs_command) +] @fold diff --git a/queries/linkerscript/highlights.scm b/queries/linkerscript/highlights.scm new file mode 100644 index 000000000..f933f31ca --- /dev/null +++ b/queries/linkerscript/highlights.scm @@ -0,0 +1,146 @@ +; Keywords + +[ + "ENTRY" + "SECTIONS" + "AT" + "OVERLAY" + "NOCROSSREFS" + "MEMORY" + "PHDRS" + "FILEHDR" +] @keyword + +; Conditionals + +(conditional_expression [ "?" ":" ] @conditional.ternary) + +; Variables + +(symbol) @variable + +(filename) @string.special @text.underline + +; Functions + +(call_expression + function: (symbol) @function.call) + +((call_expression + function: (symbol) @preproc) + (#eq? @preproc "DEFINED")) + +((call_expression + function: (symbol) @function.builtin) + (#any-of? @function.builtin + "ABSOLUTE" "ALIAS" "ADDR" "ALIGN" "ALIGNOF" "BASE" "BLOCK" "CHIP" "DATA_SEGMENT_ALIGN" + "DATA_SEGMENT_END" "DATA_SEGMENT_RELRO_END" "END" "LENGTH" "LOADADDR" "LOG2CEIL" "MAX" "MIN" + "NEXT" "ORIGIN" "SEGMENT_START" "SIZEOF" "BYTE" "FILL" "LONG" "SHORT" "QUAD" "SQUAD" "WORD")) + +[ + "KEEP" + "PROVIDE" + "PROVIDE_HIDDEN" +] @function.builtin + +; Types + +(section_type "(" [ "NOLOAD" "DSECT" "COPY" "INFO" "OVERLAY" ] @type.builtin ")") + +; Fields + +[ + "ORIGIN" "org" "o" + "LENGTH" "len" "l" +] @field.builtin + +; Constants + +((symbol) @constant + (#lua-match? @constant "^[%u_][%u%d_]+$")) + +; Labels + +(entry_command name: (symbol) @label) + +(output_section name: (symbol) @label) + +(memory_command name: (symbol) @label) + +(phdrs_command name: (symbol) @label) + +(region ">" (symbol) @label) + +(lma_region ">" (symbol) @label) + +(phdr ":" (symbol) @label) + +([(symbol) (filename)] @label + (#lua-match? @label "^%.")) + +; Exceptions + +"ASSERT" @exception + +[ + "/DISCARD/" + "." +] @variable.builtin + +; Operators + +[ + "+" + "-" + "*" + "/" + "%" + "||" + "&&" + "|" + "&" + "==" + "!=" + ">" + ">=" + "<=" + "<" + "<<" + ">>" + "!" + "~" + "=" + "+=" + "-=" + "*=" + "/=" + "<<=" + ">>=" + "&=" + "|=" +] @operator + +; Literals + +(number) @number + +(quoted_symbol) @string + +(wildcard_pattern [ "*" "[" "]" ] @character.special) + +(attributes) @character.special + +; Punctuation + +[ "{" "}" "(" ")" ] @punctuation.bracket + +[ + ":" + ";" +] @punctuation.delimiter + +">" @punctuation.special + +; Comments + +(comment) @comment @spell diff --git a/queries/linkerscript/indents.scm b/queries/linkerscript/indents.scm new file mode 100644 index 000000000..a636ba109 --- /dev/null +++ b/queries/linkerscript/indents.scm @@ -0,0 +1,11 @@ +[ + (sections_command) + (output_section) + (memory_command) + (phdrs_command) +] @indent.begin + +[ + "}" + ")" +] @indent.branch @indent.end diff --git a/queries/linkerscript/injections.scm b/queries/linkerscript/injections.scm new file mode 100644 index 000000000..51e6d1f6b --- /dev/null +++ b/queries/linkerscript/injections.scm @@ -0,0 +1,2 @@ +((comment) + (#set! injection.language "comment")) diff --git a/queries/linkerscript/locals.scm b/queries/linkerscript/locals.scm new file mode 100644 index 000000000..93ddb4357 --- /dev/null +++ b/queries/linkerscript/locals.scm @@ -0,0 +1,15 @@ +; References + +[ + (symbol) + (filename) + (quoted_symbol) +] @reference + +; Definitions + +(output_section name: (symbol) @definition.var) + +(memory_command name: (symbol) @definition.var) + +(phdrs_command name: (symbol) @definition.var) -- cgit v1.2.3-70-g09d2