summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSegev Finer <segev208@gmail.com>2017-11-19 20:01:22 +0200
committerSegev Finer <segev208@gmail.com>2017-11-19 20:01:22 +0200
commit3d7c860b33fac82076d2d8e34d0a8d71fa9ec5ec (patch)
tree2245b3d622dc292207c535ab6b52290287ff2b82
parent15d42d9d17b41cac7c0937bc858ec9407f0c2d03 (diff)
downloadply-3d7c860b33fac82076d2d8e34d0a8d71fa9ec5ec.tar.gz
The find_column example returns the column off by +1 for every line but the first.
This is a simplified version of it that works by calculating the 0-based index of the first character in the line, and than calculating the difference between it and the token position + 1.
-rw-r--r--doc/ply.html9
1 files changed, 3 insertions, 6 deletions
diff --git a/doc/ply.html b/doc/ply.html
index 30905e2..b35ba44 100644
--- a/doc/ply.html
+++ b/doc/ply.html
@@ -558,15 +558,12 @@ column information as a separate step. For instance, just count backwards unti
<blockquote>
<pre>
-# Compute column.
+# Compute column.
# input is the input text string
# token is a token instance
def find_column(input, token):
- last_cr = input.rfind('\n', 0, token.lexpos)
- if last_cr < 0:
- last_cr = 0
- column = (token.lexpos - last_cr) + 1
- return column
+ line_start = input.rfind('\n', 0, token.lexpos) + 1
+ return (token.lexpos - line_start) + 1
</pre>
</blockquote>