Skip to content

Commit b9e9433

Browse files
committed
Detect comments after variable values
1 parent 434bf6c commit b9e9433

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

parser.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ func parse() {
188188
switch {
189189
case char == ' ' || char == '\t' || char == '\n':
190190
advance()
191+
case isChar('/'):
192+
collectComment()
191193
case tokenAhead(Question):
192194
collectQuestion()
193195
case tokenAhead(Definition):
@@ -199,8 +201,6 @@ func parse() {
199201
case tokenAhead(Constant):
200202
advance()
201203
collectVariable(true)
202-
case isChar('/'):
203-
collectComment()
204204
case tokenAhead(Repeat):
205205
collectRepeat()
206206
case tokenAhead(RepeatWithEach):
@@ -293,18 +293,21 @@ func lookAheadUntil(until rune) string {
293293

294294
func collectVariableValue(constant bool, valueType *tokenType, value *any) {
295295
collectValue(valueType, value, '\n')
296-
297-
var aheadOfValue = lookAheadUntil('\n')
298-
if containsExpressionTokens(aheadOfValue) {
299-
collectExpression(valueType, value)
300-
return
301-
}
302296
if constant && (*valueType == Arr || *valueType == Variable) {
303297
parserError(fmt.Sprintf("Type %v values cannot be constants.", *valueType))
304298
}
305299
if *valueType == Question {
306300
parserError(fmt.Sprintf("Illegal reference to import question '%s'. Shortcuts does not support import questions as variable values.", *value))
307301
}
302+
303+
var aheadOfValue = lookAheadUntil('\n')
304+
if strings.Contains(aheadOfValue, "//") || strings.Contains(aheadOfValue, "/*") {
305+
return
306+
}
307+
if containsExpressionTokens(aheadOfValue) {
308+
collectExpression(valueType, value)
309+
return
310+
}
308311
}
309312

310313
func collectExpression(valueType *tokenType, value *any) {

0 commit comments

Comments
 (0)