slow but steady progress on parser
This commit is contained in:
parent
d4a047e528
commit
4dda3ec33d
|
@ -20,7 +20,7 @@ haskellPackages.mkDerivation {
|
||||||
isExecutable = true;
|
isExecutable = true;
|
||||||
enableSeparateDataOutput = true;
|
enableSeparateDataOutput = true;
|
||||||
libraryHaskellDepends = haskellDeps;
|
libraryHaskellDepends = haskellDeps;
|
||||||
executableHaskellDepends = haskellDeps;
|
executableHaskellDepends = haskellPackages.base;
|
||||||
homepage = "https://github.com/JoyOfHardware/haskellator#readme";
|
homepage = "https://github.com/JoyOfHardware/haskellator#readme";
|
||||||
license = pkgs.lib.licenses.gpl3Only;
|
license = pkgs.lib.licenses.gpl3Only;
|
||||||
mainProgram = "rtlil-parse";
|
mainProgram = "rtlil-parse";
|
||||||
|
|
|
@ -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
|
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 :: Int
|
||||||
a = 3
|
a = 3
|
Loading…
Reference in a new issue