summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Merry <dev@randomguy3.me.uk>2013-03-24 15:21:23 +0000
committerAlex Merry <dev@randomguy3.me.uk>2013-03-24 15:21:23 +0000
commit9e47962ddd0dc9f6874b7ca50874d444ed81c848 (patch)
tree605ce3e6abc03e5348fc35a2c186df3622c818f4
parent9afd11b2c7bd6ac5b964555aa539572250bcef4c (diff)
Make first/last_column count character offsets
This means that tabs don't get treated specially. No-one can seem to agree how many spaces a tab should be, and the first thing we actually ended up doing was to undo the extra tab counting.
-rw-r--r--tikzit/src/common/TikzGraphAssembler.m11
-rw-r--r--tikzit/src/common/tikzlexer.lm15
2 files changed, 8 insertions, 18 deletions
diff --git a/tikzit/src/common/TikzGraphAssembler.m b/tikzit/src/common/TikzGraphAssembler.m
index 75fca1c..b2c372a 100644
--- a/tikzit/src/common/TikzGraphAssembler.m
+++ b/tikzit/src/common/TikzGraphAssembler.m
@@ -167,17 +167,6 @@
size_t token_offset = yylloc->first_column - 1;
size_t token_len = ((last_line_start - first_line_start) + yylloc->last_column) - token_offset;
- // damn you, tabs!
- // we need to convert "column offsets" into "character/byte offsets"
- for (int i = 0; i < MIN(token_offset + token_len,context_len); ++i) {
- if (*(first_line_start + i) == '\t') {
- if (i < token_offset)
- token_offset -= 7;
- else
- token_len -= 7;
- }
- }
-
if (token_offset + token_len > context_len) {
// error position state is corrupted
NSLog(@"Got bad error state for error \"%s\": start(%i,%i), end(%i,%i)\n context_len = %d; token_offset = %d; token_len = %d",
diff --git a/tikzit/src/common/tikzlexer.lm b/tikzit/src/common/tikzlexer.lm
index 4e675ad..2956a8b 100644
--- a/tikzit/src/common/tikzlexer.lm
+++ b/tikzit/src/common/tikzlexer.lm
@@ -44,17 +44,18 @@ FLOAT \-?[0-9]*(\.[0-9]+)?
%%
-<INITIAL,xcoord,ycoord,props,noderef>\n {
+ /* whitespace is ignored, except for position counting; we don't
+ count formfeed and vtab as whitespace, because it's not obvious
+ how they should be dealt with and no-one actually uses them */
+
+ /* lex will take the longest-matching string */
+<INITIAL,xcoord,ycoord,props,noderef>\r\n|\r|\n {
yylloc->first_line += 1;
yylloc->last_line = yylloc->first_line;
yylloc->first_column = yylloc->last_column = 0;
}
-<INITIAL,xcoord,ycoord,props,noderef>[ ]+ { } /* ignore whitespace */;
-<INITIAL,xcoord,ycoord,props,noderef>[\t]+ {
- // tab = 8 columns
- // note that we have already adjusted by yyleng at this point
- yylloc->last_column += 7*yyleng;
-}
+<INITIAL,xcoord,ycoord,props,noderef>[\t ]+ { }
+
\\begin\{tikzpicture\} { return BEGIN_TIKZPICTURE_CMD; }
\\end\{tikzpicture\} { return END_TIKZPICTURE_CMD; }
\\begin\{pgfonlayer\} { return BEGIN_PGFONLAYER_CMD; }