src/format.cc

changeset 86
43fe4be38a58
parent 85
264a61e9eba0
equal deleted inserted replaced
85:264a61e9eba0 86:43fe4be38a58
31 #include "format.h" 31 #include "format.h"
32 #include "lexer.h" 32 #include "lexer.h"
33 33
34 // ============================================================================= 34 // =============================================================================
35 // 35 //
36 static void draw_pos (const string& fmt, int pos) 36 static void draw_position (const string& fmt, int pos)
37 { 37 {
38 string rep (fmt); 38 string rep (fmt);
39 rep.replace ("\n", "↵"); 39 rep.replace ("\n", "↵");
40 rep.replace ("\t", "⇥"); 40 rep.replace ("\t", "⇥");
41 41
45 fprintf (stderr, "-"); 45 fprintf (stderr, "-");
46 46
47 fprintf (stderr, "^\n"); 47 fprintf (stderr, "^\n");
48 } 48 }
49 49
50 // =============================================================================
51 //
50 string format_args (const list<format_arg>& args) 52 string format_args (const list<format_arg>& args)
51 { 53 {
52 const string& fmtstr = args[0].as_string(); 54 const string& fmtstr = args[0].as_string();
53 assert (args.size() >= 1); 55 assert (args.size() >= 1);
54 56
80 82
81 if (!isdigit (fmt[pos + ofs])) 83 if (!isdigit (fmt[pos + ofs]))
82 { 84 {
83 fprintf (stderr, "bad format string, expected digit with optional " 85 fprintf (stderr, "bad format string, expected digit with optional "
84 "modifier after '%%':\n"); 86 "modifier after '%%':\n");
85 draw_pos (fmt, pos); 87 draw_position (fmt, pos);
86 return fmt; 88 return fmt;
87 } 89 }
88 90
89 int i = fmt[pos + ofs] - '0'; 91 int i = fmt[pos + ofs] - '0';
90 92
121 123
122 // ============================================================================= 124 // =============================================================================
123 // 125 //
124 void do_error (string msg) 126 void do_error (string msg)
125 { 127 {
126 lexer* lx = lexer::get_main_lexer(); 128 lexer* lx = lexer::get_current_lexer();
127 string fileinfo; 129 string fileinfo;
128 130
129 if (lx != null && lx->has_valid_token()) 131 if (lx != null && lx->has_valid_token())
130 { 132 {
131 lexer::token* tk = lx->get_token(); 133 lexer::token* tk = lx->get_token();

mercurial