MachineGunPablo

u/MachineGunPablo


r/haskell•

Hello everyone,

I'm currently writing a parser using megaparsec which produces the following output:

data FileElement
  = SyntaxStmt SyntaxStatement
  | PackageSpec PackageSpecification
  | ImportStmt ImportStatement
  | OptionDef OptionDefinition
  | MsgDef MessageDefinition
  | EnumDef EnumDefinition
  | ServiceDef ServiceDefinition
  deriving (Show, Eq)

type File = [FileElement]

it goes on with more nested substructures.

Now I realized that I need to record the location in the document for every entity.

What would be the best way of integrating this into the AST? I would like to avoid changing the AST itself, but have the location information

185

r/haskell•

Hello,

I'm currently writing a parser for a simple DSL and want to write a test where I load a file from disk, feed it to the parser, and study the output produced by the parser, something like an integration/system test if you want. I'm currently using hspec for unit tests and stack.

My question is, what would be the best way to achieve this?

  1. is hspec the right tool for this kind of job?
  2. how can I get the path of the file to load(assuming its in a know location in the same repo)?

Thanks a lot and happy haskelling.

94

r/vim•

Hello, I program in C/C++ and want to build from vim using ninja.

I've been trying to find an ninja compiler plugin file so that I can do:

:compiler ninja
:make -C build

To my surprise I haven't been able to find one on the internet, so I thought I can ask if somebody here compiles using ninja from Vim? What do you use in that case?

Thank you and happy vimming.

46

r/haskell•

Hello, this may be quite a basic question, but haven't yet fully figured out the best way of defining the same set of compiler warnings to be used for the entire project.

I have a stack project with the standard/default project template, my package.yaml defines three targets:

library:
  source-dirs: src

executables:
  hs-protoparser-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - hs-protoparser

tests:
  hs-protoparser-test:
    main:                Spec.hs
    source-dirs:         test
    ghc-options:
31

r/cmake•

Hello, today I came across the following scenario:

I have a static lib that links against a dynamic lib:

add_library(static_lib src/lib.cpp)
target_link_libraries(static_lib dynamic_lib)

And an executable that depends on both:

add_executable(my_exec src/main.cpp)
target_link_libraries(my_exec dynamic_lib static_lib)

With this setup I get a linker error when building my_exec for a symbol defined by dynamic_lib used in static_lib. This makes sense, as dynamic_lib is linked before static_lib.

I know that one way to solve the problem is to do this:

add_executable(my_exec src/main.cpp)
target_link_libraries(my_exec static_lib dynamic_lib)

But, isn't there

21

r/haskell•

Hello Haskellers of the internet, I need your help.

I'm currently writing a parser using Megaparsec and have reached a point where I could use some input from smarter coders.

I have a grammar with multiple top-level statements, which can appear any number of times in any order, in EBNF, this would be something like:

topLevelStament -> Variant1 | Variant2
Variant1 -> ...
Variant2 -> ...

For this, I defined the following Haskell types:

data Variant1 = Variant1 String
data Variant2 = Variant2 String

I want the AST to have the following final structure:

data AST = { variants1 :: [Variant1], variants2 :: [Variant2] }

For parsing, I created a type `topLevel

811

r/i3wm•

I just wanted to share a very useful configuration that I created that has immensely helped my workflow.

I use Vim as my main text editor. My problem is that I need to enter text in non-vim environments like reddit (as writing this post), slack, discord, jira tickets, etc. I just want to be able to use vim everywhere, and not just vim bindings, my vim.

I also want a configuration that works system-wide and is minimal, i.e. that doesn't require me to install any browser extensions or plugins.

For this, I created a script that opens a temporary file in nvim in a floating window where I can edit the text using my normal nvim config (for markdown specially I have folding, syntax highlightin

9628

r/haskell•

Hello, I'm still very new to Megaparsec and Haskell in general, so this is probably a very basic question.

I want to write a parser for a simple DSL using Megaparsec and for this I'm following the Megaparsec tutorial here.

At the beginning of the tutorial the author provides the following example for constructing a parser for the string "abc":

-- Parsec as defined in the library is:
-- type Parsec e s a = ParsecT e s Identity a

type Parser = Parsec Void Text

mySequence :: Parser (Char, Char, Char)
mySequence = do
  a <- char 'a'
  b <- char 'b'
  c <- char 'c'
  return (a, b, c)

Here is what I'm trying to unde

94