Skip to content

Commit

Permalink
Defunctionalize the implementation of mapDollarDollar
Browse files Browse the repository at this point in the history
This prepares us to fix the AST for this purpose
  • Loading branch information
Ericson2314 authored and sgraf812 committed Sep 20, 2024
1 parent 26b76ab commit 43e192a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/grammar/src/Happy/Grammar.lhs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ For array-based parsers, see the note in Tabular/LALR.lhs.
Replace $$ with an arbitrary string, being careful to avoid ".." and '.'.
> mapDollarDollar :: String -> Maybe (String -> String)
> mapDollarDollar code0 = go code0 ""
> mapDollarDollar = fmap (\(l, r) repr -> l ++ repr ++ r) . mapDollarDollar'
>
> mapDollarDollar' :: String -> Maybe (String, String)
> mapDollarDollar' code0 = go code0 ""
> where go code acc =
> case code of
> [] -> Nothing
Expand All @@ -163,5 +167,5 @@ Replace $$ with an arbitrary string, being careful to avoid ".." and '.'.
> [] -> go r ('\'':acc)
> (c,r'):_ -> go r' (reverse (show c) ++ acc)
> '\\':'$':r -> go r ('$':acc)
> '$':'$':r -> Just (\repl -> reverse acc ++ repl ++ r)
> '$':'$':r -> Just (reverse acc, r)
> c:r -> go r (c:acc)

0 comments on commit 43e192a

Please sign in to comment.