@@ -22,8 +22,9 @@ type Elaborated = { readonly [_elaborated]: true }
2222export type ElaboratedSemanticGraph = WithPhantomData < SemanticGraph , Elaborated >
2323
2424export type ExpressionContext = {
25- readonly program : SemanticGraph
25+ readonly keywordHandlers : KeywordHandlers
2626 readonly location : KeyPath
27+ readonly program : SemanticGraph
2728}
2829
2930export type KeywordElaborationResult = Either < ElaborationError , SemanticGraph >
@@ -39,7 +40,8 @@ export const elaborate = (
3940 program : SyntaxTree ,
4041 keywordHandlers : KeywordHandlers ,
4142) : Either < ElaborationError , ElaboratedSemanticGraph > =>
42- elaborateWithContext ( program , keywordHandlers , {
43+ elaborateWithContext ( program , {
44+ keywordHandlers,
4345 location : [ ] ,
4446 program :
4547 typeof program === 'string'
@@ -49,19 +51,17 @@ export const elaborate = (
4951
5052export const elaborateWithContext = (
5153 program : SyntaxTree ,
52- keywordHandlers : KeywordHandlers ,
5354 context : ExpressionContext ,
5455) : Either < ElaborationError , ElaboratedSemanticGraph > =>
5556 either . map (
5657 typeof program === 'string'
5758 ? handleAtomWhichMayNotBeAKeyword ( program )
58- : elaborateWithinMolecule ( program , keywordHandlers , context ) ,
59+ : elaborateWithinMolecule ( program , context ) ,
5960 withPhantomData < Elaborated > ( ) ,
6061 )
6162
6263const elaborateWithinMolecule = (
6364 molecule : Molecule ,
64- keywordHandlers : KeywordHandlers ,
6565 context : ExpressionContext ,
6666) : Either < ElaborationError , SemanticGraph > => {
6767 const possibleExpressionAsObjectNode : Writable < ObjectNode > = makeObjectNode (
@@ -79,14 +79,11 @@ const elaborateWithinMolecule = (
7979 if ( typeof value === 'string' ) {
8080 possibleExpressionAsObjectNode [ updatedKey ] = value
8181 } else {
82- const elaborationResult = elaborateWithinMolecule (
83- value ,
84- keywordHandlers ,
85- {
86- location : [ ...context . location , key ] ,
87- program : updatedProgram ,
88- } ,
89- )
82+ const elaborationResult = elaborateWithinMolecule ( value , {
83+ keywordHandlers : context . keywordHandlers ,
84+ location : [ ...context . location , key ] ,
85+ program : updatedProgram ,
86+ } )
9087 if ( either . isLeft ( elaborationResult ) ) {
9188 // Immediately bail on error.
9289 return elaborationResult
@@ -146,8 +143,8 @@ const elaborateWithinMolecule = (
146143 ...possibleExpressionAsObjectNode ,
147144 0 : possibleKeywordAsString ,
148145 } ,
149- keywordHandlers ,
150146 {
147+ keywordHandlers : context . keywordHandlers ,
151148 program : updatedProgram ,
152149 location : context . location ,
153150 } ,
@@ -158,7 +155,6 @@ const elaborateWithinMolecule = (
158155
159156const handleObjectNodeWhichMayBeAExpression = (
160157 node : ObjectNode & { readonly 0 : Atom } ,
161- keywordHandlers : KeywordHandlers ,
162158 context : ExpressionContext ,
163159) : Either < ElaborationError , SemanticGraph > => {
164160 const { 0 : possibleKeyword , ...possibleArguments } = node
@@ -174,7 +170,7 @@ const handleObjectNodeWhichMayBeAExpression = (
174170 0 : unescapeKeywordSigil ( possibleKeyword ) ,
175171 } ) ,
176172 some : keyword =>
177- keywordHandlers [ keyword ] (
173+ context . keywordHandlers [ keyword ] (
178174 makeObjectNode ( { ...possibleArguments , 0 : keyword } ) ,
179175 context ,
180176 ) ,
0 commit comments