libidav/davqlparser.h

changeset 106
9cec78f23cbf
parent 102
e9ae1318a559
child 107
a0903d2d8e3e
--- a/libidav/davqlparser.h	Sat May 02 18:52:04 2015 +0200
+++ b/libidav/davqlparser.h	Wed May 13 12:00:54 2015 +0200
@@ -43,10 +43,22 @@
 typedef enum {DAVQL_ERROR, DAVQL_GET, DAVQL_SET} davqltype_t;
 
 /**
+ * Enumeration of possible token classes.
+ */
+typedef enum {
+    DAVQL_TOKEN_INVALID, DAVQL_TOKEN_KEYWORD,
+    DAVQL_TOKEN_IDENTIFIER, DAVQL_TOKEN_FMTSPEC,
+    DAVQL_TOKEN_STRING, DAVQL_TOKEN_NUMBER, DAVQL_TOKEN_TIMESTAMP,
+    DAVQL_TOKEN_COMMA, DAVQL_TOKEN_OPENP, DAVQL_TOKEN_CLOSEP,
+    DAVQL_TOKEN_EQ, DAVQL_TOKEN_LT, DAVQL_TOKEN_GT, DAVQL_TOKEN_EXCLAIM,
+    DAVQL_TOKEN_OPERATOR
+} davqltokenclass_t;
+
+/**
  * Enumeration of possible expression types.
  */
 typedef enum {
-    DAVQL_UNDEFINED_TYP,
+    DAVQL_UNDEFINED_TYPE,
     DAVQL_NUMBER, DAVQL_STRING, DAVQL_TIMESTAMP, DAVQL_IDENTIFIER,
     DAVQL_UNARY, DAVQL_BINARY, DAVQL_LOGICAL, DAVQL_FUNCCALL
 } davqlexprtype_t;
@@ -63,6 +75,11 @@
     DAVQL_LIKE, DAVQL_UNLIKE // comparisons
 } davqloperator_t;
 
+typedef struct {
+    davqltokenclass_t tokenclass;
+    sstr_t value;
+} DavQLToken;
+
 /**
  * An expression within a DAVQL query.
  */
@@ -145,7 +162,7 @@
  * AddExpression     = MultExpression, [AddOperator, AddExpression];
  * MultExpression    = BitwiseExpression, [MultOperator, MultExpression];
  * BitwiseExpression = UnaryExpression, [BitwiseOperator, BitwiseExpression];
- * UnaryExpression   = [UnaryOperator], (AtomicExpression | ParExpression);
+ * UnaryExpression   = [UnaryOperator], (ParExpression | AtomicExpression);
  * AtomicExpression  = FunctionCall | Identifier | Literal;
  * ParExpression     = "(", Expression, ")";
  * 
@@ -174,9 +191,9 @@
  * LogicalOperator = " and " | " or " | " xor ";
  * Comparison      = | "=" | "<" | ">" | "<=" | ">=" | "!=";
  * 
- * FieldExpressions = "*", {",", Expression, " as ", Identifier}
- *                  | FieldExpression, {",", FieldExpression}
- *                  | "-";
+ * FieldExpressions = "-"
+ *                  | "*", {",", Expression, " as ", Identifier}
+ *                  | FieldExpression, {",", FieldExpression};
  * FieldExpression  = Identifier
  *                  | Expression, " as ", Identifier;
  * SetExpressions   = SetExpression, {",", SetExpression};
@@ -266,54 +283,30 @@
 /** Depth needs to be specified at runtime. */
 #define DAV_DEPTH_PLACEHOLDER -2
 
-/** Invalid path. */
-#define DAVQL_ERROR_INVALID_PATH 1
-
-/** Expected an identifier, but found something else. */
-#define DAVQL_ERROR_IDENTIFIER_EXPECTED 10
-
-/** Expected an identifier or literal, but found something else. */
-#define DAVQL_ERROR_IDORLIT_EXPECTED 11
+/** Unexpected token. */
+#define DAVQL_ERROR_UNEXPECTED_TOKEN 1
 
-/** Expected an identifier or number, but found something else. */
-#define DAVQL_ERROR_IDORNUM_EXPECTED 12
-
-/** Expected an identifier or string, but found something else. */
-#define DAVQL_ERROR_IDORSTR_EXPECTED 13
+/** A token has been found, for which no token class is applicable. */
+#define DAVQL_ERROR_INVALID_TOKEN 2
 
-/** Expected an identifier or timestamp, but found something else. */
-#define DAVQL_ERROR_IDORTS_EXPECTED 14
-
-/** The with-clause contains an unknown attribute. */
-#define DAVQL_ERROR_UNKNOWN_ATTRIBUTE 20
+/** A token that has been expected was not found. */
+#define DAVQL_ERROR_MISSING_TOKEN 11
 
-/** Depth must be greater than zero or infinity. */
-#define DAVQL_ERROR_INVALID_DEPTH 21
-
-/** The with-clause contains an attribute more than once. */
-#define DAVQL_ERROR_DUPLICATED_ATTRIBUTE 29
-
-/** The format specifier is missing. */
-#define DAVQL_ERROR_MISSING_FMTSPEC 30
-
-/** The format specifier is unknown. */
-#define DAVQL_ERROR_UNKNOWN_FMTSPEC 31
+/** An expression has been expected, but was not found. */
+#define DAVQL_ERROR_MISSING_EXPR 12
 
-/** The format specifier is invalid. */
-#define DAVQL_ERROR_INVALID_FMTSPEC 39
-
-/** A quote symbol (' or `) is missing. */
-#define DAVQL_ERROR_MISSING_QUOTE 50
+/** An operator has been found for a unary expression, but it is invalid. */
+#define DAVQL_ERROR_INVALID_UNARY_OP 21
 
-/** No more tokens to parse, but the parser expected more. */
-#define DAVQL_ERROR_UNEXPECTED_END 100
-
-/** A token was found, which has not been expected. */
-#define DAVQL_ERROR_UNEXPECTED_TOKEN 101
+/** The depth is invalid. */
+#define DAVQL_ERROR_INVALID_DEPTH 101
 
 /** Nothing about the statement seems legit. */
 #define DAVQL_ERROR_INVALID -1
 
+/** Unhandled error */
+#define DAVQL_ERROR_UNHANDLED -2
+
 /**
  * Starts an interactive debugger for a DavQLStatement.
  * 

mercurial