Add basic query highlights (#25)

* Add basic highlight queries

* Move corpus to test. Add fsi directive node.
pull/625/head
kaashyapan 2023-07-13 18:05:33 +07:00 committed by GitHub
parent f0c2ac6aa1
commit f77763cdb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 319 additions and 0 deletions

@ -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",

@ -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

@ -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": [

@ -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

@ -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)))

@ -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