How to preserve whitespace separators?
See original GitHub issueIssue type
- Bug Report: no
- Feature Request: no
- Question: yes
- Not an issue: no
Prerequisites
- Can you reproduce the issue?: yes
- Did you search the repository issues?: yes
- Did you check the forums?: yes
- Did you perform a web search (google, yahoo, etc)?: yes
I am struggling to make PEG.js parser keep original whitespaces of the equation.
Current behavior: 2 * 5 + SUM(1, 2, 3)
[
"2",
"*",
"5",
"+",
"SUM",
"(",
[
"1",
",",
"2",
",",
"3"
],
")"
]
Desired behaviour: 2 * 5 + SUM(1, 2, 3)
[
"2",
" ",
"*",
" ",
"5",
" ",
"+",
" ",
"SUM",
"(",
[
"1",
",",
" ",
"2",
",",
" ",
"3"
],
")"
]
Grammar to copy: https://pastebin.com/zpwqT6Uw PEG.js playground https://pegjs.org/online
What am I missing?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Preserve whitespaces when using split() and join() in python
You want to use re.split() in that case, with a group: re.split(r'(\s+)', line). would return both the columns and the whitespace so you...
Read more >Python | Split String and Keep Whitespace - Finxter
Summary: To split a string and keep the delimiters/separators, you can use one of the following methods: (i) Using the regex package and...
Read more >white-space - CSS: Cascading Style Sheets - MDN Web Docs
Sequences of white space are preserved. Lines are broken at newline characters, at <br> , and as necessary to fill line boxes. pre-line....
Read more >Trimming Whitespace - Oracle Help Center
See "How the PRESERVE BLANKS Option Affects Whitespace Trimming" for details on how to prevent whitespace trimming. Table 10-5 Behavior Summary for Trimming ......
Read more >Split a String Keeping the Whitespace in JavaScript - Linux Hint
The string can be split keeping the whitespaces in JavaScript by using the “split()” method in combination with the following approaches: “join()” method....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@marek-baranowski Another gentle ping 😺
Also, I wrote a PEG.js plugin pegjs-syntactic-actions to facilitate debugging of grammars, and specifically see what characters are captured by what rule independently of the actions, which is probably your issue here as explained by @StoneCypher.
The reasoning of this plugin is: I find it is often/sometimes difficult to understand the global result when it is not what we expect, because it results from the combination of many small actions, and finding the action which behaves badly/stangely could be time-consuming. With this plugin, we see what rule captures what character, and it gives the name of the action to act on.
oh wow this is really neat actually