Skip to content

Commit

Permalink
(Working) match AST working for both case and type
Browse files Browse the repository at this point in the history
  • Loading branch information
sigilante committed Nov 15, 2024
1 parent 52ef429 commit a654557
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions hoon/lib/jock.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -524,27 +524,17 @@
:: [%match value=jock cases=(map jype jock) default=(unit jock)]
:: [%cases value=jock cases=(map jock jock) default=(unit jock)]
?: (has-keyword -.tokens %case)
~& > 'case'
=^ value tokens
(match-inner-jock +.tokens)
~& > 'value'
~& > value
=^ pairs tokens
(match-block [tokens %'{' %'}'] match-cases)
~& > 'pairs'
~& > pairs
:_ tokens
[%cases value -.pairs +.pairs]
?> (has-keyword -.tokens %type)
~& > 'type'
=^ value tokens
(match-inner-jock +.tokens)
~& > 'value'
~& > value
=^ pairs tokens
(match-block [tokens %'{' %'}'] match-match)
~& > 'pairs'
~& > pairs
:_ tokens
[%match value -.pairs +.pairs]
::
Expand Down Expand Up @@ -742,24 +732,21 @@
++ match-block
|* [[=tokens start=punctuator end=punctuator] gate=$-(tokens [* tokens])]
?> (got-punctuator -.tokens start)
~& > 'match-block'
=^ output tokens
(gate +.tokens)
~& > 'output'
~& > output
?> (got-punctuator -.tokens end)
[output +.tokens]
::
++ match-match
|= =tokens
^- [[(map jype jock) (unit jock)] (list token)]
!:
?: =(~ tokens) ~|("expect map. token: ~" !!)
=| fall=(unit jock)
=/ cf=[(map jype jock) (unit jock)]
=^ cf=[(map jype jock) (unit jock)] tokens
=| duo=(list [jype jock])
|- ^- [(map jype jock) (unit jock)]
?: =(~ tokens) [(malt duo) fall]
|- ^- [[(map jype jock) (unit jock)] (list token)]
?: (has-punctuator -.tokens %'}')
[[(malt duo) fall] tokens]
:: default case, must be last
?: (has-punctuator -.tokens %'_')
?> (got-punctuator -.+.tokens %'-')
Expand All @@ -769,7 +756,7 @@
=. tokens +.tokens
?> (has-punctuator -.tokens %'}') :: no trailing tokens in case block
=. fall `jock
[(malt duo) fall]
[[(malt duo) fall] tokens]
:: regular case
=^ jype tokens (match-jype tokens)
?> (got-punctuator -.tokens %'-')
Expand All @@ -785,13 +772,13 @@
++ match-cases
|= =tokens
^- [[(map jock jock) (unit jock)] (list token)]
!:
?: =(~ tokens) ~|("expect map. token: ~" !!)
=| fall=(unit jock)
=/ cf=[(map jock jock) (unit jock)]
=^ cf=[(map jock jock) (unit jock)] tokens
=| duo=(list [jock jock])
|- ^- [(map jock jock) (unit jock)]
?: =(~ tokens) [(malt duo) fall]
|- ^- [[(map jock jock) (unit jock)] (list token)]
?: (has-punctuator -.tokens %'}')
[[(malt duo) fall] tokens]
:: default case, must be last
?: (has-punctuator -.tokens %'_')
?> (got-punctuator -.+.tokens %'-')
Expand All @@ -801,7 +788,7 @@
=. tokens +.tokens
?> (has-punctuator -.tokens %'}') :: no trailing tokens in case block
=. fall `jock
[(malt duo) fall]
[[(malt duo) fall] tokens]
:: regular case
=^ case tokens (match-jock tokens)
?> (got-punctuator -.tokens %'-')
Expand Down

0 comments on commit a654557

Please sign in to comment.