Skip to content

Commit a84666b

Browse files
committed
Add using statement for complex return types
1 parent 2e40118 commit a84666b

8 files changed

Lines changed: 25 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## 0.0.68 - 2021-09-29
11+
12+
### Changed
13+
14+
* Add using statement for complex return types
15+
1016
## 0.0.67 - 2021-09-04
1117

1218
### Added

lua_script_language.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file is part of LuaScript
33
* https://github.com/perbone/luascrip/
44
*
5-
* Copyright 2017-2021 Paulo Perbone
5+
* Copyright 2017-2021 Paulo Perbone
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -206,7 +206,7 @@ bool LuaScriptLanguage::validate(const String &p_script, int &r_line_error, int
206206
List<String> *r_functions, List<Warning> *r_warnings, Set<int> *r_safe_lines) const {
207207
print_debug("LuaScriptLanguage::validate( p_path = %s )", p_path.ascii().get_data());
208208

209-
std::unique_ptr<parser::ast::AbstractSyntaxTree> ast = parser.parse(p_script.ascii().get_data());
209+
parser::ast::AST ast = parser.parse(p_script.ascii().get_data());
210210

211211
if (ast->is_valid()) {
212212
r_functions->clear();

parser/ast/abstract_syntax_tree.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file is part of LuaScript
33
* https://github.com/perbone/luascrip/
44
*
5-
* Copyright 2017-2021 Paulo Perbone
5+
* Copyright 2017-2021 Paulo Perbone
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919

2020
#pragma once
2121

22+
#include <memory>
2223
#include <string>
2324
#include <string_view>
2425
#include <vector>
@@ -66,4 +67,6 @@ class AbstractSyntaxTree {
6667
bool valid;
6768
};
6869

70+
using AST = std::unique_ptr<ast::AbstractSyntaxTree>;
71+
6972
}; // namespace parser::ast

parser/ast/antlr_tree_walker.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file is part of LuaScript
33
* https://github.com/perbone/luascrip/
44
*
5-
* Copyright 2017-2021 Paulo Perbone
5+
* Copyright 2017-2021 Paulo Perbone
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -25,18 +25,20 @@
2525

2626
namespace parser::ast {
2727

28-
AntlrTreeWalker::AntlrTreeWalker() {
29-
}
28+
AntlrTreeWalker::AntlrTreeWalker() {}
3029

31-
AntlrTreeWalker::~AntlrTreeWalker() {
32-
}
30+
AntlrTreeWalker::~AntlrTreeWalker() {}
3331

34-
std::unique_ptr<AbstractSyntaxTree> AntlrTreeWalker::walk(const std::string_view chunk) {
32+
AST AntlrTreeWalker::walk(const std::string_view chunk) {
3533
antlr4::ANTLRInputStream input(chunk);
3634
generated::LuaLexer lexer(&input);
3735
antlr4::CommonTokenStream tokens(&lexer);
3836
generated::LuaParser parser(&tokens);
3937

38+
// We instantiate a new collection of methods each time we walk the tree
39+
// so we can move it to the returned AST at the end of the parser.
40+
// The fact that this collection is a data member is just for easy access
41+
// from within the listener functions.
4042
this->methods = Methods{};
4143

4244
antlr4::tree::ParseTree *chunk_tree = parser.chunk();

parser/ast/antlr_tree_walker.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file is part of LuaScript
33
* https://github.com/perbone/luascrip/
44
*
5-
* Copyright 2017-2021 Paulo Perbone
5+
* Copyright 2017-2021 Paulo Perbone
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323

2424
#include "../generated/LuaBaseListener.h"
2525

26-
#include <memory>
2726
#include <string_view>
2827

2928
namespace parser::ast {
@@ -33,7 +32,7 @@ class AntlrTreeWalker : public TreeWalker, generated::LuaBaseListener {
3332
AntlrTreeWalker();
3433
~AntlrTreeWalker();
3534

36-
std::unique_ptr<ast::AbstractSyntaxTree> walk(const std::string_view chunk) override;
35+
[[nodiscard]] AST walk(const std::string_view chunk) override;
3736

3837
virtual void exitStatFunction(generated::LuaParser::StatFunctionContext *ctx) override;
3938

parser/ast/tree_walker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class TreeWalker {
3030
public:
3131
virtual ~TreeWalker() = default;
3232

33-
virtual std::unique_ptr<AbstractSyntaxTree> walk(const std::string_view chunk) = 0;
33+
virtual AST walk(const std::string_view chunk) = 0;
3434
};
3535

3636
} // namespace parser::ast

parser/parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Parser::Parser() :
3030
Parser::~Parser() {
3131
}
3232

33-
std::unique_ptr<ast::AbstractSyntaxTree> Parser::parse(const std::string_view chunk) const {
33+
ast::AST Parser::parse(const std::string_view chunk) const {
3434
return treeWalker->walk(chunk);
3535
}
3636

parser/parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Parser {
3131
Parser();
3232
~Parser();
3333

34-
std::unique_ptr<ast::AbstractSyntaxTree> parse(const std::string_view chunk) const;
34+
ast::AST parse(const std::string_view chunk) const;
3535

3636
private:
3737
std::unique_ptr<ast::TreeWalker> treeWalker;

0 commit comments

Comments
 (0)