blob: f803283e1a160bb9e5212efff76e39bdf687819c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/***************************************************************************
parserdata.cpp - Parser data: keywords, functions etc.
-------------------
copyright : (C) 2004 Michal Rudolf <mrudolf@kdewebdwev.org>
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "parserdata.h"
using namespace Parse;
KeywordGroup ParserData::keywordGroup(Keyword k) const
{
if (m_groups.contains(k))
return m_groups[k];
else
return GroupMisc;
}
Keyword ParserData::stringToKeyword(const QString& s) const
{
QString k = s.lower();
if (m_keywords.contains(k))
return m_keywords[k];
else
return Variable;
}
QString ParserData::keywordToString(Parse::Keyword k) const
{
for (QMapConstIterator<QString, Keyword> it = m_keywords.begin(); it != m_keywords.end(); ++it)
if (it.data() == k)
return it.key();
return QString();
}
bool ParserData::registerFunction(const QString& name, Function f)
{
m_functions[name.lower()] = f;
return true;
}
ParserData::ParserData()
{
m_keywords["for"] = For;
m_keywords["foreach"] = Foreach;
m_keywords["in"] = In;
m_keywords["end"] = End;
m_keywords["if"] = If;
m_keywords["then"] = Then;
m_keywords["else"] = Else;
m_keywords["elseif"] = Elseif;
m_keywords["endif"] = Endif;
m_keywords["switch"] = Switch;
m_keywords["case"] = Case;
m_keywords["while"] = While;
m_keywords["to"] = To;
m_keywords["step"] = Step;
m_keywords["do"] = Do;
m_keywords["break"] = Break;
m_keywords["continue"] = Continue;
m_keywords["exit"] = Exit;
m_keywords["."] = Dot;
m_keywords[";"] = Semicolon;
m_keywords[","] = Comma;
m_keywords["="] = Assign;
m_keywords["<"] = Less;
m_keywords["<="] = LessEqual;
m_keywords[">"] = Greater;
m_keywords[">="] = GreaterEqual;
m_keywords["=="] = Equal;
m_keywords["!="] = NotEqual;
m_keywords["<>"] = NotEqual;
m_keywords["not"] = Not;
m_keywords["!"] = Not;
m_keywords["and"] = And;
m_keywords["&&"] = And;
m_keywords["or"] = Or;
m_keywords["||"] = Or;
m_keywords["false"] = False;
m_keywords["true"] = True;
m_keywords["("] = LeftParenthesis;
m_keywords[")"] = RightParenthesis;
m_keywords["["] = LeftBracket;
m_keywords["]"] = RightBracket;
m_keywords["+"] = Plus;
m_keywords["-"] = Minus;
m_keywords["*"] = Multiply;
m_keywords["/"] = Divide;
m_keywords["%"] = Mod;
m_keywords["mod"] = Mod;
m_groups[Less] = GroupComparison;
m_groups[LessEqual] = GroupComparison;
m_groups[Equal] = GroupComparison;
m_groups[NotEqual] = GroupComparison;
m_groups[Greater] = GroupComparison;
m_groups[GreaterEqual] = GroupComparison;
m_groups[Plus] = GroupAdd;
m_groups[Minus] = GroupAdd;
m_groups[Multiply] = GroupMultiply;
m_groups[Divide] = GroupMultiply;
m_groups[Mod] = GroupMultiply;
registerStandardFunctions();
}
bool ParserData::isFunction(const QString& name) const
{
return m_functions.contains(name.lower());
}
const Function& ParserData::function(const QString& name) const
{
return m_functions[name.lower()];
}
|