Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Breaking Up with Google Play: Why Conversations Is Now Free (gultsch.de)
    75comments
  2. Understanding the Impact of LLM Watermarking on AI Agent Behavior (lasso.security)
    —discuss
  3. Fifteen years later, the Apple Cards origin story (lexontech.org)
    12comments
  4. Revealing the details of how OpenAI agents hacked Hugging Face (swarmtraces.org)
    347comments
  5. ASML currently sells no chipmaking machines in Europe, executive says (nltimes.nl)
    35comments
  6. Floci: Locally emulating any cloud service (floci.io)
    9comments
  7. CEO of Mistral: AI is software. It can be controlled (lemonde.fr)
    12comments
  8. We're gonna need a lot more mathematicians (terrytao.wordpress.com)
    267comments
  9. Plan mode is dead (aymannadeem.com)
    351comments
  10. Ollaya – Ollama for open-source, Jev-style decision models (ollaya.dev)
    125comments
  11. Is your Postgres migration safe or not safe? (safenotsafe.dev)
    16comments
  12. A single function Jev-like wrapper for LLMs, including vision models (allanrbo.blogspot.com)
    29comments
  13. Show HN: Jev Plays Pokémon Red (jev-pokemon.vercel.app)
    90comments
  14. Parsing Expression Grammar vs. Regexes: Building Org Parser in Lisp, Export HTML (jointhefreeworld.org)
    9comments
  15. What even is an OS now? (sockpuppet.org)
    309comments
  16. 16GB iPod Nano 3G Upgrade (tuckerosman.com)
    5comments
  17. Modern Object Pascal Introduction for Programmers – Castle Game Engine (castle-engine.io)
    1comments
  18. Calculating atmospheric drag on satellites for a Cubesat [pdf] (osti.gov)
    4comments
  19. Gravity seems holographic. What does that mean for reality? (quantamagazine.org)
    182comments
  20. Ask HN: Who's still keeping a DOS machine up because the business depends on it?
    156comments
  21. Scientists build most accurate atomic clock (phys.org)
    13comments
  22. The Murky History of Soviet-Born Tetris (mitpress.mit.edu)
    15comments
  23. Jury finds Facebook liable for deceiving users in Cambridge Analytica case (cbsnews.com)
    69comments
  24. One Month Without AI (bustikiller.com)
    106comments
  25. The Copilot+ PC brand is dead (windowscentral.com)
    12comments
  26. HomelabFest will be in St. Louis in September 2027 (homelabfest.org)
    30comments
  27. Fourier Analysis: Drawing Llamas with Circles (adekau.github.io)
    6comments
  28. The far side of the Moon provides clues to a previous magnetic field (ethz.ch)
    1comments
  29. Excel now supports multiple values in a single cell (techcommunity.microsoft.com)
    150comments
  30. Lab on a Contact Lens Can Measure Stress Through Serotonin (ieee.org)
    18comments

Parsing Expression Grammar vs. Regexes: Building Org Parser in Lisp, Export HTML

46 pointsby 2d agojointhefreeworld.org
9 comments
2h agoHN ↗

Ha, that's interesting.

I started exactly such a project, for org syntax, a while ago. Didn't get very far though because it seems to me that things in org cannot be parsed and understood in one go. For example the TODO keywords can be specified at the top of an org file and then would influence how headings in the document are understood. This cannot be done with merely a PEG.

Another tricky point is nested inline markup. Bold inside italic? Verbatim inside bold, inside italic? And so on. Would be great to support all meaningful combinations via recursive rules. Org has many inline markup things. Even programming language specific inline markup elements.

Another issue is, that Guile's PEG library, when using the non-string form of grammar rules, does not allow mutually recursive grammar rules, due to being buggy (in that way it is not excellent, but in other ways it is!). One has to use the string form or rules, which makes it a lot less nice to use, unfortunately. I hope that will be fixed at some point, because I like the library except for that. And it is in the standard lib, no need to install any dependencies. Like to use it for AoC puzzle inputs for example.

Will be interesting to read how far they got.

EDIT: Also it's going to be great to have an actual grammar based parser for org. This will ease creating one for other tools, like for example parsers of readmes in repos on git hosters.

35m agoHN ↗

Aha! Interesting to hear you were going in the same direction. There are indeed quite some tricky situations to handle since Org (and Markdown) are complex in many ways.

the approach I am taking is to combine the PEG with a step of AST processing in order to then produce a correct and descriptive tree structure (for later rendering).

I do agree the Guile library has some spots to improve but honestly, I am already enjoying it so much, and it's far better for the Lisper in me than other things I've tried. I also find S-expressions much more comprehensible and self-documenting.

Looking forward to seeing what you do with it :)

I am indeed hoping that this library is useful for more people and that perhaps things like Haunt blog generator can use it (and other interesting uses)

As for nested markup, and nested lists it has been tricky, but so far I've really promising results:

(assert-equal #:got (inline-org->html (inline-org->ast "*bold with /italic/*")) #:expect "<strong>bold with <em>italic</em></strong>")

23m agoHN ↗

I had done some work in this direction in my org parser for racket [0]. That work is stalled at the moment (though I still intend to come back to it), but many of the interactions between org and traditional formal grammars have been explored there.

0. https://github.com/tgbugs/laundry

18m agoHN ↗

Some really impressive work there! thanks for sharing!

1h agoHN ↗

Due to personal failings, my main takeaway from this piece is that Regex is under attack -- I will not stand by as CS theory blorbo is maligned so! Of course there's an undeniable elegance to Lisp in all cases, and seeing Lisp in use today feels like seeing someone unsheathe Valerian steel. But still, the fact remains: regex is vastly underappreciated by the standard engineer, largely because a few of the most common implementations drop some of the most important features. Namely, composition.

I have no easy way to express this other than to plug my recently-released OSS, namely a library I wrote to implement "RegexStores" in Python[1] to compile complex, composed regexes upfront from a custom DSL. I'll link a representative usecase below[2], which I think drives home two things:

1. Regex deserves to be composed using named groups, at the very least! Most people aren't even aware that you can define named groups upfront and then reference them by name throughout, even 'capturing' them multiple times in one match.[3] Even when you do write patterns that use subroutines, the ergonomics of actually accessing, say, the three matched substrings for the `username` group in your single match is finnicky at best (without some magic[4]...).

2. Regex needs high quality syntax highlighting. The linked page is hopefully skimmable in a python sense, but trying to decipher the individual patterns in GitLab would be tough even for me, and I wrote the darn things. It's kinda awkwardly sized, but this screenshot drives home the basics of the point -- note the bright yellow named groups, which are basically subroutine invocations as discussed above: https://i.imgur.com/NllqM6S.png

Sorry to quasihijack the thread. Hopefully the fact that all this stuff has never been announced or published anywhere is proof enough of my good intentions -- that is, to defend my one n' only :)

Most of this functionality was conceived and implemented in a rage after I found out that Rust's main (only?) regex library avoids the possibility of infinite loops by just dropping half the features of the language, so excuse the jank. Even the halting problem seems solvable when you're willing to make moves like that!

[1]: https://gitlab.com/doering-ai/libs/basis/#regular-expression...

[2]: https://gitlab.com/doering-ai/apps/wiki-parse/-/blob/main/wi...

[3]: I wrote up an overview of advanced regexes in Python a while back, but was hit by the agential engineering bus before I had the time to polish and release it. Some may find it interesting, if overly long -- the aforementioned subroutines are covered under `3.1`, and repeated captures under `6.2`: https://gitlab.com/doering-ai/libs/basis/-/blob/main/docs/re...

[4]: https://gitlab.com/doering-ai/libs/basis/-/blob/main/my/rege...

42m agoHN ↗

I think you make a great point in highlighting the value of Regex. I don't want to undermine it at all, although some use-cases are just not a good fit for it (even if you can horseshoe things). I think a higher-level abstraction for regex is super welcome, and I quite admire what you are doing there, thanks a lot for sharing. I do think regex's indeed quite a lot more difficult to grasp when complexity rises compared to grammars or other approaches.

1h agoHN ↗

“Org” in this context is emacs org mode. Seems odd in this day and age that anyone would see hierarchical text format and think “regex”!

40m agoHN ↗

Indeed you make a good point. My naive self thought it could work out, but actually the more you zoom out, the more tree-structures you see in many formats. And in my opinion, then it's time to sheathe Valyrian Steel of Lisp, IMHO the language to rule them all when it comes to working with tree based structures (Org, HTML, SXML, many more)

13m agoHN ↗

Indeed. Regexes are _regular_, which is non hierarchical by definition.

The two are useful for different layers of abstraction: regex is for lexing and PEG is for parsing.

Speaking of the Chomsky hierarchy, last I checked, it is still unproven whether or not PEGs can parse all context free languages. Intuitively, they're _probably_ weaker than CFGs, but no one has yet provided a counter example.