Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default grammar({
$._continuation,
$.block_comment,
'"',
'`',
$._template_chars,
$._lparen,
$._rparen,
Expand Down Expand Up @@ -118,6 +117,7 @@ export default grammar({
[$.primary_expression, $.spread_pattern],
[$.primary_expression, $._literal_pattern],
[$.primary_expression, $._jsx_child],
[$._jsx_child, $.tagged_template_expression],
[$.tuple_type, $.function_type_parameter],
[$.list, $.list_pattern],
[$.array, $.array_pattern],
Expand Down Expand Up @@ -491,6 +491,7 @@ export default grammar({
$.value_identifier,
$.number,
$.string,
$.tagged_template_expression,
$.template_string,
$.character,
$.true,
Expand Down Expand Up @@ -1404,24 +1405,21 @@ export default grammar({
),
),

template_string: ($) =>
seq(
token(
seq(
optional(
choice(
/[a-z_][a-zA-Z0-9_']*/,
// escape_sequence
seq('\\"', /[^"]+/, '"'),
),
),
'`',
// The tag is a function: ReScript parses this as an application
tagged_template_expression: ($) =>
prec(
'call',
seq(
field(
'function',
choice($.value_identifier, $.value_identifier_path),
),
field('arguments', $.template_string),
),
optional($.template_string_content),
'`',
),

template_string: ($) => seq('`', optional($.template_string_content), '`'),

template_string_content: ($) =>
repeat1(
choice(
Expand All @@ -1439,9 +1437,6 @@ export default grammar({
// prettier-ignore
seq('\'', repeat(choice(/[^\\']/, $.escape_sequence)), '\''),

_unescaped_template_string_fragment: ($) =>
token.immediate(prec(1, /[^`\\\$]+/)),

lparen: ($) => alias($._lparen, '('),
rparen: ($) => alias($._rparen, ')'),
uncurry: ($) => '.',
Expand Down
8 changes: 8 additions & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@
(call_expression
function: (value_identifier) @function.call)

(tagged_template_expression
function: (value_identifier_path
_
(value_identifier) @function.call))

(tagged_template_expression
function: (value_identifier) @function.call)

; highlight the right-hand side of a pipe operator as a function call
(pipe_expression
_
Expand Down
24 changes: 21 additions & 3 deletions queries/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,36 @@
(extension_identifier) @_name
(#eq? @_name "raw")
(expression_statement
(_ (_) @injection.content (#set! injection.language "javascript"))))
[
(string (string_fragment) @injection.content)
(template_string (template_string_content) @injection.content)
(tagged_template_expression
(template_string (template_string_content) @injection.content))
]
(#set! injection.language "javascript")))

; %graphql
(extension_expression
(extension_identifier) @_name
(#eq? @_name "graphql")
(expression_statement
(_ (_) @injection.content (#set! injection.language "graphql"))))
[
(string (string_fragment) @injection.content)
(template_string (template_string_content) @injection.content)
(tagged_template_expression
(template_string (template_string_content) @injection.content))
]
(#set! injection.language "graphql")))

; %relay
(extension_expression
(extension_identifier) @_name
(#eq? @_name "relay")
(expression_statement
(_ (_) @injection.content (#set! injection.language "graphql") )))
[
(string (string_fragment) @injection.content)
(template_string (template_string_content) @injection.content)
(tagged_template_expression
(template_string (template_string_content) @injection.content))
]
(#set! injection.language "graphql")))
103 changes: 44 additions & 59 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading