Skip to content

Add positional information, escape \r\n #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

muraken720
Copy link

Please merge if you like it.

I want to check position information.
And if a sentence contains '\r' or '\n', inspect's tree output is broken. so I want to avoid it.

@wooorm
Copy link
Member

wooorm commented Oct 1, 2015

Nice work! Could you squash the branch?

@wooorm
Copy link
Member

wooorm commented Oct 1, 2015

I just check your code out, and now I’m thinking, right now it looks like this:

RootNode[1] (start={l:1, c:1, o:0}, end={l:1, c:36, o:35})
└─ ParagraphNode[3] (start={l:1, c:1, o:0}, end={l:1, c:36, o:35})

But this is more compact:

RootNode[1] (1:1-1:36, 0-35)
└─ ParagraphNode[3] (1:1-1:36, 0-35)

I think the latter looks really nice, especially the line-column part, which is pretty standard. I’m not so sure about the offset (especially because it’s optional), so the comma might be a bit weird!

@muraken720
Copy link
Author

I agree with your compact idea.

I try to squash. but it looks no good.

May I close this pull request and retry to new pull request?

@wooorm
Copy link
Member

wooorm commented Oct 2, 2015

The article I posted before should be able to help you, what you can also do, is “uncommit” the three commits, and then git commit --amend --no-edit (this merges all commits into your first commit). Then, push with --force to your branch!

To come back to your question, I prefer this PR over others though!

@muraken720
Copy link
Author

How about it?

And I changed code by compact format.

@wooorm
Copy link
Member

wooorm commented Oct 2, 2015

I like it a lot, however I’m going to refactor a little bit and for some reason a commit by me, with your changes also came through, so I cannot rebase (meaning, it won't show your name/face next to the commit).

But I’m very grateful for the help 😄

@muraken720
Copy link
Author

Thanks a lot! Never mind.

@@ -96,7 +96,13 @@ function formatNode(node) {
if (node.children && node.children.length) {
log += dim('[') + yellow(node.children.length) + dim(']');
} else {
log += dim(': \'') + green(node.value) + dim('\'');
log += dim(': ') + green(JSON.stringify(node.value));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muraken720 Why did you opt to use JSON.stringify here versus the previous system? I really liked the single quotes, and I don’t think node.value can/should be non-string!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh just noticed that it has to do with \n and \r!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var paragraph = 'Some simple text.\nOther �$B!H�(Bsentence�$B!I�(B.';

In this case,
I want to show '\n' value.

Easy way is to use JSON.stringfy() .

I like single quote too.
but I could not output '\n' instead of "\n".

2015/10/03 7:34�$B!"�(BTitus Wormer notifications@github.com �$B$N%a%C%;!<%8�(B:

In index.js:

@@ -96,7 +96,13 @@ function formatNode(node) {
if (node.children && node.children.length) {
log += dim('[') + yellow(node.children.length) + dim(']');
} else {

  •    log += dim(': \'') + green(node.value) + dim('\'');
    
  •    log += dim(': ') + green(JSON.stringify(node.value));
    
    Oh just noticed that it has to do with \n and \r!

�$B!=�(B
Reply to this email directly or view it on GitHub.

@wooorm wooorm closed this in fc266f3 Oct 3, 2015
@wooorm
Copy link
Member

wooorm commented Oct 3, 2015

Thanks @muraken720 for the work, this was release in 2.0.0.

@wooorm wooorm added ⛵️ status/released 🗄 area/interface This affects the public interface 🦋 type/enhancement This is great to have 🧑 semver/major This is a change labels Aug 11, 2019
@wooorm wooorm changed the title add position infomation. escape \r \n. Add positional information, escape \r\n Aug 11, 2019
@wooorm wooorm added the 💪 phase/solved Post is done label Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧑 semver/major This is a change 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

2 participants