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 7884595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:50:32+00:00 2026-06-03T04:50:32+00:00

I want to write a simple parser for a subset of Jade , generating

  • 0

I want to write a simple parser for a subset of Jade, generating some XmlHtml for further processing.

The parser is quite simple, but as often with Parsec, a bit long. Since I don’t know if I am allowed to make such long code posts, I have the full working example here.

I’ve dabbled with Parsec before, but rarely successfully. Right now, I don’t quite understand why it seems to swallow following lines. For example, the jade input of

.foo.bar
    | Foo
    | Bar
    | Baz

tested with parseTest tag txt, returns this:

Element {elementTag = "div", elementAttrs = [("class","foo bar")], elementChildren = [TextNode "Foo"]}

My parser seems to be able to deal with any kind of nesting, but never more than one line. What did I miss?

  • 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-06-03T04:50:33+00:00Added an answer on June 3, 2026 at 4:50 am

    If Parsec cannot match the remaining input, it will stop parsing at that point and simply ignore that input. Here, the problem is that after having parsed a tag, you don’t consume the whitespace in the beginning of the line before the next tag, so Parsec cannot parse the remaining input and bails. (There might also be other issues, I can’t test the code right now)

    There are many ways of adding something that consumes the spaces, but I am not familiar with Jade so I cannot tell you which way is the “correct” way (I don’t know how the indentation syntax works) but just adding whiteSpace somewhere at the end of tag should do it.

    By the way, you should consider splitting up your parser into a Lexer and Parser. The Lexer produces a token stream like [Ident "bind", OpenParen, Ident "tag", Equals, StringLiteral "longname", ..., Indentation 1, ...] and the parser parses that token stream (Yes, Parsec can parse lists of anything). I think that it would make your job easier/less confusing.

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

Sidebar

Related Questions

I try to write a simple Markdown parser in JavaScript. Therefore I want to
I am currently trying to write a simple parser for some XMI files (Generated
I want write a simple query which will fetch data from a table (which
I want to write simple script to copy/backup directory then remove on server startup.
I'm new to Java programming. I want to write simple Java network protocol. I
I want to write a simple chat application (for test use). The users and
I want to write a simple regular expression in Python that extracts a number
I want to write a simple applet to put in a tray. Let's say
I want to write a simple web framework myself using WSGI, Python. I am
I want to write a simple DSL in C#. Nothing too complicated. I'm looking

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.