Skip to content

Parsing while preserving all whitespace (in an ergonomic fashion) #142

Answered by renggli
amake asked this question in Q&A
Discussion options

You must be logged in to vote

This is a great question and an interesting topic. I think you captured the two approaches very well:

  • I agree that retaining every piece of whitespace is probably the easiest. For example, this is what this XML parser selectively does in the parts that matter (between tags, there is a feature request to also do it between attributes). This makes it trivial to support modifications and to serialize the unmodified parts to an identical output.

  • As you mention, the other way is to store the offsets in the AST. This is what this Smalltalk Parser does. Instead of capturing the position manually using the position() parser, it uses the token() parser, which wraps all primitive values into a T…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by renggli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants