hoshi-lang dev
Yet another programming language
Loading...
Searching...
No Matches
formatter.hpp
Go to the documentation of this file.
1//
2// Created by XIaokang00010 on 2025/2/16.
3//
4#ifndef HOSHI_LANG_FORMATTER_HPP
5#define HOSHI_LANG_FORMATTER_HPP
6
8#include "lexer.hpp"
9#include <share/def.hpp>
10
11namespace yoi {
12 struct FormatOption {
13 enum class IndentType {
14 Space,
15 Tab
17 size_t indentSize{4};
22 size_t maxWidth{80};
23
24 FormatOption() = default;
25
26 FormatOption(IndentType indentType, size_t indentSize, BraceType braceType, size_t maxWidth = 80);
27 };
28
29 void formatToken(std::wostream &os, FormatOption option, const lexer::token &token);
30
31 class Formatter {
32 public:
34 std::wostream &os;
36
37 Formatter(std::wostream &os, FormatOption option);
38
40
41 private:
42 size_t indentLevel{0};
43 size_t currentColumn{0};
44 size_t lastCommentIdx{0};
45 uint64_t lastLine{0};
46 void indent();
47 void newLine();
48 void write(const yoi::wstr &s);
49 bool printComments(AST *node);
50 bool printComments(uint64_t line, uint64_t col);
51 bool willFit(invocationArguments *node);
52
53 public:
54 void format(const lexer::token &token);
55 void format(basicLiterals *node);
56
57 void format(identifier *node);
58
60
61 void format(defTemplateArgSpec *node);
62
63 void format(defTemplateArg *node);
64
65 void format(templateArgSpec *node);
66
67 void format(templateArg *node);
68
69 void format(invocationArguments *node);
70
71 void format(definitionArguments *node);
72
73 void format(funcTypeSpec *node);
74
75 void format(typeSpec *node);
76
77 void format(decltypeExpr *node);
78
79 void format(subscript *node);
80
82
84
85 void format(subscriptExpr *node);
86
87 void format(memberExpr *node);
88
89 void format(primary *node);
90
91 void format(uniqueExpr *node);
92
93 void format(mulExpr *node);
94
95 void format(addExpr *node);
96
97 void format(shiftExpr *node);
98
100
101 void format(equalityExpr *node);
102
103 void format(andExpr *node);
104
106
108
110
112
113 void format(rExpr *node);
114
115 void format(codeBlock *node);
116
117 void format(useStmt *node);
118
119 void format(funcDefStmt *node);
120
121 void format(interfaceDefInnerPair *node);
122
123 void format(interfaceDefInner *node);
124
125 void format(interfaceDefStmt *node);
126
127 void format(structDefInnerPair *node);
128
129 void format(structDefInner *node);
130
131 void format(structDefStmt *node);
132
133 void format(dataStructDefStmt *node);
134
135 void format(implInnerPair *node);
136
137 void format(implInner *node);
138
139 void format(implStmt *node);
140
141 void format(letAssignmentPair *node);
142
143 void format(letStmt *node);
144
145 void format(globalStmt *node);
146
147 void format(ifStmt *node);
148
149 void format(whileStmt *node);
150
151 void format(forStmt *node);
152
153 void format(forEachStmt *node);
154
155 void format(returnStmt *node);
156
157 void format(continueStmt *node);
158
159 void format(breakStmt *node);
160
161 void format(inCodeBlockStmt *node);
162
163 void format(leftExpr *node);
164
166
167 void format(exportDecl *node);
168
169 void format(importDecl *node);
170
171 void format(importInner *node);
172
173 void format(throwStmt *node);
174
175 void format(catchParam *node);
176
177 void format(tryCatchStmt *node);
178
179 void format(dynCastExpression *node);
180
181 void format(typeIdExpression *node);
182
183 void format(newExpression *node);
184
185 void format(abstractExpr *node);
186
187 void format(lambdaExpr *node);
188
190
191 void format(marcoPair *node);
192
193 void format(marcoDescriptor *node);
194
195 void format(typeAliasStmt *node);
196
197 void format(finalizerDef *node);
198
199 void format(finalizerDecl *node);
200
201 void format(funcExpr *node);
202
203 void format(letAssignmentPairLHS *node);
204
205 void format(enumerationDefinition *node);
206
207 void format(enumerationPair *node);
208
209 void format(bracedInitalizerList *node);
210
211 void format(hoshiModule *node);
212
213 void format(innerMethodDecl *node);
214
215 void format(innerMethodDef *node);
216
217 void format(constructorDecl *node);
218
219 void format(constructorDef *node);
220
221 void format(yieldStmt *node);
222
223 void format(conceptStmt *node);
224
225 void format(satisfyStmt *node);
226
227 void format(satisfyClause *node);
228
229 void format(conceptDefinition *node);
230 };
231}
232
233#endif
FormatOption option
Definition formatter.hpp:33
void format(relationalExpr *node)
void format(logicalAndExpr *node)
size_t currentColumn
Definition formatter.hpp:43
void format(mulExpr *node)
size_t lastCommentIdx
Definition formatter.hpp:44
void format(const lexer::token &token)
void format(logicalOrExpr *node)
void format(shiftExpr *node)
void format(andExpr *node)
vec< lexer::Comment > comments
Definition formatter.hpp:35
void format(inclusiveExpr *node)
bool willFit(invocationArguments *node)
void write(const yoi::wstr &s)
std::wostream & os
Definition formatter.hpp:34
void format(equalityExpr *node)
uint64_t lastLine
Definition formatter.hpp:45
bool printComments(AST *node)
void format(addExpr *node)
size_t indentLevel
Definition formatter.hpp:42
void format(exclusiveExpr *node)
std::vector< t > vec
Definition def.hpp:53
void formatToken(std::wostream &os, FormatOption option, const lexer::token &token)
Definition formatter.cpp:14
std::wstring wstr
Definition def.hpp:48
enum yoi::FormatOption::IndentType Space
enum yoi::FormatOption::BraceType Attached
FormatOption()=default