Skip to content

Commit dffa4ea

Browse files
committed
Add optionalTrivia parser
1 parent e18bd6a commit dffa4ea

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/language/parsing/molecule.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
openingParenthesis,
2626
} from './literals.js'
2727
import { optionallySurroundedByParentheses } from './parentheses.js'
28-
import { trivia } from './trivia.js'
28+
import { optionalTrivia, trivia } from './trivia.js'
2929

3030
export type Molecule = { readonly [key: Atom]: Molecule | Atom }
3131

@@ -52,7 +52,7 @@ const propertyValue = oneOf([
5252
])
5353

5454
const namedProperty = map(
55-
sequence([propertyKey, colon, optional(trivia), propertyValue]),
55+
sequence([propertyKey, colon, optionalTrivia, propertyValue]),
5656
([key, _colon, _trivia, value]) => [key, value] as const,
5757
)
5858

@@ -65,16 +65,16 @@ const property = (index: Indexer) =>
6565
)
6666

6767
const propertyDelimiter = oneOf([
68-
sequence([optional(trivia), comma, optional(trivia)]),
68+
sequence([optionalTrivia, comma, optionalTrivia]),
6969
trivia,
7070
])
7171

7272
const argument = map(
7373
sequence([
7474
openingParenthesis,
75-
optional(trivia),
75+
optionalTrivia,
7676
propertyValue,
77-
optional(trivia),
77+
optionalTrivia,
7878
closingParenthesis,
7979
]),
8080
([_openingParenthesis, _trivia1, argument, _trivia2, _closingParenthesis]) =>
@@ -83,9 +83,9 @@ const argument = map(
8383

8484
const dottedKeyPathComponent = map(
8585
sequence([
86-
optional(trivia),
86+
optionalTrivia,
8787
dot,
88-
optional(trivia),
88+
optionalTrivia,
8989
atomWithAdditionalQuotationRequirements(dot),
9090
]),
9191
([_trivia1, _dot, _trivia2, key]) => key,

src/language/parsing/trivia.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
anySingleCharacter,
33
butNot,
44
lookaheadNot,
5+
nothing,
56
oneOf,
67
oneOrMore,
78
regularExpression,
@@ -38,3 +39,5 @@ export const whitespace = regularExpression(/^\s+/)
3839
export const trivia = oneOrMore(
3940
oneOf([whitespace, singleLineComment, blockComment]),
4041
)
42+
43+
export const optionalTrivia = oneOf([trivia, nothing])

0 commit comments

Comments
 (0)