swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 1 | #include <QCoreApplication> |
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 2 | #include <QCommandLineParser> |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 3 | #include <QDebug> |
| 4 | |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 5 | #include "Matcher.h" |
| 6 | #include "Token.h" |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 7 | #include "AstNode.h" |
| 8 | #include "Parser.h" |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 9 | #include "Evaluator.h" |
| 10 | #include "VarContext.h" |
swissChili | f8c74f0 | 2022-04-16 18:47:16 -0700 | [diff] [blame] | 11 | #ifdef INCLUDE_CLI |
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 12 | #include "Repl.h" |
swissChili | f8c74f0 | 2022-04-16 18:47:16 -0700 | [diff] [blame] | 13 | #endif |
swissChili | 9dddbf7 | 2021-12-08 23:03:25 -0800 | [diff] [blame] | 14 | #include "PPrint.h" |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 15 | |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 16 | #ifdef NO_IDE |
| 17 | using Application = QCoreApplication; |
| 18 | #else |
| 19 | #include "ide/IdeMain.h" |
| 20 | #endif |
| 21 | |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 22 | int g_numFailed = 0; |
| 23 | |
swissChili | 1060c0e | 2021-12-09 09:46:42 -0800 | [diff] [blame] | 24 | |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 25 | void testEval(QString function, QString expression, QString expected) |
| 26 | { |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 27 | Evaluator eval; |
| 28 | Parser funcParser(function), |
| 29 | exprParser(expression), |
| 30 | resParser(expected); |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 31 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 32 | Function func; |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 33 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 34 | QList<AstNode> expr; |
| 35 | ParseResult exprRet = exprParser.parseMany<AstNode>(&expr); |
| 36 | QList<Token> res; |
| 37 | ParseResult resRet = resParser.parseMany<Token>(&res); |
| 38 | ParseResult funcRet; |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 39 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 40 | QList<Token> result; |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 41 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 42 | exprParser.skip(); |
| 43 | resParser.skip(); |
| 44 | while ((funcRet = funcParser.parseFunctionDefinition(&func))) |
| 45 | { |
| 46 | eval.addFunction(func); |
| 47 | } |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 48 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 49 | funcParser.skip(); |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 50 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 51 | if (!exprRet || !resRet || funcRet.status() == ParseResult::INCOMPLETE) |
| 52 | { |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 53 | g_numFailed++; |
| 54 | qDebug() << "\n\033[31mTEST FAILS:\033[0m"; |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 55 | qDebug() << "Failed to fully parse expression, function or result"; |
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame] | 56 | qDebug() << "Function:"; |
| 57 | sout(pprint(funcRet, funcParser)); |
| 58 | |
| 59 | qDebug() << "Expression:"; |
| 60 | sout(pprint(exprRet, exprParser)); |
| 61 | |
| 62 | qDebug() << "Result:"; |
| 63 | sout(pprint(resRet, resParser)); |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 64 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 65 | goto end; |
| 66 | } |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 67 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 68 | for (const AstNode &node : expr) |
| 69 | { |
| 70 | RuntimeResult rr = eval.evaluate(node, VarContext()); |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 71 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 72 | if (!rr.success()) |
| 73 | { |
| 74 | g_numFailed++; |
| 75 | qDebug() << "\n\033[31mTEST FAILS:\033[0m"; |
| 76 | qDebug() << "Runtime error while evaluating" << node; |
| 77 | qDebug() << rr; |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 78 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 79 | goto end; |
| 80 | } |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 81 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 82 | result.append(rr.result()); |
| 83 | } |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 84 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 85 | if (result != res) |
| 86 | { |
| 87 | g_numFailed++; |
| 88 | qDebug() << "\n\033[31mTEST FAILS:\033[0m"; |
| 89 | qDebug() << "Expected result" << res; |
| 90 | qDebug() << "Got" << result; |
| 91 | } |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 92 | |
| 93 | end: |
swissChili | 918557c | 2022-02-20 20:16:34 -0800 | [diff] [blame] | 94 | qDebug() << "\033[36mEvaluate\033[0m" << function << expression << "->" << pprint(result); |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 95 | } |
| 96 | |
swissChili | 1060c0e | 2021-12-09 09:46:42 -0800 | [diff] [blame] | 97 | void testEval(QString function, QString expression, QList<Token> expected) |
| 98 | { |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 99 | testEval(function, expression, pprint(expected)); |
swissChili | 1060c0e | 2021-12-09 09:46:42 -0800 | [diff] [blame] | 100 | } |
| 101 | |
swissChili | 918557c | 2022-02-20 20:16:34 -0800 | [diff] [blame] | 102 | void testEval(QString expression, QString expected) |
| 103 | { |
| 104 | testEval("", expression, expected); |
| 105 | } |
| 106 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 107 | void testMatch(const QString &test, bool shouldBe, const MatchResult &result) |
| 108 | { |
| 109 | if (result.success != shouldBe) |
| 110 | { |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 111 | g_numFailed++; |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 112 | qDebug() << "\n\033[31mTEST FAILS:\033[0m"; |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame] | 113 | qDebug() << "with context" << result.context; |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 114 | } |
| 115 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 116 | qDebug() << "\033[36mMatchResult\033[0m" << test << result.success; |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame] | 117 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 118 | if (result.success != shouldBe) |
| 119 | { |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame] | 120 | qDebug() << ""; |
| 121 | } |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 122 | } |
| 123 | |
swissChili | 682e7bc | 2021-12-07 09:04:54 -0800 | [diff] [blame] | 124 | void testMatch(QString data, QString pattern, bool shouldBe = true) |
| 125 | { |
| 126 | Parser dataParser(data), |
| 127 | patternParser(pattern); |
| 128 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 129 | QList<Token> parsedData, parsedPattern; |
| 130 | |
| 131 | dataParser.parseMany<Token>(&parsedData); |
| 132 | patternParser.parseMany<Token>(&parsedPattern); |
swissChili | 847a78c | 2021-12-09 17:44:52 -0800 | [diff] [blame] | 133 | |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 134 | testMatch(pattern + " = " + data, shouldBe, |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 135 | match(parsedData, parsedPattern, VarContext())); |
swissChili | 682e7bc | 2021-12-07 09:04:54 -0800 | [diff] [blame] | 136 | } |
| 137 | |
swissChili | 9dddbf7 | 2021-12-08 23:03:25 -0800 | [diff] [blame] | 138 | void testParseAst(QString string, QList<AstNode> equals = {}) |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 139 | { |
| 140 | Parser parser{string}; |
| 141 | |
swissChili | 847a78c | 2021-12-09 17:44:52 -0800 | [diff] [blame] | 142 | QList<AstNode> result; |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 143 | parser.parseMany<AstNode>(&result); |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 144 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 145 | if (!equals.empty() && result != equals) |
| 146 | { |
swissChili | 9dddbf7 | 2021-12-08 23:03:25 -0800 | [diff] [blame] | 147 | g_numFailed++; |
| 148 | qDebug() << "\n\033[31mTEST FAILS:\033[0m"; |
| 149 | qDebug() << "Expected" << pprint(equals); |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 150 | } |
swissChili | 9dddbf7 | 2021-12-08 23:03:25 -0800 | [diff] [blame] | 151 | |
| 152 | qDebug() << "\033[36mParse\033[0m" << string << pprint(result); |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 153 | } |
| 154 | |
swissChili | 8a581c6 | 2021-12-07 13:29:21 -0800 | [diff] [blame] | 155 | void testParseFunc(QString string) |
| 156 | { |
| 157 | Parser parser{string}; |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 158 | ParseResult ret; |
swissChili | 8a581c6 | 2021-12-07 13:29:21 -0800 | [diff] [blame] | 159 | |
| 160 | Function func; |
| 161 | |
swissChili | 847a78c | 2021-12-09 17:44:52 -0800 | [diff] [blame] | 162 | if (!(ret = parser.parseFunctionDefinition(&func))) |
swissChili | 8a581c6 | 2021-12-07 13:29:21 -0800 | [diff] [blame] | 163 | { |
| 164 | g_numFailed++; |
| 165 | qDebug() << "\n\033[31mTEST FAILS:\033[0m"; |
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame] | 166 | sout(pprint(ret, parser)); |
swissChili | 8a581c6 | 2021-12-07 13:29:21 -0800 | [diff] [blame] | 167 | qDebug() << string; |
| 168 | } |
| 169 | else |
| 170 | { |
| 171 | qDebug() << "\033[36mFunction\033[0m"; |
| 172 | qDebug().noquote() << func; |
| 173 | } |
| 174 | } |
| 175 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 176 | int testResults() |
| 177 | { |
| 178 | if (g_numFailed == 0) |
| 179 | { |
| 180 | qDebug() << "\033[32mALL TESTS SUCCEEDED\033[0m"; |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | qDebug().nospace() << "\033[31m" << g_numFailed << " TESTS FAILED\033[0m"; |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | return g_numFailed; |
| 188 | } |
| 189 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 190 | void testAllMatches() |
| 191 | { |
| 192 | testMatch("a = a", true, match({Token('a')}, {Token('a')}, VarContext())); |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 193 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 194 | testMatch("s.a = y", true, match({Token('y')}, {Token('s', "a")}, VarContext())); |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame] | 195 | |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 196 | LTok sameTwo = {Token('s', "a"), Token('s', "a")}; |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 197 | testMatch("s.a s.a = aa", true, match({Token('a'), Token('a')}, sameTwo, VarContext())); |
| 198 | testMatch("s.a s.a = ab", false, match({Token('a'), Token('b')}, sameTwo, VarContext())); |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 199 | |
| 200 | LTok sameStartEnd = { |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 201 | Token('s', "a"), |
| 202 | Token('e', "middle"), |
| 203 | Token('s', "a")}; |
| 204 | testMatch("s.a e.middle s.a = aea", true, |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 205 | match({Token('a'), Token('e'), Token('a')}, sameStartEnd, VarContext())); |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 206 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 207 | testMatch("s.a e.middle s.a = aef Hi a", true, |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 208 | match({Token('a'), Token('e'), Token('f'), Token("Hi"), Token('a')}, sameStartEnd, VarContext())); |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 209 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 210 | testMatch("s.a e.middle s.a = aef Hi c", false, |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 211 | match({Token('a'), Token('e'), Token('f'), Token("Hi"), Token('c')}, sameStartEnd, VarContext())); |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame] | 212 | |
| 213 | LTok parenthesized = { |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 214 | Token(LTok({Token('s', "a")})), |
| 215 | Token('e', "Middle"), |
| 216 | Token('s', "a"), |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame] | 217 | }; |
| 218 | LTok parenTest1 = { |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 219 | Token(LTok({Token('y')})), |
| 220 | Token('f'), |
| 221 | Token("MiddleStuff"), |
| 222 | Token('y')}; |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame] | 223 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 224 | testMatch("(s.a) e.Middle s.a = (y)f MiddleStuff y", true, |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 225 | match(parenTest1, parenthesized, VarContext())); |
swissChili | 682e7bc | 2021-12-07 09:04:54 -0800 | [diff] [blame] | 226 | // testMatch("(y)f Middle-stuff y", "(s.a) e.Middle s.a"); |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame] | 227 | |
swissChili | 682e7bc | 2021-12-07 09:04:54 -0800 | [diff] [blame] | 228 | testMatch("(a)", "(a)"); |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 229 | testMatch("hello", "s.A e.Rest"); |
| 230 | testMatch("123", "123"); |
| 231 | testMatch("(123)", "t.a"); |
| 232 | testMatch("(123)", "(s.a)"); |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 233 | } |
| 234 | |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 235 | void testAllParses() |
| 236 | { |
swissChili | 682e7bc | 2021-12-07 09:04:54 -0800 | [diff] [blame] | 237 | testParseAst("all symbols"); |
| 238 | testParseAst("Identifier symbols Identifier"); |
| 239 | testParseAst("s.A"); |
| 240 | testParseAst("(s.A) Variable-quoted"); |
| 241 | testParseAst("<Func-name a b (c)>"); |
| 242 | testParseAst("<Prout hi>"); |
| 243 | testParseAst("(Prout hi)"); |
| 244 | testParseAst("(<Prout hi>)"); |
| 245 | testParseAst("<If T Then (<Prout hi>) Else (<Prout sorry>)>"); |
| 246 | testParseAst("(s.a) e.Middle s.a"); |
swissChili | 8a581c6 | 2021-12-07 13:29:21 -0800 | [diff] [blame] | 247 | testParseAst("Hello; Goodbye"); |
| 248 | testParseAst("Key = Value"); |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 249 | testParseAst("123", {AstNode("123", 10)}); |
| 250 | testParseAst("12 00", {AstNode::fromInteger(12), AstNode::fromInteger(0)}); |
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame] | 251 | testParseAst("s.A s.B", {AstNode('s', "A"), AstNode('s', "B")}); |
swissChili | 918557c | 2022-02-20 20:16:34 -0800 | [diff] [blame] | 252 | testParseAst("a '=' b", {AstNode('a'), AstNode('='), AstNode('b')}); |
| 253 | testParseAst("'This\\'<>#$@#^%\\n' 'another $3543543'"); |
swissChili | 8a581c6 | 2021-12-07 13:29:21 -0800 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | void testAllFunctionDefs() |
| 257 | { |
| 258 | testParseFunc("Test { = HI; }"); |
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 259 | testParseFunc("Palindrome { = T; s.A = T; s.A e.Middle s.A = <Palindrome e.Middle>; e.Ignored = F; } "); |
swissChili | 07d325f | 2021-12-08 20:02:05 -0800 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | void testAllEvals() |
| 263 | { |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 264 | testEval("First {s.A e.Rest = s.A;}", "<First hello>", "h"); |
| 265 | testEval("Number { = 123; }", "<Number>", QList<Token>{Token::fromInteger(123)}); |
swissChili | 918557c | 2022-02-20 20:16:34 -0800 | [diff] [blame] | 266 | testEval("<Br Name '=' Jim> <Dg Name>", "Jim"); |
| 267 | testEval("<Br A '=' hello> <Br A '=' 'good bye'> <Dg A> <Dg A>", "'good byehello'"); |
swissChili | c71acc6 | 2021-12-07 08:03:37 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | int main(int argc, char *argv[]) |
| 271 | { |
swissChili | e386bc7 | 2022-02-24 21:31:31 -0800 | [diff] [blame] | 272 | QCoreApplication::setAttribute(Qt::AA_UseOpenGLES); |
swissChili | d2af6ad | 2022-04-16 14:42:17 -0700 | [diff] [blame] | 273 | #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
| 274 | QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); |
| 275 | #endif |
swissChili | e386bc7 | 2022-02-24 21:31:31 -0800 | [diff] [blame] | 276 | |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 277 | Application a(argc, argv); |
| 278 | a.setApplicationName("REFAL"); |
| 279 | a.setApplicationVersion("1.0-a1"); |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 280 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 281 | QCommandLineParser cli; |
| 282 | cli.setApplicationDescription("REFAL interpreter"); |
| 283 | cli.addHelpOption(); |
| 284 | cli.addVersionOption(); |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 285 | |
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame] | 286 | cli.addPositionalArgument("script", "REFAL script to run"); |
| 287 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 288 | QCommandLineOption testOption(QStringList{"t", "test"}, "Run test suite."); |
| 289 | cli.addOption(testOption); |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 290 | QCommandLineOption replOption(QStringList({"r", "repl"}), "Start CLI REPL"); |
| 291 | cli.addOption(replOption); |
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 292 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 293 | cli.process(a); |
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 294 | |
swissChili | 323883d | 2022-02-20 16:35:23 -0800 | [diff] [blame] | 295 | if (cli.positionalArguments().length() > 0) |
| 296 | { |
| 297 | qDebug() << "Running script" << cli.positionalArguments()[0]; |
| 298 | } |
| 299 | else if (cli.isSet(testOption)) |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 300 | { |
| 301 | testAllMatches(); |
| 302 | qDebug() << ""; |
| 303 | testAllParses(); |
| 304 | qDebug() << ""; |
| 305 | testAllFunctionDefs(); |
| 306 | qDebug() << ""; |
| 307 | testAllEvals(); |
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 308 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 309 | qDebug() << ""; |
swissChili | 923bd53 | 2021-12-08 22:48:58 -0800 | [diff] [blame] | 310 | |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 311 | return testResults(); |
| 312 | } |
swissChili | f8c74f0 | 2022-04-16 18:47:16 -0700 | [diff] [blame] | 313 | #ifdef INCLUDE_CLI |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 314 | else if (cli.isSet(replOption)) |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 315 | { |
| 316 | Repl repl; |
| 317 | repl.start(); |
| 318 | } |
swissChili | f8c74f0 | 2022-04-16 18:47:16 -0700 | [diff] [blame] | 319 | #endif |
swissChili | 23958ca | 2022-02-21 19:23:34 -0800 | [diff] [blame] | 320 | else |
| 321 | { |
| 322 | return ideMain(&a); |
| 323 | } |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 324 | } |