Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4334916
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:35:54+00:00 2026-05-21T10:35:54+00:00

The guys at the Budapest Functional Programming meetup group finally convinced me to port

  • 0

The guys at the Budapest Functional Programming meetup group finally convinced me to port Tandoori to GHC 7. Things are turning out OK, but I’m having a problem parsing .hs source files with no module M where header.

Here’s a standalone version of the code that calls GHC’s internal parser to parse source files:

module Main where

import SrcLoc
import FastString
import Outputable (showSDoc)
import Parser (parseModule)
import Lexer (unP, mkPState, ParseResult(..))
import StringBuffer (hGetStringBuffer)
import DynFlags (defaultDynFlags)
import System.Environment (getArgs)

parseMod src_filename = do 
  buf <- hGetStringBuffer src_filename
  let loc = mkSrcLoc (mkFastString src_filename) 1 0
      dflags = defaultDynFlags
  case unP Parser.parseModule (mkPState dflags buf loc) of
    POk pst rdr_module -> return rdr_module
    PFailed srcspan message -> error $ showSDoc message

main = do 
  args <- getArgs
  case args of
    [src_filename] -> parseMod src_filename
    _ -> error "Usage: parse-test filename.hs"

here’s an input file that works:

foo = 1

here’s another one that works:

module M where

foo = 1 
bar = 2

and here’s one that doesn’t:

foo = 1
bar = 2

For this one, the output of the program above is:

*** Exception: parse error on input `='

Note that I’m using GHC’s parser instead of something like haskell-src because the real code also uses the renamer from GHC.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:35:55+00:00Added an answer on May 21, 2026 at 10:35 am

    We simply prepend a module header line to the source we want to get parsed by the parser of GHC. Would this help you?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys lease help me out I think I'm close, but I'm missing something. Background
guys am having some troubles with running out of memory when displaying an animation
guys. I've been searching for an answer for my issue the whole morning, but
guys, I have iOS app, which running good on ios5.0, but on 4.3.3 it's
Guys. I use getpixel & getdata to retrieve data from the same pic.but some
Guys, I’ve been writing code for 15+ years, but managed to avoid Web Development
Guys, this probably will be fairly simple, but how am I able to find
Guys my question is very simple but I am confused about the theory behind
Guys!! I'm really enthusiastic in learning django and learnt a bit on Django-1.2 but
guys i need help on my menus. when i zoom out of page it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.