From: Ben Pfaff <blp@gnu.org>
Date: Wed, 5 Dec 2007 06:15:38 +0000 (+0000)
Subject: * lexer.c (lex_match_id_n): New function.
X-Git-Tag: v0.6.0~174
X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=601e58677703d381b6ace162b3ddb3c53d27f50a;p=pspp-builds.git

* lexer.c (lex_match_id_n): New function.
(lex_match_id): Reimplement in terms of lex_match_id_n.

* identifier.c (lex_id_match_n): New function.
(lex_id_match): Reimplement in terms of lex_id_match_n.
---

diff --git a/src/data/ChangeLog b/src/data/ChangeLog
index 4facdaf1..6c3b4518 100644
--- a/src/data/ChangeLog
+++ b/src/data/ChangeLog
@@ -1,3 +1,8 @@
+2007-12-04  Ben Pfaff  <blp@gnu.org>
+
+	* identifier.c (lex_id_match_n): New function.
+	(lex_id_match): Reimplement in terms of lex_id_match_n.
+
 2007-11-24  Ben Pfaff  <blp@gnu.org>
 
 	* automake.mk (src_data_libdata_a_SOURCES): Add val-type.h, to fix
diff --git a/src/data/identifier.c b/src/data/identifier.c
index 5c25cd07..a52944e2 100644
--- a/src/data/identifier.c
+++ b/src/data/identifier.c
@@ -74,11 +74,19 @@ lex_id_get_length (struct substring string)
    and those characters are identical to KEYWORD. */
 bool
 lex_id_match (struct substring keyword, struct substring token)
+{
+  return lex_id_match_n (keyword, token, 3);
+}
+
+/* Returns true if TOKEN is a case-insensitive match for at least
+   the first N characters of KEYWORD. */
+bool
+lex_id_match_n (struct substring keyword, struct substring token, size_t n)
 {
   size_t token_len = ss_length (token);
   size_t keyword_len = ss_length (keyword);
 
-  if (token_len >= 3 && token_len < keyword_len)
+  if (token_len >= n && token_len < keyword_len)
     return ss_equals_case (ss_head (keyword, token_len), token);
   else
     return ss_equals_case (keyword, token);
diff --git a/src/data/identifier.h b/src/data/identifier.h
index a8c2a9fd..352ef2ea 100644
--- a/src/data/identifier.h
+++ b/src/data/identifier.h
@@ -60,6 +60,8 @@ size_t lex_id_get_length (struct substring);
 
 /* Comparing identifiers. */
 bool lex_id_match (struct substring keyword, struct substring token);
+bool lex_id_match_n (struct substring keyword, struct substring token,
+                     size_t n);
 int lex_id_to_token (struct substring);
 
 /* Identifier names. */
diff --git a/src/language/lexer/ChangeLog b/src/language/lexer/ChangeLog
index 192debf8..aea10c5f 100644
--- a/src/language/lexer/ChangeLog
+++ b/src/language/lexer/ChangeLog
@@ -1,3 +1,8 @@
+2007-12-04  Ben Pfaff  <blp@gnu.org>
+
+	* lexer.c (lex_match_id_n): New function.
+	(lex_match_id): Reimplement in terms of lex_match_id_n.
+
 2007-08-16  Ben Pfaff  <blp@gnu.org>
 
 	Implement journaling.  Bug #17240.
diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c
index ac0af600..d1612876 100644
--- a/src/language/lexer/lexer.c
+++ b/src/language/lexer/lexer.c
@@ -548,9 +548,19 @@ lex_match (struct lexer *lexer, int t)
    Otherwise, returns false. */
 bool
 lex_match_id (struct lexer *lexer, const char *s)
+{
+  return lex_match_id_n (lexer, s, 3);
+}
+
+/* If the current token is the identifier S, skips it and returns
+   true.  The identifier may be abbreviated to its first N
+   letters.
+   Otherwise, returns false. */
+bool
+lex_match_id_n (struct lexer *lexer, const char *s, size_t n)
 {
   if (lexer->token == T_ID
-      && lex_id_match (ss_cstr (s), ss_cstr (lexer->tokid)))
+      && lex_id_match_n (ss_cstr (s), ss_cstr (lexer->tokid), n))
     {
       lex_get (lexer);
       return true;
diff --git a/src/language/lexer/lexer.h b/src/language/lexer/lexer.h
index ada09ade..53732b49 100644
--- a/src/language/lexer/lexer.h
+++ b/src/language/lexer/lexer.h
@@ -53,6 +53,7 @@ bool lex_is_string (struct lexer *);
 /* Token matching functions. */
 bool lex_match (struct lexer *, int);
 bool lex_match_id (struct lexer *, const char *);
+bool lex_match_id_n (struct lexer *, const char *, size_t n);
 bool lex_match_int (struct lexer *, int);
 
 /* Forcible matching functions. */