Fix typos in comments
[pspp] / src / language / lexer / lexer.c
index 98cf8ec298245dfc53caf68648be4169a4cf90b0..9c402e679a949837720ce3f2589b0306b44b05cb 100644 (file)
@@ -272,7 +272,7 @@ lex_next_error (struct lexer *lexer, int n0, int n1, const char *format, ...)
 /* Prints a syntax error message saying that OPTION0 or one of the other
    strings following it, up to the first NULL, is expected. */
 void
-lex_error_expecting (struct lexer *lexer, const char *option0, ...)
+(lex_error_expecting) (struct lexer *lexer, const char *option0, ...)
 {
   enum { MAX_OPTIONS = 8 };
   const char *options[MAX_OPTIONS + 1];
@@ -428,14 +428,14 @@ lex_end_of_command (struct lexer *lexer)
 
 /* Returns true if the current token is a number. */
 bool
-lex_is_number (struct lexer *lexer)
+lex_is_number (const struct lexer *lexer)
 {
   return lex_next_is_number (lexer, 0);
 }
 
 /* Returns true if the current token is a string. */
 bool
-lex_is_string (struct lexer *lexer)
+lex_is_string (const struct lexer *lexer)
 {
   return lex_next_is_string (lexer, 0);
 }
@@ -443,14 +443,14 @@ lex_is_string (struct lexer *lexer)
 /* Returns the value of the current token, which must be a
    floating point number. */
 double
-lex_number (struct lexer *lexer)
+lex_number (const struct lexer *lexer)
 {
   return lex_next_number (lexer, 0);
 }
 
 /* Returns true iff the current token is an integer. */
 bool
-lex_is_integer (struct lexer *lexer)
+lex_is_integer (const struct lexer *lexer)
 {
   return lex_next_is_integer (lexer, 0);
 }
@@ -458,7 +458,7 @@ lex_is_integer (struct lexer *lexer)
 /* Returns the value of the current token, which must be an
    integer. */
 long
-lex_integer (struct lexer *lexer)
+lex_integer (const struct lexer *lexer)
 {
   return lex_next_integer (lexer, 0);
 }
@@ -472,7 +472,7 @@ lex_integer (struct lexer *lexer)
 
 /* Returns true if the token N ahead of the current token is a number. */
 bool
-lex_next_is_number (struct lexer *lexer, int n)
+lex_next_is_number (const struct lexer *lexer, int n)
 {
   enum token_type next_token = lex_next_token (lexer, n);
   return next_token == T_POS_NUM || next_token == T_NEG_NUM;
@@ -480,7 +480,7 @@ lex_next_is_number (struct lexer *lexer, int n)
 
 /* Returns true if the token N ahead of the current token is a string. */
 bool
-lex_next_is_string (struct lexer *lexer, int n)
+lex_next_is_string (const struct lexer *lexer, int n)
 {
   return lex_next_token (lexer, n) == T_STRING;
 }
@@ -488,7 +488,7 @@ lex_next_is_string (struct lexer *lexer, int n)
 /* Returns the value of the token N ahead of the current token, which must be a
    floating point number. */
 double
-lex_next_number (struct lexer *lexer, int n)
+lex_next_number (const struct lexer *lexer, int n)
 {
   assert (lex_next_is_number (lexer, n));
   return lex_next_tokval (lexer, n);
@@ -496,7 +496,7 @@ lex_next_number (struct lexer *lexer, int n)
 
 /* Returns true if the token N ahead of the current token is an integer. */
 bool
-lex_next_is_integer (struct lexer *lexer, int n)
+lex_next_is_integer (const struct lexer *lexer, int n)
 {
   double value;
 
@@ -510,7 +510,7 @@ lex_next_is_integer (struct lexer *lexer, int n)
 /* Returns the value of the token N ahead of the current token, which must be
    an integer. */
 long
-lex_next_integer (struct lexer *lexer, int n)
+lex_next_integer (const struct lexer *lexer, int n)
 {
   assert (lex_next_is_integer (lexer, n));
   return lex_next_tokval (lexer, n);
@@ -588,7 +588,7 @@ lex_force_match_id (struct lexer *lexer, const char *identifier)
     return true;
   else
     {
-      lex_error_expecting (lexer, identifier, NULL_SENTINEL);
+      lex_error_expecting (lexer, identifier);
       return false;
     }
 }
@@ -609,11 +609,11 @@ lex_force_match (struct lexer *lexer, enum token_type type)
       if (type_string)
        {
          char *s = xasprintf ("`%s'", type_string);
-         lex_error_expecting (lexer, s, NULL_SENTINEL);
+         lex_error_expecting (lexer, s);
          free (s);
        }
       else
-       lex_error_expecting (lexer, token_type_to_name (type), NULL_SENTINEL);
+       lex_error_expecting (lexer, token_type_to_name (type));
 
       return false;
     }
@@ -1257,7 +1257,6 @@ lex_source_error_valist (struct lex_source *src, int n0, int n1,
 {
   const struct lex_token *token;
   struct string s;
-  struct msg m;
 
   ds_init_empty (&s);
 
@@ -1285,14 +1284,16 @@ lex_source_error_valist (struct lex_source *src, int n0, int n1,
     }
   ds_put_byte (&s, '.');
 
-  m.category = MSG_C_SYNTAX;
-  m.severity = MSG_S_ERROR;
-  m.file_name = src->reader->file_name;
-  m.first_line = lex_source_get_first_line_number (src, n0);
-  m.last_line = lex_source_get_last_line_number (src, n1);
-  m.first_column = lex_source_get_first_column (src, n0);
-  m.last_column = lex_source_get_last_column (src, n1);
-  m.text = ds_steal_cstr (&s);
+  struct msg m = {
+    .category = MSG_C_SYNTAX,
+    .severity = MSG_S_ERROR,
+    .file_name = src->reader->file_name,
+    .first_line = lex_source_get_first_line_number (src, n0),
+    .last_line = lex_source_get_last_line_number (src, n1),
+    .first_column = lex_source_get_first_column (src, n0),
+    .last_column = lex_source_get_last_column (src, n1),
+    .text = ds_steal_cstr (&s),
+  };
   msg_emit (&m);
 }
 
@@ -1417,8 +1418,13 @@ lex_source_get__ (const struct lex_source *src_)
       /* Beginning of line. */
       const char *line = &src->buffer[src->journal_pos - src->tail];
 
-      /* Calculate line length, including \n or \r\n end-of-line if present. */
-      size_t max_len = state.line_pos - src->journal_pos;
+      /* Calculate line length, including \n or \r\n end-of-line if present.
+
+         We use src->head even though that may be beyond what we've actually
+         converted to tokens (which is only through state.line_pos).  That's
+         because, if we're emitting the line due to SEG_END_COMMAND, we want to
+         take the whole line through the newline, not just through the '.'. */
+      size_t max_len = src->head - src->journal_pos;
       const char *newline = memchr (line, '\n', max_len);
       size_t line_len = newline ? newline - line + 1 : max_len;
 
@@ -1429,13 +1435,9 @@ lex_source_get__ (const struct lex_source *src_)
       if (copy_len > 0 && line[copy_len - 1] == '\r')
         copy_len--;
 
-      /* Make a copy of the line with \n end-of-line and null terminator. */
-      char *syntax = xmalloc (copy_len + 2);
-      memcpy (syntax, line, copy_len);
-      syntax[copy_len] = '\n';
-      syntax[copy_len + 1] = '\0';
-
-      text_item_submit (text_item_create_nocopy (TEXT_ITEM_SYNTAX, syntax));
+      /* Submit the line as syntax. */
+      text_item_submit (text_item_create_nocopy (TEXT_ITEM_SYNTAX,
+                                                 xmemdup0 (line, copy_len)));
 
       src->journal_pos += line_len;
     }