lexer: New type enum token_type.
[pspp-builds.git] / src / data / identifier.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2010 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef DATA_IDENTIFIER_H
18 #define DATA_IDENTIFIER_H 1
19
20 #include <ctype.h>
21 #include <stdbool.h>
22 #include <unitypes.h>
23 #include "libpspp/str.h"
24
25 /* Token types. */
26 enum token_type
27   {
28     T_ID = 1,   /* Identifier. */
29     T_POS_NUM,  /* Positive number. */
30     T_NEG_NUM,  /* Negative number. */
31     T_STRING,   /* Quoted string. */
32     T_STOP,     /* End of input. */
33
34     T_ENDCMD,   /* End of command (e.g. '.'). */
35
36     T_PLUS,     /* + */
37     T_DASH,     /* - */
38     T_ASTERISK, /* * */
39     T_SLASH,    /* / */
40     T_EQUALS,   /* = */
41     T_LPAREN,   /* ( */
42     T_RPAREN,   /* ) */
43     T_LBRACK,   /* [ */
44     T_RBRACK,   /* ] */
45     T_COMMA,    /* , */
46
47     T_AND,      /* AND */
48     T_OR,       /* OR */
49     T_NOT,      /* NOT */
50
51     T_EQ,       /* EQ */
52     T_GE,       /* GE or >= */
53     T_GT,       /* GT or > */
54     T_LE,       /* LE or <= */
55     T_LT,       /* LT or < */
56     T_NE,       /* NE or ~= */
57
58     T_ALL,      /* ALL */
59     T_BY,       /* BY */
60     T_TO,       /* TO */
61     T_WITH,     /* WITH */
62
63     T_EXP,      /* ** */
64   };
65
66 /* Tokens. */
67 bool lex_is_keyword (enum token_type);
68
69 /* Recognizing identifiers. */
70 bool lex_is_id1 (char);
71 bool lex_is_idn (char);
72 bool lex_uc_is_id1 (ucs4_t);
73 bool lex_uc_is_idn (ucs4_t);
74 bool lex_uc_is_space (ucs4_t);
75 size_t lex_id_get_length (struct substring);
76
77 /* Comparing identifiers. */
78 bool lex_id_match (struct substring keyword, struct substring token);
79 bool lex_id_match_n (struct substring keyword, struct substring token,
80                      size_t n);
81 int lex_id_to_token (struct substring);
82
83 /* Identifier names. */
84 const char *lex_id_name (enum token_type);
85
86 #endif /* !data/identifier.h */