From 4dda3ec33da84328dd28927751865d04fb212628 Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Sun, 17 Nov 2024 20:18:37 -0500 Subject: [PATCH] slow but steady progress on parser --- default.nix | 2 +- src/Haskellator.hs | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 8ae91f6..f55f8c5 100644 --- a/default.nix +++ b/default.nix @@ -20,7 +20,7 @@ haskellPackages.mkDerivation { isExecutable = true; enableSeparateDataOutput = true; libraryHaskellDepends = haskellDeps; - executableHaskellDepends = haskellDeps; + executableHaskellDepends = haskellPackages.base; homepage = "https://github.com/JoyOfHardware/haskellator#readme"; license = pkgs.lib.licenses.gpl3Only; mainProgram = "rtlil-parse"; diff --git a/src/Haskellator.hs b/src/Haskellator.hs index 5f5cf8c..b2cac52 100644 --- a/src/Haskellator.hs +++ b/src/Haskellator.hs @@ -1,4 +1,33 @@ +-- this parser largely references: +-- https://github.com/YosysHQ/yosys/blob/111b747d2797238eadf541879848492a9d34909a/docs/source/yosys_internals/formats/rtlil_text.rst module Haskellator(a) where +import Text.Parsec +import Text.Parsec.String (Parser) + +-- https://github.com/YosysHQ/yosys/blob/111b747d2797238eadf541879848492a9d34909a/frontends/rtlil/rtlil_lexer.l#L88C1-L88C17 +nonws :: Parser Char +nonws = noneOf " \t\r\n" + +pPublicId :: Parser String +pPublicId = char '\\' *> many1 nonws + +pAutogenId :: Parser String +pAutogenId = char '$' *> many1 nonws + +decimalDigit :: Parser Char +decimalDigit = oneOf "0123456789" + +binaryDigit :: Parser Char +binaryDigit = oneOf "01xzm-" + +-- an integer can be positive or negative +pInteger :: Parser Int +pInteger = read <$> (pNegInt <|> pPosInt) + where + pIntAtom = many1 decimalDigit + pNegInt = char '-' *> pIntAtom + pPosInt = pIntAtom + a :: Int a = 3 \ No newline at end of file