1 /* vim: set ft=cpp : */
5 static void parse_error(const char *p, int lineno) {
6 std::ostringstream oss;
7 oss << "Parse error at line " << lineno;
8 throw parseException(oss.str());
11 static char string_escape(char c) {
13 case 'n': return '\n';
14 case 'r': return '\r';
15 case 't': return '\t';
21 void lexcaos(std::vector<token> &v, const char *p, bool c2) {
22 #define make_word(str) \
23 v.push_back(token(std::string(str), yylineno))
28 const char *basep, *YYMARKER;
32 re2c:define:YYCTYPE = "unsigned char";
33 re2c:define:YYCURSOR = p;
34 re2c:yyfill:enable = 0;
35 re2c:yych:conversion = 1;
43 WORDANY = [$#a-zA-Z0-9:?!_+-];
47 [\r\n] { ++yylineno; goto std; }
49 "*" [^\r\n\000]* { goto std; }
50 "'" noneoi "'" { v.push_back(token(caosVar((int)basep[1]), yylineno)); goto std; }
51 [fF] "**" [kK] { make_word("f**k"); goto std; }
52 WORDANY* WORDINIT WORDANY* {
53 std::string word(basep, p - basep);
54 std::transform(word.begin(), word.end(), word.begin(), tolower);
60 for (const char *i = basep + 1; i <= p; i++) {
64 v.push_back(token(caosVar(accum), yylineno));
67 SIGN? DIGIT* "." DIGIT* {
68 v.push_back(token(caosVar((float)atof(basep)), yylineno));
72 v.push_back(token(caosVar(atoi(basep)), yylineno));
75 "<>" { make_word("ne"); goto std; }
76 "<=" { make_word("le"); goto std; }
77 ">=" { make_word("ge"); goto std; }
78 "<" { make_word("lt"); goto std; }
79 ">" { make_word("gt"); goto std; }
80 "==" { make_word("eq"); goto std; }
81 "=" { make_word("eq"); goto std; }
82 "&&" { make_word("and"); goto std; }
83 "||" { make_word("or"); goto std; }
85 "[" { if (c2) goto brstr; else goto bytestr; }
89 any { parse_error(p, yylineno); }
94 [0-9]+ { tempbs.push_back(atoi(basep)); goto bytestr; }
95 [\n\r] { yylineno++; goto bytestr; }
96 [ \t] { goto bytestr; }
97 "]" { v.push_back(token(tempbs, yylineno)); tempbs.clear(); goto std; }
98 any { parse_error(p, yylineno); }
103 [\000\r\n] { parse_error(basep, yylineno); }
104 "]" { v.push_back(token(caosVar(tempstr), yylineno)); tempstr.clear(); goto std; }
105 noneoi { tempstr.push_back(*basep); goto brstr; }
111 [\000\r\n] { parse_error(p, yylineno); }
112 "\\" . { tempstr.push_back(string_escape(basep[1])); goto str; }
113 "\"" { v.push_back(token(caosVar(tempstr), yylineno)); tempstr.clear(); goto std; }
114 noneoi { tempstr.push_back(*basep); goto str; }
117 v.push_back(token()); // EOI
118 for (size_t i = 0; i < v.size(); i++)