diff --git a/grammar.js b/grammar.js index 40d701976..7bebd2fe8 100644 --- a/grammar.js +++ b/grammar.js @@ -104,6 +104,7 @@ module.exports = grammar({ $.module_abbrev, $.import_decl, $.compiler_directive_decl, + $.fsi_directive_decl, $.type_definition, // $.exception_defn ), @@ -137,6 +138,13 @@ module.exports = grammar({ repeat($.string), ), + + fsi_directive_decl: $ => + choice( + seq("#r", repeat($.string)), + seq("#load", repeat($.string)), + ), + import_decl: $ => seq( "open", diff --git a/queries/highlights.scm b/queries/highlights.scm new file mode 100644 index 000000000..68b70ba7d --- /dev/null +++ b/queries/highlights.scm @@ -0,0 +1,196 @@ +;; ---------------------------------------------------------------------------- +;; Literals and comments + +[ + (line_comment) + (block_comment) + (block_comment_content) +] @comment + + +;; ---------------------------------------------------------------------------- +;; Punctuation + +[ + "(" + ")" + "{" + "}" + "[" + "]" + "[|" + "|]" + "[<" + ">]" +] @punctuation.bracket + +[ + "," + ";" +] @punctuation.delimiter + +[ + "|" + "=" + ">" + "<" + "-" + "~" + (infix_op) + (prefix_op) + (symbolic_op) +] @operator + + + +(attribute) @attribute + +[ + "if" + "then" + "else" + "elif" + "when" + "match" + "match!" + "and" + "or" + "&&" + "||" + "then" +] @keyword.control.conditional + +[ + "return" + "return!" +] @keyword.control.return + +[ + "for" + "while" +] @keyword.control.return + + +[ + "open" + "#r" + "#load" +] @keyword.control.import + +[ + "abstract" + "delegate" + "static" + "inline" + "internal" + "mutable" + "override" + "private" + "public" + "rec" +] @keyword.storage.modifier + +[ + "enum" + "let" + "let!" + "member" + "module" + "namespace" + "type" +] @keyword.storage + +[ + "as" + "assert" + "begin" + "default" + "do" + "do!" + "done" + "downcast" + "downto" + "end" + "event" + "field" + "finally" + "fun" + "function" + "get" + "global" + "inherit" + "interface" + "lazy" + "new" + "not" + "null" + "of" + "param" + "property" + "set" + "struct" + "try" + "upcast" + "use" + "use!" + "val" + "with" + "yield" + "yield!" +] @keyword + +[ + "true" + "false" + "unit" + ] @constant.builtin + +[ + (type) + (const) +] @constant + +[ + (union_type_case) + (rules (rule (identifier_pattern))) +] @type.enum + +(fsi_directive_decl (string) @namespace) + +[ + (import_decl (long_identifier)) + (named_module (long_identifier)) + (namespace (long_identifier)) + (named_module + name: (long_identifier) ) + (namespace + name: (long_identifier) ) +] @namespace + + +(dot_expression + base: (long_identifier_or_op) @variable.other.member + field: (long_identifier_or_op) @function) + +[ + ;;(value_declaration_left (identifier_pattern) ) + (function_declaration_left (identifier) ) + (call_expression (long_identifier_or_op (long_identifier))) + ;;(application_expression (long_identifier_or_op (long_identifier))) +] @function + +[ + (string) + (triple_quoted_string) +] @string + +[ + (int) + (int16) + (int32) + (int64) + (float) + (decimal) +] @constant.numeric + + diff --git a/src/grammar.json b/src/grammar.json index d4e8d26bc..1a2b084d4 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -113,6 +113,10 @@ "type": "SYMBOL", "name": "compiler_directive_decl" }, + { + "type": "SYMBOL", + "name": "fsi_directive_decl" + }, { "type": "SYMBOL", "name": "type_definition" @@ -224,6 +228,43 @@ } ] }, + "fsi_directive_decl": { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "#r" + }, + { + "type": "REPEAT", + "content": { + "type": "SYMBOL", + "name": "string" + } + } + ] + }, + { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "#load" + }, + { + "type": "REPEAT", + "content": { + "type": "SYMBOL", + "name": "string" + } + } + ] + } + ] + }, "import_decl": { "type": "SEQ", "members": [ diff --git a/src/node-types.json b/src/node-types.json index db0ddd303..566e97d23 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -141,6 +141,10 @@ "type": "compiler_directive_decl", "named": true }, + { + "type": "fsi_directive_decl", + "named": true + }, { "type": "import_decl", "named": true @@ -1414,6 +1418,21 @@ ] } }, + { + "type": "fsi_directive_decl", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "string", + "named": true + } + ] + } + }, { "type": "fun_expression", "named": true, @@ -3278,10 +3297,18 @@ "type": "#", "named": false }, + { + "type": "#load", + "named": false + }, { "type": "#nowarn", "named": false }, + { + "type": "#r", + "named": false + }, { "type": "$", "named": false diff --git a/corpus/attributes.txt b/test/corpus/attributes.txt similarity index 100% rename from corpus/attributes.txt rename to test/corpus/attributes.txt diff --git a/corpus/comments.txt b/test/corpus/comments.txt similarity index 100% rename from corpus/comments.txt rename to test/corpus/comments.txt diff --git a/corpus/compiler_directive.txt b/test/corpus/compiler_directive.txt similarity index 100% rename from corpus/compiler_directive.txt rename to test/corpus/compiler_directive.txt diff --git a/corpus/constants.txt b/test/corpus/constants.txt similarity index 100% rename from corpus/constants.txt rename to test/corpus/constants.txt diff --git a/corpus/expr.txt b/test/corpus/expr.txt similarity index 100% rename from corpus/expr.txt rename to test/corpus/expr.txt diff --git a/test/corpus/fsi_directives.txt b/test/corpus/fsi_directives.txt new file mode 100644 index 000000000..60b654f41 --- /dev/null +++ b/test/corpus/fsi_directives.txt @@ -0,0 +1,37 @@ +=== +refer dll +=== + +#r "path/to/MyAssembly.dll" + +--- + +(file + (fsi_directive_decl + (string))) + +=== +refer nuget package +=== + +#r "path/to/MyAssembly.dll" + +--- + +(file + (fsi_directive_decl + (string))) + +=== +load script +=== + +#load "Script1.fsx" + +--- + +(file + (fsi_directive_decl + (string))) + + diff --git a/corpus/function_defn.txt b/test/corpus/function_defn.txt similarity index 100% rename from corpus/function_defn.txt rename to test/corpus/function_defn.txt diff --git a/corpus/identifiers.txt b/test/corpus/identifiers.txt similarity index 100% rename from corpus/identifiers.txt rename to test/corpus/identifiers.txt diff --git a/corpus/import.txt b/test/corpus/import.txt similarity index 100% rename from corpus/import.txt rename to test/corpus/import.txt diff --git a/corpus/module.txt b/test/corpus/module.txt similarity index 100% rename from corpus/module.txt rename to test/corpus/module.txt diff --git a/corpus/module_abbrev.txt b/test/corpus/module_abbrev.txt similarity index 100% rename from corpus/module_abbrev.txt rename to test/corpus/module_abbrev.txt diff --git a/corpus/patterns.txt b/test/corpus/patterns.txt similarity index 100% rename from corpus/patterns.txt rename to test/corpus/patterns.txt diff --git a/corpus/source_file.txt b/test/corpus/source_file.txt similarity index 100% rename from corpus/source_file.txt rename to test/corpus/source_file.txt diff --git a/corpus/type_defn.txt b/test/corpus/type_defn.txt similarity index 100% rename from corpus/type_defn.txt rename to test/corpus/type_defn.txt diff --git a/test/highlight/fsi_directives.fsx b/test/highlight/fsi_directives.fsx new file mode 100644 index 000000000..57691b34a --- /dev/null +++ b/test/highlight/fsi_directives.fsx @@ -0,0 +1,10 @@ +#r "nuget: FSharp.Compiler.Service, 43.7.300" +//<- keyword.control.import +// ^ namespace +#r "/home/bin/MyApp.dll" +//<- keyword.control.import +// ^ namespace +#load "Strings.fsx" +//<- keyword.control.import +// ^ namespace +