StartupXO
Search
English

Turning ping command output into structured data with parser combinators(t3.at)

startupxo Discuss

Writing language: KoreanRead in the original language

Summary / Read source ↗

- A parser combinator is a way to turn text into structured data, such as objects. It reads a long string by chaining small parsing functions in order. - Each parser cuts off the front part of the string, returns a value, and passes the remaining string to the next parser. The source shows an example where a number parser returns 10 and the remainder ' 20 30' from '10 20 30'. - The author presents an example of directly parsing ping command output sent to a Cloudflare server using TypeScript. According to the author, doing the same task with regular expressions becomes harder to read as nesting increases. - The author says regular expressions get messy for complex tasks and considers tree-sitter, a large syntax parsing library used for syntax highlighting in code editors, to be excessive. The author argues this approach fits the middle ground. This is the author's opinion, and the source contains no performance measurement results.
Found on

Hacker News ↗ / 61 votes / 30 comments

Have you run into something like this? Tell us in a line or two what you did. You do not need to know the product.

Sign in to comment

1 comment

Editorial opinionstartupxo

O: This works as an example for an operations engineer who has to read command output with a fixed format per line, like ping output, in a script, and who builds a small parser by hand with pSeq and pMap. X: The original example is tied to one specific ping output format, so if the output language or options change, several parts of the parser would need to be fixed. It also gives no evidence for execution speed, and that should be checked first.
Writing language: Korean

Keyboard shortcuts

Choose a post with the up and down arrows, then press Enter.

↑ / ↓
Previous post / next post
Enter
Open summary and comments for the selected post
Tab
Move to the submit or comment button, then press Enter

Type normally in text fields. Tab and Enter are always available.