-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
WIP: use dedent for de-indentation in lexer, fix #15184 #16699
Conversation
bummer: there is no dedent in csources, because csources is of version 0.20.0. It worked so well in my local copy :-( |
@a-mr in strutils, change as follows: since (1, 3):
func indentation*(s: string): Natural = ...
func dedent*(s: string, count: Natural = indentation(s)): string {.rtl,
extern: "nsuDedent".} = ... after that you're hitting timotheecour#521 proc dedent(a: string): string =
# pending https://github.com/timotheecour/Nim/issues/521
let b = a
let i = indentation(b)
dedent(a, i) then this works |
Why can't we fix the existing logic instead... |
To avoid duplicating code. Code reuse is good. |
@Araq , @timotheecour . Bringing into consideration another edge case. Assume we really want to start comment from a quote: proc f* =
## Quote
## Paragraph
discard Current logic sets indentation to 0 at "Quote", then it will re-adapt indentation to 0 again at "Paragraph", so we get
To make indentation right in such cases we need to look ahead through the entire string and find non-whitespace-character with minimal indentation. It's what dedent does. So we are back to re-inventing dedent. I think, we can avoid the workarounds proposed by timotheecours and just copy a (short, few lines long) implementation of Alternative solutionYou can specify that zero or one space in any comment correspond to zero indentation, then grows linearly. This solution avoids to do any de-indentation, except the trivial crop that can be done on each line separately
-> " x", etc.
The side effect of such decision is that there will appear a block quote if e.g. 2 spaces are present after "#"
|
So do it in a way that doesn't slow down things. Also: I avoid helpers from the stdlib nowadays because you never know if it gets "fixed" in an incompatible manner because it's "inconsistent with Python/Unix/some other proc somewhere else". |
When first line in a doc comment is empty, lexer.nim memorizes indentation at it and keeps one space on the following lines:
tokenized as comment tok.literal =
(with space before x) which is considered a block quote in RST.