gui: Factor out duplicated code for executing and pasting syntax.
[pspp] / src / data / identifier.h
index 53be9a7655048c7cabd12c15950bf3a6cd791f6b..02fc0db97b28aef3f975ad79466921f4186779b0 100644 (file)
@@ -1,39 +1,49 @@
-/* PSPP - computes sample statistics.
-   Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
-   Written by Ben Pfaff <blp@gnu.org>.
+/* PSPP - a program for statistical analysis.
+   Copyright (C) 1997-9, 2000, 2010 Free Software Foundation, Inc.
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA. */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if !lex_def_h
-#define lex_def_h 1
+#ifndef DATA_IDENTIFIER_H
+#define DATA_IDENTIFIER_H 1
 
 #include <ctype.h>
 #include <stdbool.h>
-#include <sys/types.h>
+#include <unitypes.h>
+#include "libpspp/str.h"
 
 /* Token types. */
-/* The order of the enumerals below is important.  Do not change it. */
-enum
+enum token_type
   {
-    T_ID = 256, /* Identifier. */
+    T_ID = 1,   /* Identifier. */
     T_POS_NUM, /* Positive number. */
     T_NEG_NUM, /* Negative number. */
     T_STRING,  /* Quoted string. */
     T_STOP,    /* End of input. */
 
+    T_ENDCMD,   /* End of command (e.g. '.'). */
+
+    T_PLUS,     /* + */
+    T_DASH,     /* - */
+    T_ASTERISK, /* * */
+    T_SLASH,    /* / */
+    T_EQUALS,   /* = */
+    T_LPAREN,   /* ( */
+    T_RPAREN,   /* ) */
+    T_LBRACK,   /* [ */
+    T_RBRACK,   /* ] */
+    T_COMMA,    /* , */
+
     T_AND,     /* AND */
     T_OR,      /* OR */
     T_NOT,     /* NOT */
@@ -51,23 +61,26 @@ enum
     T_WITH,    /* WITH */
 
     T_EXP,     /* ** */
-
-    T_FIRST_KEYWORD = T_AND,
-    T_LAST_KEYWORD = T_WITH,
-    T_N_KEYWORDS = T_LAST_KEYWORD - T_FIRST_KEYWORD + 1
   };
 
+/* Tokens. */
+bool lex_is_keyword (enum token_type);
+
 /* Recognizing identifiers. */
 bool lex_is_id1 (char);
 bool lex_is_idn (char);
-char *lex_skip_identifier (const char *);
+bool lex_uc_is_id1 (ucs4_t);
+bool lex_uc_is_idn (ucs4_t);
+bool lex_uc_is_space (ucs4_t);
+size_t lex_id_get_length (struct substring);
 
 /* Comparing identifiers. */
-bool lex_id_match_len (const char *keyword_string, size_t keyword_len,
-                       const char *token_string, size_t token_len);
-bool lex_id_match (const char *keyword_string, const char *token_string);
-int lex_id_to_token (const char *id, size_t len);
+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);
 
-extern const char *keywords[T_N_KEYWORDS + 1] ;
+/* Identifier names. */
+const char *lex_id_name (enum token_type);
 
-#endif /* !lex_def_h */
+#endif /* !data/identifier.h */