Line |
Branch |
Exec |
Source |
1 |
|
|
#pragma once |
2 |
|
|
|
3 |
|
|
#include "dtypes.h" |
4 |
|
|
|
5 |
|
|
namespace lython { |
6 |
|
|
|
7 |
|
|
// Python traceback example: |
8 |
|
|
// ------------------------- |
9 |
|
|
|
10 |
|
|
// Traceback (most recent call last): |
11 |
|
|
// File "/home/runner/ShyCalculatingGraph/main.py", line 11, in <module> |
12 |
|
|
// rec(10) |
13 |
|
|
// File "/home/runner/ShyCalculatingGraph/main.py", line 7, in rec |
14 |
|
|
// return rec(n - 1) |
15 |
|
|
// File "/home/runner/ShyCalculatingGraph/main.py", line 7, in rec |
16 |
|
|
// return rec(n - 1) |
17 |
|
|
// File "/home/runner/ShyCalculatingGraph/main.py", line 7, in rec |
18 |
|
|
// return rec(n - 1) |
19 |
|
|
// [Previous line repeated 7 more times] |
20 |
|
|
// File "/home/runner/ShyCalculatingGraph/main.py", line 5, in rec |
21 |
|
|
// raise RuntimeError() |
22 |
|
|
// RuntimeError |
23 |
|
|
|
24 |
|
|
// Lython error messages |
25 |
|
|
// --------------------- |
26 |
|
|
// |
27 |
|
|
// Note that python stops at the first error while |
28 |
|
|
// lython can keep going and print more than one error. |
29 |
|
|
// |
30 |
|
|
// Parsing error messages (2) < Error kind |
31 |
|
|
// File "<replay buffer>", line 0 < File and line |
32 |
|
|
// |self.x = < code line |
33 |
|
|
// | ^ < Underline |
34 |
|
|
// SyntaxError: Expected an expression < Error message |
35 |
|
|
// |
36 |
|
|
// File "<replay buffer>", line 0 < File and line |
37 |
|
|
// |def __init__(self): < code line |
38 |
|
|
// | ^ < Underline |
39 |
|
|
// SyntaxError: Expected a body < Error message |
40 |
|
|
// |
41 |
|
|
|
42 |
|
|
struct BaseErrorPrinter { |
43 |
|
|
BaseErrorPrinter(std::ostream& out, class AbstractLexer* lexer = nullptr): |
44 |
|
731 |
out(out), lexer(lexer) // |
45 |
|
731 |
{} |
46 |
|
|
|
47 |
|
|
~BaseErrorPrinter() {} |
48 |
|
|
|
49 |
|
|
virtual void print(LythonException const& err) {} |
50 |
|
|
|
51 |
|
|
String get_filename() const; |
52 |
|
|
|
53 |
|
|
virtual String indentation(); |
54 |
|
|
virtual std::ostream& firstline(); |
55 |
|
|
virtual std::ostream& newline(); |
56 |
|
|
virtual std::ostream& errorline(); |
57 |
|
|
virtual std::ostream& codeline(); |
58 |
|
|
virtual void end(); |
59 |
|
|
|
60 |
|
|
void underline(class Token const& tok); |
61 |
|
|
void underline(struct CommonAttributes const& attr); |
62 |
|
|
|
63 |
|
|
// |
64 |
|
|
int indent = 1; |
65 |
|
|
class AbstractLexer* lexer = nullptr; |
66 |
|
|
std::ostream& out; |
67 |
|
|
}; |
68 |
|
|
|
69 |
|
|
struct StmtNode* get_parent_stmt(struct Node* node); |
70 |
|
|
|
71 |
|
|
} // namespace lython |
72 |
|
|
|