11import {
22 lazy ,
3- literal ,
43 map ,
54 nothing ,
65 oneOf ,
@@ -15,6 +14,16 @@ import {
1514 atomWithAdditionalQuotationRequirements ,
1615 type Atom ,
1716} from './atom.js'
17+ import {
18+ arrow ,
19+ closingBrace ,
20+ closingParenthesis ,
21+ colon ,
22+ comma ,
23+ dot ,
24+ openingBrace ,
25+ openingParenthesis ,
26+ } from './literals.js'
1827import { optionallySurroundedByParentheses } from './parentheses.js'
1928import { trivia } from './trivia.js'
2029
@@ -43,7 +52,7 @@ const propertyValue = oneOf([
4352] )
4453
4554const namedProperty = map (
46- sequence ( [ propertyKey , literal ( ':' ) , optional ( trivia ) , propertyValue ] ) ,
55+ sequence ( [ propertyKey , colon , optional ( trivia ) , propertyValue ] ) ,
4756 ( [ key , _colon , _trivia , value ] ) => [ key , value ] as const ,
4857)
4958
@@ -56,17 +65,17 @@ const property = (index: Indexer) =>
5665 )
5766
5867const propertyDelimiter = oneOf ( [
59- sequence ( [ optional ( trivia ) , literal ( ',' ) , optional ( trivia ) ] ) ,
68+ sequence ( [ optional ( trivia ) , comma , optional ( trivia ) ] ) ,
6069 trivia ,
6170] )
6271
6372const argument = map (
6473 sequence ( [
65- literal ( '(' ) ,
74+ openingParenthesis ,
6675 optional ( trivia ) ,
6776 propertyValue ,
6877 optional ( trivia ) ,
69- literal ( ')' ) ,
78+ closingParenthesis ,
7079 ] ) ,
7180 ( [ _openingParenthesis , _trivia1 , argument , _trivia2 , _closingParenthesis ] ) =>
7281 argument ,
@@ -75,9 +84,9 @@ const argument = map(
7584const dottedKeyPathComponent = map (
7685 sequence ( [
7786 optional ( trivia ) ,
78- literal ( '.' ) ,
87+ dot ,
7988 optional ( trivia ) ,
80- atomWithAdditionalQuotationRequirements ( literal ( '.' ) ) ,
89+ atomWithAdditionalQuotationRequirements ( dot ) ,
8190 ] ) ,
8291 ( [ _trivia1 , _dot , _trivia2 , key ] ) => key ,
8392)
@@ -87,7 +96,7 @@ const moleculeAsEntries = (
8796) : Parser < readonly ( readonly [ string , string | Molecule ] ) [ ] > =>
8897 map (
8998 sequence ( [
90- literal ( '{' ) ,
99+ openingBrace ,
91100 // Allow initial property not preceded by a delimiter (e.g. `{a b}`).
92101 optional ( property ( index ) ) ,
93102 zeroOrMore (
@@ -97,7 +106,7 @@ const moleculeAsEntries = (
97106 ) ,
98107 ) ,
99108 optional ( propertyDelimiter ) ,
100- literal ( '}' ) ,
109+ closingBrace ,
101110 ] ) ,
102111 ( [
103112 _openingBrace ,
@@ -121,17 +130,17 @@ const sugarFreeMolecule: Parser<Molecule> = optionallySurroundedByParentheses(
121130const sugaredLookup : Parser < Molecule > = optionallySurroundedByParentheses (
122131 map (
123132 sequence ( [
124- literal ( ':' ) ,
133+ colon ,
125134 // Reserve `.` so that `:a.b` is parsed as a lookup followed by an index.
126- atomWithAdditionalQuotationRequirements ( literal ( '.' ) ) ,
135+ atomWithAdditionalQuotationRequirements ( dot ) ,
127136 ] ) ,
128137 ( [ _colon , key ] ) => ( { 0 : '@lookup' , key } ) ,
129138 ) ,
130139)
131140
132141const sugaredFunction : Parser < Molecule > = optionallySurroundedByParentheses (
133142 map (
134- sequence ( [ atomParser , trivia , literal ( '=>' ) , trivia , propertyValue ] ) ,
143+ sequence ( [ atomParser , trivia , arrow , trivia , propertyValue ] ) ,
135144 ( [ parameter , _trivia1 , _arrow , _trivia2 , body ] ) => ( {
136145 0 : '@function' ,
137146 parameter,
0 commit comments