Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Ast/include/Luau/ParseResult.h
2727 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include "Luau/Common.h"
5
#include "Luau/Location.h"
6
#include "Luau/Lexer.h"
7
#include "Luau/StringUtils.h"
8
9
namespace Luau
10
{
11
12
class AstStatBlock;
13
class CstNode;
14
15
class ParseError : public std::exception
16
{
17
public:
18
ParseError(const Location& location, std::string message);
19
20
const char* what() const throw() override;
21
22
const Location& getLocation() const;
23
const std::string& getMessage() const;
24
25
static LUAU_NORETURN void raise(const Location& location, const char* format, ...) LUAU_PRINTF_ATTR(2, 3);
26
27
private:
28
Location location;
29
std::string message;
30
};
31
32
class ParseErrors : public std::exception
33
{
34
public:
35
ParseErrors(std::vector<ParseError> errors);
36
37
const char* what() const throw() override;
38
39
const std::vector<ParseError>& getErrors() const;
40
41
private:
42
std::vector<ParseError> errors;
43
std::string message;
44
};
45
46
struct HotComment
47
{
48
bool header;
49
Location location;
50
std::string content;
51
};
52
53
struct Comment
54
{
55
Lexeme::Type type; // Comment, BlockComment, or BrokenComment
56
Location location;
57
};
58
59
using CstNodeMap = DenseHashMap<AstNode*, CstNode*>;
60
61
struct ParseResult
62
{
63
AstStatBlock* root;
64
size_t lines = 0;
65
66
std::vector<HotComment> hotcomments;
67
std::vector<ParseError> errors;
68
69
std::vector<Comment> commentLocations;
70
71
CstNodeMap cstNodeMap{nullptr};
72
};
73
74
template<typename Node>
75
struct ParseNodeResult
76
{
77
Node* root;
78
size_t lines = 0;
79
80
std::vector<HotComment> hotcomments;
81
std::vector<ParseError> errors;
82
83
std::vector<Comment> commentLocations;
84
85
CstNodeMap cstNodeMap{nullptr};
86
};
87
88
inline constexpr const char* kParseNameError = "%error-id%";
89
90
} // namespace Luau
91
92