Skip to content

Commit c5ccea0

Browse files
add constant string concatenation (#126)
1 parent 21e0e7b commit c5ccea0

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

grammar.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ module.exports = grammar({
131131
alias($._constant_bit_string, $.bit_string),
132132
alias($.constant_record, $.record),
133133
$.identifier,
134-
alias($.constant_field_access, $.field_access)
134+
alias($.constant_field_access, $.field_access),
135+
alias($.constant_binary_expression, $.binary_expression)
135136
),
136137
constant_tuple: ($) =>
137138
seq("#", "(", optional(series_of($._constant_value, ",")), ")"),
@@ -159,6 +160,8 @@ module.exports = grammar({
159160
),
160161
seq(field("label", $.label), ":")
161162
),
163+
constant_binary_expression: ($) =>
164+
choice(binaryExpr(prec.left, 7, "<>", $._constant_value)),
162165
// This rule exists to parse remote function references which are generally
163166
// indistinguishable from field accesses and so share an AST node.
164167
constant_field_access: ($) =>

test/corpus/constants.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,24 @@ const b = Wibble(arg:, arg:)
463463
(label))
464464
(argument
465465
(label))))))
466+
467+
================================================================================
468+
String concatenation constants
469+
================================================================================
470+
471+
const name = "Jak"
472+
const string = "hello, " <> name <> "!"
473+
474+
--------------------------------------------------------------------------------
475+
476+
(source_file
477+
(constant
478+
(identifier)
479+
(string (quoted_content)))
480+
(constant
481+
(identifier)
482+
(binary_expression
483+
(binary_expression
484+
(string (quoted_content))
485+
(identifier))
486+
(string (quoted_content)))))

test/highlight/constants.gleam

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ const s = "Hello, \e\t\n"
88
// ^ warning
99
// ^ string.escape
1010
// ^ string.escape
11+
12+
const s = "Hello, " <> "World!"
13+
// ^ string
14+
// ^ operator
15+
// ^ string

0 commit comments

Comments
 (0)