From c4d4d5fb7dfc076ff4c1b17fa70bce9474037d67 Mon Sep 17 00:00:00 2001 From: Mark Shachkov Date: Sun, 4 Dec 2022 09:17:35 +0300 Subject: [PATCH] Add CUDA syntax support (#2652) Reusing cpp syntax with minor additions. --- runtime/syntax/cuda.yaml | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 runtime/syntax/cuda.yaml diff --git a/runtime/syntax/cuda.yaml b/runtime/syntax/cuda.yaml new file mode 100644 index 00000000..6875b1ef --- /dev/null +++ b/runtime/syntax/cuda.yaml @@ -0,0 +1,68 @@ +filetype: cuda + +detect: + filename: "(\\.cu[h]?$)" + +rules: + - identifier: "\\b[A-Z_][0-9A-Z_]*\\b" + - type: "\\b(float|double|bool|char|int|short|long|enum|void|struct|union|typedef|(un)?signed|inline)\\b" + - type: "\\b(((s?size)|((u_?)?int(8|16|32|64|ptr))|char(8|16|32))_t|wchar_t)\\b" + - type: "\\b[a-z_][0-9a-z_]+(_t|_T)\\b" + - type: "\\b(final|override)\\b" + - type.keyword: "\\b(auto|volatile|const(expr|eval|init)?|mutable|register|thread_local|static|extern|decltype|explicit|virtual)\\b" + - statement: "\\b(class|namespace|template|typename|this|friend|using|public|protected|private|noexcept)\\b" + - statement: "\\b(concept|requires)\\b" + - statement: "\\b(import|export|module)\\b" + - statement: "\\b(for|if|while|do|else|case|default|switch)\\b" + - statement: "\\b(try|throw|catch|operator|new|delete|static_assert)\\b" + - statement: "\\b(goto|continue|break|return)\\b" + - preproc: "^[[:space:]]*#[[:space:]]*(define|pragma|include|(un|ifn?)def|endif|el(if|se)|if|warning|error)|_Pragma" + + # Conditionally-supported/extension keywords + - statement: "\\b(asm|fortran)\\b" + + # GCC builtins + - statement: "(__attribute__[[:space:]]*\\(\\([^)]*\\)\\)|__(aligned|asm|builtin|hidden|inline|packed|restrict|section|typeof|weak)__)" + + # CUDA specific keywords + - statement: "__(global|device|host|shared)__" + + # Operator Color + - symbol.operator: "[-+*/%=<>.:;,~&|^!?]|\\b(sizeof|alignof|typeid|(and|or|xor|not)(_eq)?|bitor|compl|bitand|(const|dynamic|reinterpret|static)_cast)\\b" + # Parenthetical Color + - symbol.brackets: "[(){}]|\\[|\\]" + # Integer Literals + - constant.number: "(\\b([1-9][0-9']*|0[0-7']*|0[Xx][0-9a-fA-F']+|0[Bb][01]+)([Uu]?[Ll][Ll]?|[Ll][Ll]?[Uu]?)?\\b)" + # Decimal Floating-point Literals + - constant.number: "(\\b(([0-9']*[.][0-9']+|[0-9']+[.][0-9']*)([Ee][+-]?[0-9']+)?|[0-9']+[Ee][+-]?[0-9']+)[FfLl]?\\b)" + # Hexadecimal Floating-point Literals + - constant.number: "(\\b0[Xx]([0-9a-zA-Z']*[.][0-9a-zA-Z']+|[0-9a-zA-Z']+[.][0-9a-zA-Z']*)[Pp][+-]?[0-9']+[FfLl]?\\b)" + - constant.bool: "(\\b(true|false|NULL|nullptr)\\b)" + + - constant.string: + start: "\"" + end: "\"" + skip: "\\\\." + rules: + - constant.specialChar: "\\\\([\"'abfnrtv\\\\]|[0-3]?[0-7]{1,2}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})" + + - constant.string: + start: "'" + end: "'" + skip: "\\\\." + rules: + - error: "..+" + - constant.specialChar: "\\\\([\"'abfnrtv\\\\]|[0-3]?[0-7]{1,2}|x[0-9A-Fa-f]{1,2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})" + + - comment: + start: "//" + end: "$" + rules: + - todo: "(TODO|XXX|FIXME):?" + + - comment: + start: "/\\*" + end: "\\*/" + rules: + - todo: "(TODO|XXX|FIXME):?" +