GithubHelp home page GithubHelp logo

Comments (6)

recursion-ninja avatar recursion-ninja commented on May 30, 2024

Couldn't you get the list of error messages on a failure, or are you entirely reliant on the stringified results of show :: ParseError -> String?

Example:

case result of
    Left  x -> f $ errorMessages x
    Right y -> g y
    where 
      f = undefined -- Your code to operate on the errors
      g = undefined -- Your code to operate on successful parse

from megaparsec.

Toxaris avatar Toxaris commented on May 30, 2024

Yes, that's what I'm doing. But if you look into how to implement f, it turns out to be unnecessarily complicated. I need to write something like this:

Left err -> 
  let pos = errorPos err
      name = sourceName pos
      line = sourceLine pos
      column = sourceColumn pos
      messages = showErrorMessages
                   "or" "unknown parse error" "expecting"
                   "unexpected" "end of input"
                   (errorMessages err)
  in intercalate ":" [name, show line, show column, "Syntax Error"] ++
     (unlines $ map ("  " ++) $ lines $ message)

That's relatively complicated for such a simple task, and I have to lookup how to call showErrorMessage in the sources as well as figure out the API for source positions.

from megaparsec.

mrkkrp avatar mrkkrp commented on May 30, 2024

@Toxaris, rendering of error messages (i.e. everything except for the first line with file name, line number, and column number) is done with showMessages function, which is hopefully more handy than Parsec's showErrorMessages. Its type looks like this:

showMessages :: [Message] -> String

When I first saw showErrorMessages it made me choke. Absolutely naïve idea of passing words into this function in hope to make it “international”. Has it even occurred to the author of Parsec that translation into different language is not done by one-to-one word substitution? Even if we consider only punctuation, list separated by commas with “or” / “and” at the end looks differently in different languages. I only speak three languages: Russian, English, and French and it's different in them all (punctuation); I can imagine this approach is even less applicable for eastern languages like Arabic and Japanese. So, let's focus on English alone for now.


What you're asking is worth consideration. That part about better default representation is. I don't see how I can make easier custom rendering of error messages. If you want it, you'll obviously have to write some Haskell.

Although I use Emacs on daily basis I don't know whether it expects quoted file names when they contain space…

from megaparsec.

Toxaris avatar Toxaris commented on May 30, 2024

Oh showMessages sounds like a nice improvement indeed. Sorry for not checking out what you already improved before posting here.

A better default would still help me. Maybe there is a standard format that is understood by many tools, not just emacs?

from megaparsec.

mrkkrp avatar mrkkrp commented on May 30, 2024

@Toxaris, The format has been changed in b062a39, the new default should be satisfactory.

from megaparsec.

Toxaris avatar Toxaris commented on May 30, 2024

thanks 👍

from megaparsec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.