Skip to content

Commit

Permalink
feat: format strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Nsidorenco committed Apr 22, 2024
1 parent 3720231 commit 7696a57
Show file tree
Hide file tree
Showing 7 changed files with 318,732 additions and 298,755 deletions.
5 changes: 2 additions & 3 deletions examples/expressions.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

let f = A {
x
}
let str =
$"int: {x + 1}"
30 changes: 28 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,22 @@ module.exports = grammar({
seq('\\', $._string_elem),
),
char: $ => seq('\'', $._char_char, token.immediate('\'')),
string: $ => seq('"', repeat($._string_char), '"'),

format_string_eval: $ =>
seq(token.immediate(prec(1000, '{')), $._expression, '}'),

format_string: $ =>
seq(
token(prec(100, '$"')),
repeat(choice($.format_string_eval, $._string_char)),
'"',
),

string: $ =>
choice(
seq('"', repeat($._string_char), '"'),
$.format_string,
),
_verbatim_string_char: $ => choice(
$._simple_string_char,
$._non_escape_char,
Expand All @@ -1625,7 +1640,18 @@ module.exports = grammar({

_triple_quoted_end: _ => token.immediate('"""'),

triple_quoted_string: $ => seq('"""', repeat($._string_char), $._triple_quoted_end),
format_triple_quoted_string: $ =>
seq(
token(prec(100, '$"""')),
repeat(choice($.format_string_eval, $._string_char)),
'"""',
),

triple_quoted_string: $ =>
choice(
seq('"""', repeat($._string_char), $._triple_quoted_end),
$.format_triple_quoted_string,
),

bool: _ => token(choice('true', 'false')),

Expand Down
134 changes: 124 additions & 10 deletions src/grammar.json

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

81 changes: 77 additions & 4 deletions src/node-types.json

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

Loading

0 comments on commit 7696a57

Please sign in to comment.