techhub.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A hub primarily for passionate technologists, but everyone is welcome

Administered by:

Server stats:

4.7K
active users

#parser

1 post1 participant1 post today

I finally got around to wrapping up and publishing a first version of my #Rust crate ts-typed-ast. It's a crate inspired by Rowan that automatically generates a typed AST from a tree-sitter grammar. You can find it here: crates.io/crates/ts-typed-ast

It works similarly to Rowan and Swift's libsyntax. tree-sitter provides the green nodes, while this crate generates the red nodes.

I've used it a few times already, to prototype various toy programming languages. You write a grammar in tree-sitter, and then either evaluate the ts-typed-ast tree directly, or convert it to some other IR.

Using tree-sitter as the parser generator for a toy project is pretty nice. You get a powerful, declarative way to create a parser, and at the same time you benefit from the whole tree-sitter ecosystem. Things like incremental parsing, syntax highlighting, structural editing, and formatting with Topiary.

Main downside is that tree-sitter does not (yet) offer good error reporting and recovery, so when parsing fails it's often in dramatic, unhelpful ways. Not a big issue for experimenting, which is what this crate is for. Production-ready languages probably need bespoke parsers anyway.

crates.iocrates.io: Rust Package Registry

To the #Rust #rustlang community: I once started to write a #compiler / #parser with #nom #crate. However I had some struggles with it of how to provide **multiple** errors with line+column indicators for a parsed context.
Now I read a tiny bit about #syn and #chumsky 👀
Are they the right crates for me? Are there others?
I do not parse rust-code, but a completely custom language (similar to pugjs)

(Boost for reach 🙏)

Trying to improve my Tree-sitter #parser for my new #esolang Bespoke, so that it recognizes things like commands and comments.

Trouble is, I can't figure out how best to handle block comments. And when I tried a workaround...it crashed my computer.

This is gonna be tough.

In Bespoke, words are first turned into digits, then the digits are turned into commands.

Block comments start and end with 0...0, where ... is an arbitrary digit sequence.

I need the digits before I can detect the commands, so I'm unsure how to handle this with Tree-sitter.

輸入:
@foo
{@foo|@bar|12\|}

輸出:
Any[Main.uahgi.Parsing.ID("foo"), "\n", 
Main.uahgi.Parsing.SEQ(Any[Main.uahgi.Parsing.ELE(Any[Main.uahgi.Parsing.ID("foo")]), 
Main.uahgi.Parsing.ELE(Any[Main.uahgi.Parsing.ID("bar")]), Main.uahgi.Parsing.ELE(Any["1", "2", 
Main.uahgi.Parsing.ESC_CHAR("|")])])]```

Parsec這樣還是很不錯的。(參考:
https://repo.kianting.info/yoxem/uahgi/src/branch/main/src/parsing.jl#Julia #Parser #ParserCombinator
Tan Kian-ting's Repos: 個人的程式碼倉庫uahgi/src/parsing.jl at mainuahgi - another experimential typesetting tool