From fd0c4b4c7a817c6ad35d8fe651a4ccbd81abf0f2 Mon Sep 17 00:00:00 2001 From: Albert Hofkamp Date: Mon, 3 Feb 2020 09:19:10 +0100 Subject: [PATCH 1/2] Fix find_column() documentation comment. --- docs/sly.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sly.rst b/docs/sly.rst index 8ee47a0..d09cb30 100644 --- a/docs/sly.rst +++ b/docs/sly.rst @@ -301,7 +301,7 @@ column information as a separate step. For instance, you can search backwards until you reach the previous newline:: # Compute column. - # input is the input text string + # text is the input text string # token is a token instance def find_column(text, token): last_cr = text.rfind('\n', 0, token.index) From 1bdec83336174d42d51d7c62cd66d684a69ebebe Mon Sep 17 00:00:00 2001 From: Albert Hofkamp Date: Mon, 3 Feb 2020 09:23:44 +0100 Subject: [PATCH 2/2] Fix off-by-one column computation for all but first line. --- docs/sly.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/sly.rst b/docs/sly.rst index d09cb30..4a2affe 100644 --- a/docs/sly.rst +++ b/docs/sly.rst @@ -305,9 +305,7 @@ backwards until you reach the previous newline:: # token is a token instance def find_column(text, token): last_cr = text.rfind('\n', 0, token.index) - if last_cr < 0: - last_cr = 0 - column = (token.index - last_cr) + 1 + column = token.index - last_cr return column Since column information is often only useful in the context of error