generated from bialger/cpp_tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Parser!! #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
biqiboqi
wants to merge
22
commits into
master
Choose a base branch
from
parser
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Parser!! #20
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bbfbbc8
feat: add parser interfaces and classes
biqiboqi 50ae1f1
fix: clang issues fixed
biqiboqi 4ac3bd2
refactor: SPACES
biqiboqi dd4dd26
refactor: IState forward declaration fix
biqiboqi 771ef20
feat: afterreview fixes
biqiboqi 6003896
fix: fix branch class
biqiboqi cd624eb
fix: fix branch class and some lil mistakes
biqiboqi 1b4c52a
fix: I HATE !$@$!%#@$!@ CI/CD WITH !*@#^&!(@&#^ CODESTYLE
biqiboqi 1094bf4
fix: fixed SafeCall
biqiboqi 0d66cef
feat: add ast nodes implementation
biqiboqi e191c32
feat: add ast visitors and OpTags
biqiboqi aec527f
feat: add contexts
biqiboqi cadbe0e
feat: add types
biqiboqi 2a390fe
feat: add diagnostics
biqiboqi 1850ca9
feat: add LintVisitor
biqiboqi 0a2a9d7
feat: add vector token stream
biqiboqi f675de4
feat: add vector token stream
biqiboqi 0a0a249
fix: deleted accidentally added file
biqiboqi ceef53b
Merge branch 'master' into parser
bialger 82816b8
fix: update include directive for MethodDecl.cpp
bialger 4e4f497
refactor: add namespace closure to parser files and update header guards
bialger 5ec413a
refactor: optimize Diagnostic methods by using move semantics and add…
bialger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #ifndef PARSER_IPARSER_HPP_ | ||
| #define PARSER_IPARSER_HPP_ | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "ast/nodes/decls/Module.hpp" | ||
| #include "diagnostics/IDiagnosticSink.hpp" | ||
| #include "tokens/token_streams/ITokenStream.hpp" | ||
|
|
||
| namespace ovum::compiler::parser { | ||
|
|
||
| class IParser { | ||
| public: | ||
| virtual ~IParser() = default; | ||
| virtual std::unique_ptr<Module> Parse(ITokenStream& ts, IDiagnosticSink& diags) = 0; | ||
| }; | ||
|
|
||
| } // namespace ovum::compiler::parser | ||
|
|
||
| #endif // PARSER_IPARSER_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #include "ParserFsm.hpp" | ||
|
|
||
| namespace ovum::compiler::parser {} // namespace ovum::compiler::parser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #ifndef PARSER_PARSERFSM_HPP_ | ||
| #define PARSER_PARSERFSM_HPP_ | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "IParser.hpp" | ||
| #include "ast/IAstFactory.hpp" | ||
| #include "pratt/IExpressionParser.hpp" | ||
| #include "type_parser/ITypeParser.hpp" | ||
|
|
||
| namespace ovum::compiler::parser { | ||
|
|
||
| class ParserFsm : public IParser { | ||
| public: | ||
| ParserFsm(std::unique_ptr<IExpressionParser> expr, | ||
| std::unique_ptr<ITypeParser> typep, | ||
| std::unique_ptr<IAstFactory> factory); | ||
|
|
||
| ~ParserFsm() override = default; | ||
|
|
||
| std::unique_ptr<Module> Parse(ITokenStream& ts, IDiagnosticSink& diags) override; | ||
|
|
||
| private: | ||
| std::unique_ptr<IExpressionParser> expr_parser_; | ||
| std::unique_ptr<ITypeParser> type_parser_; | ||
| std::unique_ptr<IAstFactory> factory_; | ||
| }; | ||
|
|
||
| } // namespace ovum::compiler::parser | ||
|
|
||
| #endif // PARSER_PARSERFSM_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| #ifndef PARSER_ASTVISITOR_HPP_ | ||
| #define PARSER_ASTVISITOR_HPP_ | ||
|
|
||
| #include "nodes/class_members/CallDecl.hpp" | ||
| #include "nodes/class_members/DestructorDecl.hpp" | ||
| #include "nodes/class_members/FieldDecl.hpp" | ||
| #include "nodes/class_members/MethodDecl.hpp" | ||
| #include "nodes/class_members/StaticFieldDecl.hpp" | ||
| #include "nodes/decls/ClassDecl.hpp" | ||
| #include "nodes/decls/FunctionDecl.hpp" | ||
| #include "nodes/decls/GlobalVarDecl.hpp" | ||
| #include "nodes/decls/InterfaceDecl.hpp" | ||
| #include "nodes/decls/Module.hpp" | ||
| #include "nodes/decls/TypeAliasDecl.hpp" | ||
| #include "nodes/exprs/Assign.hpp" | ||
| #include "nodes/exprs/Binary.hpp" | ||
| #include "nodes/exprs/Call.hpp" | ||
| #include "nodes/exprs/CastAs.hpp" | ||
| #include "nodes/exprs/Elvis.hpp" | ||
| #include "nodes/exprs/FieldAccess.hpp" | ||
| #include "nodes/exprs/IdentRef.hpp" | ||
| #include "nodes/exprs/IndexAccess.hpp" | ||
| #include "nodes/exprs/NamespaceRef.hpp" | ||
| #include "nodes/exprs/SafeCall.hpp" | ||
| #include "nodes/exprs/TypeTestIs.hpp" | ||
| #include "nodes/exprs/Unary.hpp" | ||
| #include "nodes/exprs/literals/BoolLit.hpp" | ||
| #include "nodes/exprs/literals/CharLit.hpp" | ||
| #include "nodes/exprs/literals/FloatLit.hpp" | ||
| #include "nodes/exprs/literals/IntLit.hpp" | ||
| #include "nodes/exprs/literals/NullLit.hpp" | ||
| #include "nodes/exprs/literals/StringLit.hpp" | ||
| #include "nodes/stmts/BreakStmt.hpp" | ||
| #include "nodes/stmts/ContinueStmt.hpp" | ||
| #include "nodes/stmts/ExprStmt.hpp" | ||
| #include "nodes/stmts/ForStmt.hpp" | ||
| #include "nodes/stmts/IfStmt.hpp" | ||
| #include "nodes/stmts/ReturnStmt.hpp" | ||
| #include "nodes/stmts/UnsafeBlock.hpp" | ||
| #include "nodes/stmts/VarDeclStmt.hpp" | ||
| #include "nodes/stmts/WhileStmt.hpp" | ||
|
|
||
| namespace ovum::compiler::parser { | ||
|
|
||
| class AstVisitor { | ||
| public: | ||
| virtual ~AstVisitor() = default; | ||
|
|
||
| // Decls | ||
| virtual void Visit(Module&) = 0; | ||
| virtual void Visit(FunctionDecl&) = 0; | ||
| virtual void Visit(ClassDecl&) = 0; | ||
| virtual void Visit(InterfaceMethod&) = 0; | ||
| virtual void Visit(InterfaceDecl&) = 0; | ||
| virtual void Visit(TypeAliasDecl&) = 0; | ||
| virtual void Visit(GlobalVarDecl&) = 0; | ||
| virtual void Visit(FieldDecl&) = 0; | ||
| virtual void Visit(StaticFieldDecl&) = 0; | ||
| virtual void Visit(MethodDecl&) = 0; | ||
| virtual void Visit(CallDecl&) = 0; | ||
| virtual void Visit(DestructorDecl&) = 0; | ||
|
|
||
| // Stmts | ||
| virtual void Visit(Block&) = 0; | ||
| virtual void Visit(VarDeclStmt&) = 0; | ||
| virtual void Visit(ExprStmt&) = 0; | ||
| virtual void Visit(ReturnStmt&) = 0; | ||
| virtual void Visit(BreakStmt&) = 0; | ||
| virtual void Visit(ContinueStmt&) = 0; | ||
| virtual void Visit(IfStmt&) = 0; | ||
| virtual void Visit(WhileStmt&) = 0; | ||
| virtual void Visit(ForStmt&) = 0; | ||
| virtual void Visit(UnsafeBlock&) = 0; | ||
|
|
||
| // Exprs | ||
| virtual void Visit(Binary&) = 0; | ||
| virtual void Visit(Unary&) = 0; | ||
| virtual void Visit(Assign&) = 0; | ||
| virtual void Visit(Call&) = 0; | ||
| virtual void Visit(FieldAccess&) = 0; | ||
| virtual void Visit(IndexAccess&) = 0; | ||
| virtual void Visit(NamespaceRef&) = 0; | ||
| virtual void Visit(SafeCall&) = 0; | ||
| virtual void Visit(Elvis&) = 0; | ||
| virtual void Visit(CastAs&) = 0; | ||
| virtual void Visit(TypeTestIs&) = 0; | ||
| virtual void Visit(IdentRef&) = 0; | ||
| virtual void Visit(IntLit&) = 0; | ||
| virtual void Visit(FloatLit&) = 0; | ||
| virtual void Visit(StringLit&) = 0; | ||
| virtual void Visit(CharLit&) = 0; | ||
| virtual void Visit(BoolLit&) = 0; | ||
| virtual void Visit(NullLit&) = 0; | ||
| }; | ||
|
|
||
| } // namespace ovum::compiler::parser | ||
|
|
||
| #endif // PARSER_ASTVISITOR_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #ifndef PARSER_IASTFACTORY_HPP_ | ||
| #define PARSER_IASTFACTORY_HPP_ | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "nodes/class_members/CallDecl.hpp" | ||
| #include "nodes/class_members/DestructorDecl.hpp" | ||
| #include "nodes/class_members/FieldDecl.hpp" | ||
| #include "nodes/class_members/MethodDecl.hpp" | ||
| #include "nodes/class_members/StaticFieldDecl.hpp" | ||
| #include "nodes/decls/ClassDecl.hpp" | ||
| #include "nodes/decls/FunctionDecl.hpp" | ||
| #include "nodes/decls/GlobalVarDecl.hpp" | ||
| #include "nodes/decls/InterfaceDecl.hpp" | ||
| #include "nodes/decls/TypeAliasDecl.hpp" | ||
| #include "nodes/exprs/Assign.hpp" | ||
| #include "nodes/exprs/Binary.hpp" | ||
| #include "nodes/exprs/Call.hpp" | ||
| #include "nodes/exprs/CastAs.hpp" | ||
| #include "nodes/exprs/Elvis.hpp" | ||
| #include "nodes/exprs/FieldAccess.hpp" | ||
| #include "nodes/exprs/IdentRef.hpp" | ||
| #include "nodes/exprs/IndexAccess.hpp" | ||
| #include "nodes/exprs/NamespaceRef.hpp" | ||
| #include "nodes/exprs/SafeCall.hpp" | ||
| #include "nodes/exprs/TypeTestIs.hpp" | ||
| #include "nodes/exprs/Unary.hpp" | ||
| #include "nodes/exprs/literals/BoolLit.hpp" | ||
| #include "nodes/exprs/literals/CharLit.hpp" | ||
| #include "nodes/exprs/literals/FloatLit.hpp" | ||
| #include "nodes/exprs/literals/IntLit.hpp" | ||
| #include "nodes/exprs/literals/NullLit.hpp" | ||
| #include "nodes/exprs/literals/StringLit.hpp" | ||
| #include "nodes/stmts/BreakStmt.hpp" | ||
| #include "nodes/stmts/ContinueStmt.hpp" | ||
| #include "nodes/stmts/ExprStmt.hpp" | ||
| #include "nodes/stmts/ForStmt.hpp" | ||
| #include "nodes/stmts/IfStmt.hpp" | ||
| #include "nodes/stmts/ReturnStmt.hpp" | ||
| #include "nodes/stmts/UnsafeBlock.hpp" | ||
| #include "nodes/stmts/VarDeclStmt.hpp" | ||
| #include "nodes/stmts/WhileStmt.hpp" | ||
|
|
||
| namespace ovum::compiler::parser { | ||
|
|
||
| class IAstFactory { | ||
| public: | ||
| virtual ~IAstFactory() = default; | ||
|
|
||
| virtual std::unique_ptr<FunctionDecl> MakeFunction() = 0; | ||
| virtual std::unique_ptr<ClassDecl> MakeClass() = 0; | ||
| virtual std::unique_ptr<InterfaceDecl> MakeInterface() = 0; | ||
| virtual std::unique_ptr<InterfaceMethod> MakeInterfaceMethod() = 0; | ||
| virtual std::unique_ptr<TypeAliasDecl> MakeTypeAlias() = 0; | ||
| virtual std::unique_ptr<GlobalVarDecl> MakeGlobalVar() = 0; | ||
|
|
||
| virtual std::unique_ptr<FieldDecl> MakeField() = 0; | ||
| virtual std::unique_ptr<StaticFieldDecl> MakeStaticField() = 0; | ||
| virtual std::unique_ptr<MethodDecl> MakeMethod() = 0; | ||
| virtual std::unique_ptr<CallDecl> MakeCallDecl() = 0; | ||
| virtual std::unique_ptr<DestructorDecl> MakeDestructor() = 0; | ||
|
|
||
| virtual std::unique_ptr<Block> MakeBlock() = 0; | ||
| virtual std::unique_ptr<VarDeclStmt> MakeVarDeclStmt() = 0; | ||
| virtual std::unique_ptr<ExprStmt> MakeExprStmt() = 0; | ||
| virtual std::unique_ptr<ReturnStmt> MakeReturnStmt() = 0; | ||
| virtual std::unique_ptr<BreakStmt> MakeBreakStmt() = 0; | ||
| virtual std::unique_ptr<ContinueStmt> MakeContinueStmt() = 0; | ||
| virtual std::unique_ptr<IfStmt> MakeIfStmt() = 0; | ||
| virtual std::unique_ptr<WhileStmt> MakeWhileStmt() = 0; | ||
| virtual std::unique_ptr<ForStmt> MakeForStmt() = 0; | ||
| virtual std::unique_ptr<UnsafeBlock> MakeUnsafeBlock() = 0; | ||
|
|
||
| virtual std::unique_ptr<Binary> MakeBinary(const IBinaryOpTag& op) = 0; | ||
| virtual std::unique_ptr<Unary> MakeUnary(const IUnaryOpTag& op) = 0; | ||
| virtual std::unique_ptr<Assign> MakeAssign(const IAssignOpTag& op) = 0; | ||
| virtual std::unique_ptr<Call> MakeCall() = 0; | ||
| virtual std::unique_ptr<FieldAccess> MakeFieldAccess() = 0; | ||
| virtual std::unique_ptr<IndexAccess> MakeIndexAccess() = 0; | ||
| virtual std::unique_ptr<NamespaceRef> MakeNamespaceRef() = 0; | ||
| virtual std::unique_ptr<SafeCall> MakeSafeCall() = 0; | ||
| virtual std::unique_ptr<Elvis> MakeElvis() = 0; | ||
| virtual std::unique_ptr<CastAs> MakeCastAs() = 0; | ||
| virtual std::unique_ptr<TypeTestIs> MakeTypeTestIs() = 0; | ||
| virtual std::unique_ptr<IdentRef> MakeIdent(std::string name) = 0; | ||
| virtual std::unique_ptr<IntLit> MakeInt(long long v) = 0; | ||
| virtual std::unique_ptr<FloatLit> MakeFloat(long double v) = 0; | ||
| virtual std::unique_ptr<StringLit> MakeString(std::u32string v) = 0; | ||
| virtual std::unique_ptr<CharLit> MakeChar(char32_t v) = 0; | ||
| virtual std::unique_ptr<BoolLit> MakeBool(bool v) = 0; | ||
| virtual std::unique_ptr<NullLit> MakeNull() = 0; | ||
| }; | ||
|
|
||
| } // namespace ovum::compiler::parser | ||
|
|
||
| #endif // PARSER_IASTFACTORY_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #ifndef PARSER_ASTNODE_HPP_ | ||
| #define PARSER_ASTNODE_HPP_ | ||
|
|
||
| namespace ovum::compiler::parser { | ||
|
|
||
| class AstVisitor; // forward | ||
|
|
||
| class AstNode { | ||
| public: | ||
| virtual ~AstNode() = default; | ||
|
|
||
| // TODO: add positions...... | ||
|
|
||
| virtual void Accept(AstVisitor& visitor) = 0; | ||
| }; | ||
|
|
||
| } // namespace ovum::compiler::parser | ||
|
|
||
| #endif // PARSER_ASTNODE_HPP_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #ifndef PARSER_DECL_HPP_ | ||
| #define PARSER_DECL_HPP_ | ||
|
|
||
| #include "AstNode.hpp" | ||
|
|
||
| namespace ovum::compiler::parser { | ||
|
|
||
| class Decl : public AstNode {}; | ||
|
|
||
| } // namespace ovum::compiler::parser | ||
|
|
||
| #endif // PARSER_DECL_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #ifndef PARSER_EXPR_HPP_ | ||
| #define PARSER_EXPR_HPP_ | ||
|
|
||
| #include "AstNode.hpp" | ||
|
|
||
| namespace ovum::compiler::parser { | ||
|
|
||
| class Expr : public AstNode {}; | ||
|
|
||
| } // namespace ovum::compiler::parser | ||
|
|
||
| #endif // PARSER_EXPR_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #ifndef PARSER_STMT_HPP_ | ||
| #define PARSER_STMT_HPP_ | ||
|
|
||
| #include "AstNode.hpp" | ||
|
|
||
| namespace ovum::compiler::parser { | ||
|
|
||
| class Stmt : public AstNode {}; | ||
|
|
||
| } // namespace ovum::compiler::parser | ||
|
|
||
| #endif // PARSER_STMT_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #include "lib/parser/ast/nodes/class_members/CallDecl.hpp" | ||
|
|
||
| #include "lib/parser/ast/AstVisitor.hpp" | ||
|
|
||
| #include <utility> | ||
|
|
||
| namespace ovum::compiler::parser { | ||
|
|
||
| void CallDecl::Accept(AstVisitor& visitor) { | ||
| visitor.Visit(*this); | ||
| } | ||
|
|
||
| bool CallDecl::IsPublic() const noexcept { | ||
| return is_public_; | ||
| } | ||
|
|
||
| void CallDecl::SetPublic(bool v) noexcept { | ||
| is_public_ = v; | ||
| } | ||
|
|
||
| const std::vector<Param>& CallDecl::Params() const noexcept { | ||
| return params_; | ||
| } | ||
|
|
||
| std::vector<Param>& CallDecl::MutableParams() noexcept { | ||
| return params_; | ||
| } | ||
|
|
||
| void CallDecl::AddParam(Param param) { | ||
| params_.emplace_back(std::move(param)); | ||
| } | ||
|
|
||
| const TypeReference* CallDecl::ReturnType() const noexcept { | ||
| return ret_type_.get(); | ||
| } | ||
|
|
||
| TypeReference* CallDecl::MutableReturnType() noexcept { | ||
| return ret_type_.get(); | ||
| } | ||
|
|
||
| void CallDecl::SetReturnType(std::unique_ptr<TypeReference> type) { | ||
| ret_type_ = std::move(type); | ||
| } | ||
|
|
||
| std::unique_ptr<TypeReference> CallDecl::ReleaseReturnType() { | ||
| return std::move(ret_type_); | ||
| } | ||
|
|
||
| const Block* CallDecl::Body() const noexcept { | ||
| return body_.get(); | ||
| } | ||
|
|
||
| Block* CallDecl::MutableBody() noexcept { | ||
| return body_.get(); | ||
| } | ||
|
|
||
| void CallDecl::SetBody(std::unique_ptr<Block> block) { | ||
| body_ = std::move(block); | ||
| } | ||
|
|
||
| std::unique_ptr<Block> CallDecl::ReleaseBody() { | ||
| return std::move(body_); | ||
| } | ||
|
|
||
| } // namespace ovum::compiler::parser |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add said positions