Skip to content

Commit

Permalink
properly annotate paths in the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira authored and paulcadman committed Feb 9, 2024
1 parent d24476e commit e6083f2
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/Juvix/Compiler/Nockma/Translation/FromSource/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Juvix.Compiler.Nockma.Language
import Juvix.Extra.Strings qualified as Str
import Juvix.Parser.Error
import Juvix.Parser.Lexer (onlyInterval, withLoc)
import Juvix.Prelude hiding (Atom, many, some)
import Juvix.Prelude hiding (Atom, Path, many, some)
import Juvix.Prelude.Parsing hiding (runParser)
import Text.Megaparsec qualified as P
import Text.Megaparsec.Char.Lexer qualified as L
Expand Down Expand Up @@ -86,18 +86,25 @@ atomOp = do
}
return (Atom (serializeNockOp op') info)

atomDirection :: Parser (Atom Natural)
atomDirection = do
WithLoc loc dirs <-
withLoc $
symbol "S" $> []
<|> NonEmpty.toList <$> some (choice [symbol "L" $> L, symbol "R" $> R])
atomPath :: Parser (Atom Natural)
atomPath = do
WithLoc loc path <- withLoc pPath
let info =
AtomInfo
{ _atomInfoHint = Just AtomHintOp,
{ _atomInfoHint = Just AtomHintPath,
_atomInfoLoc = Irrelevant (Just loc)
}
return (Atom (serializePath dirs) info)
return (Atom (serializePath path) info)

direction :: Parser Direction
direction =
symbol "L" $> L
<|> symbol "R" $> R

pPath :: Parser Path
pPath =
symbol "S" $> []
<|> NonEmpty.toList <$> some direction

atomNat :: Parser (Atom Natural)
atomNat = do
Expand Down Expand Up @@ -131,7 +138,7 @@ patom :: Parser (Atom Natural)
patom =
atomOp
<|> atomNat
<|> atomDirection
<|> atomPath
<|> atomBool
<|> atomNil
<|> atomVoid
Expand Down

0 comments on commit e6083f2

Please sign in to comment.