Parsing a Markdown-like syntax into a document tree #243
SwiftDevJournal
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm exploring using the swift-parsing framework to write a parser for a language with Markdown-like syntax. I want to take a string and return a document tree (abstract syntax tree) for the text. To keep things simple at the start, i'm focusing on headings and paragraphs. I have the following code for the document tree:
I know what I have to do to parse a heading.
#
characters.This should return a heading node with one child: a text node with the heading title.
Parsing a paragraph entails Step 3 in the header parsing flow, returning a paragraph node with one child: a text node with the paragraph text.
To parse the text, go through each paragraph. Check if it's a heading. If so, parse the heading. If not, parse the paragraph. Accumulate the document tree nodes into an array.
I have an initial version of the code using swift-parsing.
To move ahead on the parser, I have two questions:
#
characters that were read so I can set the heading level?Beta Was this translation helpful? Give feedback.
All reactions