Skip to content
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

Markdown: allow to end URL with balanced parenthesis #18321

Merged
merged 4 commits into from
Jun 23, 2021

Conversation

a-mr
Copy link
Contributor

@a-mr a-mr commented Jun 21, 2021

Mostly fixes bug 24 from #17340 (except escaping).

cc @timotheecour

@@ -1246,15 +1246,44 @@ proc isUrl(p: RstParser, i: int): bool =
p.tok[i+3].kind == tkWord and
p.tok[i].symbol in ["http", "https", "ftp", "telnet", "file"]

proc checkParen(token: Token, parensStack: var seq[char]): bool {.inline.} =
Copy link
Member

Choose a reason for hiding this comment

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

completely optional: can you split this into a more general reusable proc and then call it, and then in future work we can move this reusable proc to strbasics or strutils? (similar to https://dlang.org/library/std/algorithm/searching/balanced_parens.html, and same functionality as what you have)

proc balancedParens(a: openArray[char], parensStack: var seq[char]): bool =
  # xxx in future work, move to stdlib
proc checkParen(token: Token, parensStack: var seq[char]): bool {.inline.} =
  call balancedParens somehow

Copy link
Contributor Author

@a-mr a-mr Jun 21, 2021

Choose a reason for hiding this comment

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

The idea of balancedParens is very different: it check whether parens are balanced or not.

checkParen does not always forbid unbalanced parens: e.g. ([) and (]) are legal, and checkParen will return 3 values False,False,True in both cases for 3 tokens.

a-mr and others added 2 commits June 22, 2021 01:09
Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
if c in {'(', '[', '{'}: # push
parensStack.add c
elif c in {')', ']', '}'}: # try pop
if parensStack.len > 0:
Copy link
Member

Choose a reason for hiding this comment

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

Pointless if statement, if the collection is empty the loop will iterate 0 times.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed, thanks.

@Araq Araq merged commit 9c43f05 into nim-lang:devel Jun 23, 2021
@a-mr a-mr mentioned this pull request Jun 25, 2021
28 tasks
PMunch pushed a commit to PMunch/Nim that referenced this pull request Mar 28, 2022
* Markdown: allow to end URL with balanced parenthesis

* Update lib/packages/docutils/rst.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* apply suggestion

* remove unnecessary if

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants