working
[pspp] / src / language / lexer / lexer.c
index cf40dcbe6d0ee76f53a16dbf110c8b34d201d5c1..3c46fa70ebb787689a81244559ec2477f874eec4 100644 (file)
@@ -1101,6 +1101,35 @@ lex_next_tokss (const struct lexer *lexer, int n)
   return lex_next (lexer, n)->string;
 }
 
+int
+lex_ofs (const struct lexer *lexer)
+{
+  struct lex_source *src = lex_source__ (lexer);
+  return src ? src->parse_ofs : 0;
+}
+
+const struct token *
+lex_ofs_token (const struct lexer *lexer_, int ofs)
+{
+  struct lexer *lexer = CONST_CAST (struct lexer *, lexer_);
+  struct lex_source *src = lex_source__ (lexer);
+
+  if (src != NULL)
+    return &lex_source_next__ (src, ofs - src->parse_ofs)->token;
+  else
+    {
+      static const struct token stop_token = { .type = T_STOP };
+      return &stop_token;
+    }
+}
+
+struct msg_location *
+lex_ofs_location (const struct lexer *lexer, int ofs0, int ofs1)
+{
+  int ofs = lex_ofs (lexer);
+  return lex_get_location (lexer, ofs0 - ofs, ofs1 - ofs);
+}
+
 /* Returns the text of the syntax in tokens N0 ahead of the current one,
    through N1 ahead of the current one, inclusive.  (For example, if N0 and N1
    are both zero, this requests the syntax for the current token.)  The caller
@@ -1376,7 +1405,7 @@ lex_get_lines (const struct lexer *lexer, int n0, int n1)
 }
 
 void
-lex_extend_location (const struct lexer *lexer, int n, struct msg_location *loc)
+lex_extend_location (const struct lexer *lexer, int n, struct msg_location **loc)
 {
   struct msg_location *new = lex_get_location (lexer, n, n);
   msg_location_merge (loc, new);