kDB: Knowledge DataBase
Loading...
Searching...
No Matches
Token_p.h
1/*
2 * Copyright (c) 2008,2010,2015 Cyrille Berger <cberger@cberger.net>
3 *
4 */
5
6#ifndef _SPARQL_TOKEN_H_
7#define _SPARQL_TOKEN_H_
8
9#include <QString>
10#include <sstream>
11
12#include <knowCore/Curie.h>
13
14namespace kDB
15{
16 namespace SPARQL
17 {
18 struct Token
19 {
23 enum Type
24 {
25 // Not really token
26 INVALID_BINDING = -6,
27 UNKNOWN_BINDING = -5,
28 UNFINISHED_STRING = -4,
29 END_OF_FILE = -3,
30 END_OF_LINE = -2,
31 UNKNOWN = -1,
32 // Special characters
33 SEMI = 0,
58 // Constants
59 FLOAT_CONSTANT,
60 INTEGER_CONSTANT,
61 STRING_CONSTANT,
62 URI_CONSTANT,
63 NAME,
64 LANG_TAG,
65 VARIABLE,
66 CURIE_CONSTANT,
67 BINDING,
68 // Special values,
69 FALSE,
70 TRUE,
71#define KDB_SPARQL_KEYWORD(_NAME_) _NAME_,
72 // Keywords
73 A,
74#include "Keywords.h"
75 // PL/SPARQL
76#include "PlKeywords.h"
77#undef KDB_SPARQL_KEYWORD
78 ___
79 };
83 int line;
85 int column;
87 QString string;
88 // Curie
89 knowCore::Curie curie;
90 Token();
91 Token(const knowCore::Curie& _curie, int _line, int _column);
95 Token(Type _type, int _line, int _column);
99 Token(Type _type, const QString& _string, int _line, int _column);
100 bool isExpressionTerminal();
101 bool isConstant() const;
102 bool isBinaryOperator() const;
103 int binaryOperationPriority() const;
104 bool isUnaryOperator() const;
105 bool isOperator() const;
106 bool isPrimary() const;
107 static QString typeToString(Type);
108 QString toString() const;
109 bool operator==(const Token& _rhs) const
110 {
111 return type == _rhs.type and line == _rhs.line and column == _rhs.column
112 and string == _rhs.string and curie == _rhs.curie;
113 }
114 };
115 } // namespace SPARQL
116}; // namespace kDB
117
118#include <knowCore/Formatter.h>
119
120clog_format_declare_formatter(kDB::SPARQL::Token::Type)
121{
122 return format_to(ctx.out(), "{}", kDB::SPARQL::Token::typeToString(p));
123}
124
125#endif
Definition Curie.h:22
Definition Token_p.h:19
Type type
type of the token
Definition Token_p.h:81
QString string
String or identifier name.
Definition Token_p.h:87
int column
Column of the token.
Definition Token_p.h:85
int line
line of the token
Definition Token_p.h:83
Type
Definition Token_p.h:24
@ AND
and &&
Definition Token_p.h:45
@ SUPPERIOREQUAL
>=
Definition Token_p.h:50
@ COMA
,
Definition Token_p.h:35
@ STARTBOXBRACKET
[
Definition Token_p.h:41
@ DIFFERENT
!=
Definition Token_p.h:44
@ DIVIDE
/
Definition Token_p.h:54
@ EXCLAMATION
not !
Definition Token_p.h:55
@ MINUS
Definition Token_p.h:52
@ STARTBRACE
{
Definition Token_p.h:37
@ INFERIOR
<
Definition Token_p.h:47
@ PLUS
Definition Token_p.h:51
@ STARTBRACKET
(
Definition Token_p.h:39
@ SEMI
;
Definition Token_p.h:33
@ INFERIOREQUAL
<=
Definition Token_p.h:48
@ CIRCUMFLEXCIRCUMFLEX
^^
Definition Token_p.h:57
@ MULTIPLY
Definition Token_p.h:53
@ UNDERSCORECOLON
_:
Definition Token_p.h:56
@ COLON
:
Definition Token_p.h:34
@ EQUAL
=
Definition Token_p.h:43
@ ENDBOXBRACKET
]
Definition Token_p.h:42
@ SUPPERIOR
Definition Token_p.h:49
@ OR
or ||
Definition Token_p.h:46
@ ENDBRACE
}
Definition Token_p.h:38
@ DOT
Definition Token_p.h:36
@ ENDBRACKET
)
Definition Token_p.h:40