Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bbfbbc8
feat: add parser interfaces and classes
biqiboqi Oct 22, 2025
50ae1f1
fix: clang issues fixed
biqiboqi Oct 23, 2025
4ac3bd2
refactor: SPACES
biqiboqi Oct 23, 2025
dd4dd26
refactor: IState forward declaration fix
biqiboqi Oct 23, 2025
771ef20
feat: afterreview fixes
biqiboqi Nov 2, 2025
6003896
fix: fix branch class
biqiboqi Nov 2, 2025
cd624eb
fix: fix branch class and some lil mistakes
biqiboqi Nov 2, 2025
1b4c52a
fix: I HATE !$@$!%#@$!@ CI/CD WITH !*@#^&!(@&#^ CODESTYLE
biqiboqi Nov 2, 2025
1094bf4
fix: fixed SafeCall
biqiboqi Nov 2, 2025
0d66cef
feat: add ast nodes implementation
biqiboqi Nov 9, 2025
e191c32
feat: add ast visitors and OpTags
biqiboqi Nov 9, 2025
aec527f
feat: add contexts
biqiboqi Nov 9, 2025
cadbe0e
feat: add types
biqiboqi Nov 9, 2025
2a390fe
feat: add diagnostics
biqiboqi Nov 9, 2025
1850ca9
feat: add LintVisitor
biqiboqi Nov 9, 2025
0a2a9d7
feat: add vector token stream
biqiboqi Nov 9, 2025
f675de4
feat: add vector token stream
biqiboqi Nov 9, 2025
0a0a249
fix: deleted accidentally added file
biqiboqi Nov 9, 2025
ceef53b
Merge branch 'master' into parser
bialger Nov 9, 2025
82816b8
fix: update include directive for MethodDecl.cpp
bialger Nov 9, 2025
4e4f497
refactor: add namespace closure to parser files and update header guards
bialger Nov 9, 2025
5ec413a
refactor: optimize Diagnostic methods by using move semantics and add…
bialger Nov 9, 2025
555ea73
feat: add builders for ast nodes, add SourceSpan in ast nodes
biqiboqi Nov 23, 2025
15dbbfc
feat: implement token matchers
biqiboqi Nov 23, 2025
8aab101
feat: add const to states, implemented ParserFSM
biqiboqi Nov 23, 2025
938f642
feat: add pratt parser initial and ast factory
biqiboqi Nov 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/parser/IParser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef IPARSER_HPP_
#define IPARSER_HPP_

#include <memory>

#include "ast/nodes/decls/Module.hpp"
#include "diagnostics/IDiagnosticSink.hpp"
#include "tokens/token_streams/ITokenStream.hpp"

class IParser {
public:
virtual ~IParser() = default;
virtual std::unique_ptr<Module> Parse(ITokenStream& ts, IDiagnosticSink& diags) = 0;
};

#endif // IPARSER_HPP_
1 change: 1 addition & 0 deletions lib/parser/ParserFsm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "ParserFsm.hpp"
24 changes: 24 additions & 0 deletions lib/parser/ParserFsm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef PARSERFSM_HPP_
#define PARSERFSM_HPP_

#include <memory>

#include "IParser.hpp"

class ParserFsm : public IParser {
public:
ParserFsm(std::unique_ptr<class IExpressionParser> expr,
std::unique_ptr<class ITypeParser> typep,
std::unique_ptr<class 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_;
};

#endif // PARSERFSM_HPP_
96 changes: 96 additions & 0 deletions lib/parser/ast/AstVisitor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#ifndef ASTVISITOR_HPP_
#define ASTVISITOR_HPP_

class Module;
class FunctionDecl;
class ClassDecl;
class InterfaceDecl;
class TypeAliasDecl;
class GlobalVarDecl;
class FieldDecl;
class StaticFieldDecl;
class MethodDecl;
class CallDecl;
class DestructorDecl;

class Block;
class VarDeclStmt;
class ExprStmt;
class ReturnStmt;
class BreakStmt;
class ContinueStmt;
class IfStmt;
class WhileStmt;
class ForStmt;
class UnsafeBlock;

class Binary;
class Unary;
class Assign;
class Call;
class FieldAccess;
class IndexAccess;
class NamespaceRef;
class SafeCall;
class Elvis;
class CastAs;
class TypeTestIs;
class IdentRef;
class IntLit;
class FloatLit;
class StringLit;
class CharLit;
class BoolLit;
class NullLit;

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(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;
};

#endif // ASTVISITOR_HPP_
93 changes: 93 additions & 0 deletions lib/parser/ast/IAstFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#ifndef IASTFACTORY_HPP_
#define 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/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"

class IAstFactory {
public:
virtual ~IAstFactory() = default;

virtual std::unique_ptr<Module> MakeModule() = 0;

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<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;
};

#endif // IASTFACTORY_HPP_
13 changes: 13 additions & 0 deletions lib/parser/ast/nodes/base/AstNode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef ASTNODE_HPP_
#define ASTNODE_HPP_

class AstVisitor; // forward

class AstNode {
public:
virtual ~AstNode() = default;

virtual void Accept(AstVisitor& v) = 0;
};

#endif // ASTNODE_HPP_
8 changes: 8 additions & 0 deletions lib/parser/ast/nodes/base/Decl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef DECL_HPP_
#define DECL_HPP_

#include "AstNode.hpp"

class Decl : public AstNode {};

#endif // DECL_HPP_
8 changes: 8 additions & 0 deletions lib/parser/ast/nodes/base/Expr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef EXPR_HPP_
#define EXPR_HPP_

#include "AstNode.hpp"

class Expr : public AstNode {};

#endif // EXPR_HPP_
8 changes: 8 additions & 0 deletions lib/parser/ast/nodes/base/Stmt.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef STMT_HPP_
#define STMT_HPP_

#include "AstNode.hpp"

class Stmt : public AstNode {};

#endif // STMT_HPP_
1 change: 1 addition & 0 deletions lib/parser/ast/nodes/class_members/CallDecl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "CallDecl.hpp"
22 changes: 22 additions & 0 deletions lib/parser/ast/nodes/class_members/CallDecl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef CALLDECL_HPP_
#define CALLDECL_HPP_

#include <memory>
#include <vector>

#include "lib/parser/ast/nodes/base/Decl.hpp"
#include "lib/parser/types/TypeReference.hpp"

class Param;
class CallDecl : public Decl {
public:
void Accept(AstVisitor& v) override;

private:
bool is_public_ = true;
std::vector<Param> params_;
std::unique_ptr<TypeReference> ret_type_;
std::unique_ptr<class Block> body_;
};

#endif // CALLDECL_HPP_
1 change: 1 addition & 0 deletions lib/parser/ast/nodes/class_members/DestructorDecl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "DestructorDecl.hpp"
18 changes: 18 additions & 0 deletions lib/parser/ast/nodes/class_members/DestructorDecl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef DESTRUCTORDECL_HPP_
#define DESTRUCTORDECL_HPP_

#include <memory>

#include "lib/parser/ast/nodes/base/Decl.hpp"
#include "lib/parser/ast/nodes/stmts/Block.hpp"

class DestructorDecl : public Decl {
public:
void Accept(AstVisitor& v) override;

private:
bool is_public_ = true;
std::unique_ptr<Block> body_;
};

#endif // DESTRUCTORDECL_HPP_
1 change: 1 addition & 0 deletions lib/parser/ast/nodes/class_members/FieldDecl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "FieldDecl.hpp"
22 changes: 22 additions & 0 deletions lib/parser/ast/nodes/class_members/FieldDecl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef FIELDDECL_HPP_
#define FIELDDECL_HPP_

#include <memory>
#include <string>

#include "lib/parser/ast/nodes/base/Decl.hpp"
#include "lib/parser/types/TypeReference.hpp"

class FieldDecl : public Decl {
public:
void Accept(AstVisitor& v) override;

private:
bool is_public_ = true;
bool is_var_ = false;
std::string name_;
TypeReference type_;
std::unique_ptr<class Expr> init_; // optional
};

#endif // FIELDDECL_HPP_
1 change: 1 addition & 0 deletions lib/parser/ast/nodes/class_members/MethodDecl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "MethodDecl.hpp"
30 changes: 30 additions & 0 deletions lib/parser/ast/nodes/class_members/MethodDecl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef METHODDECL_HPP_
#define METHODDECL_HPP_

#include <memory>
#include <string>
#include <vector>

#include "lib/parser/ast/nodes/base/Decl.hpp"
#include "lib/parser/ast/nodes/stmts/Block.hpp"
#include "lib/parser/types/Param.hpp"
#include "lib/parser/types/TypeReference.hpp"

class MethodDecl : public Decl {
public:

void Accept(AstVisitor& v) override;

private:
bool is_public_ = true;
bool is_override_ = false;
bool is_static_ = false;
bool is_pure_ = false;

std::string name;
std::vector<Param> params;
std::unique_ptr<TypeReference> ret_type;
std::unique_ptr<Block> body; // optional
};

#endif // METHODDECL_HPP_
1 change: 1 addition & 0 deletions lib/parser/ast/nodes/class_members/StaticFieldDecl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "StaticFieldDecl.hpp"
Loading
Loading