ungron: accept tabs as whitespace alongside spaces#132
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
Issue tomnomnom#129 asks for ungron to accept input where the equals sign is preceded (or surrounded) by tabs instead of plain spaces, so output from tools that align statements like foo.bar = "val1"; foo.hijklm = "val2"; foo.quxz = "val3"; can be round-tripped. Update the three acceptRun(" ") whitespace-skip points in lexValue to also accept '\t', and update the lexStatement dispatch so a path followed by a tab routes to lexValue (otherwise the lexer emits typError on the tab before ever reaching lexValue). Update the grammar comment to document that whitespace is "WS ::= ' ' | '\t'". Add lex test cases for tab-only and mixed-whitespace inputs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #129.
The reporter wants ungron to handle input where statements are aligned with tabs, e.g. output from a tool that pads keys to a common column:
On master, ungronning that input fails — the tab between the path and
=makes the lexer fall throughlexStatement's switch into thetypErrordefault, because the dispatch only matches' 'and'='.This:
'\t'to thelexStatementdispatch case so a path followed by a tab routes tolexValue(the same way a space-separated path does).l.acceptRun(" ")whitespace-skip calls inlexValuetol.acceptRun(" \t")so tabs around=and before;are also consumed.Path Space* "=" Space*toPath WS* "=" WS*and definesWS ::= ' ' | '\t'.TestLextable cases: a tab-only"json\t=\t1;"and a mixed-whitespace"json.foo \t = \t \"bar\"\t;".Verified
./script/testand a manual round-trip on the reporter's example: