@@ -295,23 +295,32 @@ const compactExpression: Parser<Molecule | Atom> = oneOf([
295295
296296const trailingInfixTokens = oneOrMore (
297297 map (
298- sequence ( [
299- trivia ,
300- infixOperator ,
301- // Allowing newlines here could lead to ambiguity. The following object could either
302- // have three enumerated atom-valued properties, or a single enumerated property
303- // whose value is the result of an infix expression:
298+ oneOf ( [
299+ // Allowing newlines both before and after operators could lead to
300+ // ambiguity between three enumerated object properties, or a single
301+ // enumerated property whose value is the result of an infix expression:
304302 // ```
305303 // {
306304 // 1
307305 // +
308306 // 1
309307 // }
310308 // ```
311- // TODO: This could be made context-dependent, only forbidding newlines when between
312- // curly braces. Currently this forbids the above formatting even within parentheses.
313- triviaExceptNewlines ,
314- compactExpression ,
309+ // TODO: This could be made context-dependent, only forbidding newlines
310+ // when between curly braces. Currently this forbids the above formatting
311+ // even within parentheses, where there would be no ambiguity.
312+ sequence ( [
313+ trivia ,
314+ infixOperator ,
315+ triviaExceptNewlines ,
316+ compactExpression ,
317+ ] ) ,
318+ sequence ( [
319+ triviaExceptNewlines ,
320+ infixOperator ,
321+ trivia ,
322+ compactExpression ,
323+ ] ) ,
315324 ] ) ,
316325 ( [ _trivia1 , operator , _trivia2 , operand ] ) => [ operator , operand ] as const ,
317326 ) ,
@@ -425,11 +434,20 @@ const precededByColonThenAtom = map(
425434 trailingIndexesAndArguments ,
426435 zeroOrMore (
427436 map (
428- sequence ( [
429- trivia ,
430- infixOperator ,
431- triviaExceptNewlines , // See note in `precededByAtomThenTrivia`.
432- compactExpression ,
437+ // See note in `trailingInfixTokens` about newlines.
438+ oneOf ( [
439+ sequence ( [
440+ trivia ,
441+ infixOperator ,
442+ triviaExceptNewlines ,
443+ compactExpression ,
444+ ] ) ,
445+ sequence ( [
446+ triviaExceptNewlines ,
447+ infixOperator ,
448+ trivia ,
449+ compactExpression ,
450+ ] ) ,
433451 ] ) ,
434452 ( [ _trivia1 , operator , _trivia2 , operand ] ) =>
435453 [ operator , operand ] as const ,
0 commit comments