Comments (5)
Yes, of cause I also want to support over-line, "island" and multi-line comments.
The main difficulty I meet, is that there seems no good way to describe which does a comment belong to (while parsing or stringifying). The commens could be too whimsical.
Think about this:
# overall
# a
# a.a
a.a = 1
# a.b
a.b.x = 1
a.b.y = 1
#a.b.z = 1
How would you treat that?
If we just remain the comments, without correct belonging relationship which most likely meeting the writer's intention, then it rarely help, and will break the compatibility when we finally find a good enough rule in the future.
I'm glad to discuss any possible idea, welcome to feedback.
from j-toml.
Yeah, totally understood. The island comments seem to be the hardest to handle here, but I think that you could create a few rules which would capture most situations.
For example, today you only capture inline comments, and drop the rest.
You could also enable a feature where single / multi-line comments are attached to the nearest TOML line below it, and the rest would be dropped just as before.
So using your example above, we would get:
{
a: {
a: '1', [commentAbove('a')]: ' a \n a.a',
b: {
x: '1', [commentAbove('x')]: ' a.b',
y: '1'
}
}
}
At least in this case, we capture what is arguably the most common kind of comment in the way that is most normally expected. Here we still drop the island comment, and the tricky comment at the end of the file, but this would be a large step forward from what is available today.
And, at the end, I believe more rules like this could be configurable as xOptions, allowing the user to play with the rules for their desired behavior.
from j-toml.
I think I need to confirm your final need about comment.
Firstly, @ltd/j-toml
support any valid comment parsing; problem is how to remain it when stringify.
Here are two main cases to stringify a TOML document with comments: 1) a table parsed from existing file (which means you only want to change some value, and want to remain the comments without changes); 2) a brand new table with new structure, or change existing comments info.
If only 1st case is usually needed, then the mechanisms can be in black box; if both, then here must be a good enough api, and I need to design it systematically.
from j-toml.
# overall
# a
# a.a
a.a = 1
# a.b
a.b.x = 1
a.b.y = 1
#a.b.z = 1
{
[commentsInThis]: [ [' overall'], [' a',' a.a'], 'a', ['a.b.z = 1'] ],
a: {
[commentsInThis]: [ 'a', [' a.b'], 'b' ],
a: 1,
b: {
x: 1,
y: 1,
},
},
}
Does this look good enough? (Won't distinguish over-line comment and "island" comment, which can be designed, but I found it's easy to see mixing up in your samples.)
from j-toml.
@LongTengDao first, thank you for your time to discuss this with me.
I think this might work. As I understand this syntax, you are keeping track of the comments and where they are relative to certain keys. In this case a
and b
in those commentsInThis
refer to the location of the key, and then the comments exist positionally around them.
Ultimately, I would need to test this logic on some of the files by doing parse -> stringify
to see the diff, but yes, I think this would already be a big improvement.
from j-toml.
Related Issues (20)
- Safari crashes with SyntaxError HOT 1
- How can I define custom typescript type for parsed data? HOT 1
- [feature?] Multiline in stringify HOT 4
- [Feature] Option to use double quotes for strings HOT 1
- Section equivalent for arrays? HOT 4
- Logical nullish assignment (??=) is not supported in Node <15 HOT 1
- Controlling spaces in list output HOT 6
- Configure double quotes or single quotes output HOT 5
- Stringify of the same JSON created via parse does not produce a valid TOML back HOT 6
- Can't Parse a Stringified example. HOT 2
- bug: npm bundle is invalid with version 1.35.0 HOT 3
- Cannot use with Cypress - requires es2019 or lower? HOT 2
- NULL prototype thing causes trouble HOT 1
- Is there a simple demo code to provide pretty format? HOT 2
- Maintain "style" HOT 2
- 使用的时候遇到了一个报错 HOT 1
- https://www.longtengdao.com/ is down HOT 1
- v1.16.0 breaks bundled javascript HOT 5
- use in browser HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from j-toml.