Line objects should maybe have a char() function equivalent to InlineContext.char() #6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Preface: This is a really minor "issue".
Currently, line objects implement similar methods to
InlineContextobjects but notably do not have achar()function, which feels disjointed / mildly disorientating (to me), considering the similarity of the two interfaces.I would think this function would be document-relative, just like
InlineContext.char().To demonstrate my use-case:
This function is a handy helper function to check if an array of specified code points can be found at a chosen position within the content of a
LineorInlineContextobject. Currently, this function behaves differently depending on whether you pass aLineobject or if you pass aInlineContextobject. With lines, the position is relative, and with inline, the position is document-relative.I believe the reason why this isn't a thing is because
Lineis agnostic to its position within the document, so I understand if you don't want to implement this feature. I will say that, at least for me, the most common usage ofLineis in the context of block parsers. Unless I am mistaken, in that context you will always havecx.lineStartavailable to you. Maybe a separateLineobject type that includes document-relative position info and helper methods could be handy for block parsers?And with this issue: I am done with my spam. Again, great work on this! It's awesome and I'm somehow having a lot of fun re-implementing my grammar for a third time.
I agree that the dealing with multiple coordinate systems (document, line, after-
line.pos) is awkward. It was even worse in the inline parsers, which is why I added the convenience functions there. The thing is that line-level logic often needs to deal with actual line structure, where offset into the line is a lot more meaningful than offset into the document (when dealing with indentation and such). Since I didn't really run into a lot of trouble writing this logic, I decided against trying to abstract that away for the time being.Then clearly
InlineContextandLinehave different interfaces and can't be used interchangeably via polymorphic calls. I agree with marjnh, that it should be made similiar just to match abstractions; where-as the real use cases are different.Thanks for @marijnh !