29 #include <cstdio> |
29 #include <cstdio> |
30 #include "main.h" |
30 #include "main.h" |
31 #include "format.h" |
31 #include "format.h" |
32 #include "lexer.h" |
32 #include "lexer.h" |
33 |
33 |
34 // ============================================================================= |
34 // |
|
35 // Throws an error while formatting the string |
35 // |
36 // |
36 static void formatError (String fmtstr, const String errdescribe, int pos) |
37 static void formatError (String fmtstr, const String errdescribe, int pos) |
37 { |
38 { |
38 fmtstr.replace ("\n", " "); |
39 fmtstr.replace ("\n", " "); |
39 fmtstr.replace ("\t", " "); |
40 fmtstr.replace ("\t", " "); |
44 |
45 |
45 errmsg += "^\n" + errdescribe; |
46 errmsg += "^\n" + errdescribe; |
46 throw std::logic_error (errmsg.stdString()); |
47 throw std::logic_error (errmsg.stdString()); |
47 } |
48 } |
48 |
49 |
49 // ============================================================================= |
50 // |
|
51 // Main formatter algorithm function. Processes @fmtstr with @args and returns |
|
52 // the result. |
50 // |
53 // |
51 String formatArgs (const String& fmtstr, const std::vector<String>& args) |
54 String formatArgs (const String& fmtstr, const std::vector<String>& args) |
52 { |
55 { |
53 String fmt = fmtstr; |
56 String fmt = fmtstr; |
54 String out; |
57 String out; |
97 } |
100 } |
98 |
101 |
99 return fmt; |
102 return fmt; |
100 } |
103 } |
101 |
104 |
102 // ============================================================================= |
|
103 // |
105 // |
104 void error (String msg) |
106 // Throws a runtime error with the message @msg. If a lexer is active, its |
|
107 // position is printed as well. |
|
108 // |
|
109 void error (const String& msg) |
105 { |
110 { |
106 Lexer* lx = Lexer::getCurrentLexer(); |
111 Lexer* lx = Lexer::getCurrentLexer(); |
107 String fileinfo; |
112 String fileinfo; |
108 |
113 |
109 if (lx != null && lx->hasValidToken()) |
114 if (lx != null && lx->hasValidToken()) |