Bash++
Bash++ compiler internal documentation
BashppParser.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <memory>
10#include <variant>
11#include <stack>
12#include <vector>
13#include <AST/ASTNode.h>
14#include <AST/Nodes/Nodes.h>
15#include <error/ParserError.h>
16
17typedef void* yyscan_t;
18
19namespace AST {
20
28 private:
30 std::shared_ptr<AST::Program> m_program = nullptr;
31 bool current_command_can_receive_lvalues = true; // State variable needed by the parser
32
33 bool utf16_mode = false; // Whether to use UTF-16 mode for character counting
35
36 std::vector<ParserError> errors;
37
38 std::string input_file_path = "<stdin>";
39 std::vector<std::string> include_chain;
40
46
47 std::variant<std::string, FILE*, std::monostate> input_source = std::monostate{}; // Can be a file path, FILE*, or string contents
49
50 FILE* input_file = nullptr;
51
52 void _initialize_lexer();
53 void _destroy_lexer();
54 void _parse();
55 public:
56 BashppParser() = default;
57
58 void setUTF16Mode(bool enabled);
59 bool getUTF16Mode() const;
60
61 void setDisplayLexerOutput(bool enabled);
62 bool getDisplayLexerOutput() const;
63
64 void setInputFromFilePath(const std::string& file_path);
65 void setInputFromFilePtr(FILE* file_ptr, const std::string& file_path);
66 void setInputFromStringContents(const std::string& contents);
67
68 void setIncludeChain(const std::vector<std::string>& includes);
69
70 std::shared_ptr<AST::Program> program();
71
72 const std::vector<ParserError>& get_errors() const;
73};
74
75} // namespace AST
void * yyscan_t
Definition BashppParser.h:17
A driver class to wrap around the Bison-generated parser for Bash++. This class manages both the lexe...
Definition BashppParser.h:27
void setInputFromFilePath(const std::string &file_path)
Definition BashppParser.cpp:116
void setInputFromFilePtr(FILE *file_ptr, const std::string &file_path)
Definition BashppParser.cpp:122
void setDisplayLexerOutput(bool enabled)
Definition BashppParser.cpp:109
enum AST::BashppParser::InputType input_type
std::variant< std::string, FILE *, std::monostate > input_source
Definition BashppParser.h:47
std::vector< std::string > include_chain
Definition BashppParser.h:39
bool getUTF16Mode() const
Definition BashppParser.cpp:105
std::shared_ptr< AST::Program > m_program
Definition BashppParser.h:30
void _parse()
Definition BashppParser.cpp:83
void _destroy_lexer()
Definition BashppParser.cpp:73
std::string input_file_path
Definition BashppParser.h:38
std::shared_ptr< AST::Program > program()
Definition BashppParser.cpp:137
BashppParser()=default
bool current_command_can_receive_lvalues
Definition BashppParser.h:31
bool display_lexer_output
Definition BashppParser.h:34
void _initialize_lexer()
Definition BashppParser.cpp:28
void setIncludeChain(const std::vector< std::string > &includes)
Definition BashppParser.cpp:133
void setInputFromStringContents(const std::string &contents)
Definition BashppParser.cpp:128
InputType
Definition BashppParser.h:41
bool getDisplayLexerOutput() const
Definition BashppParser.cpp:112
const std::vector< ParserError > & get_errors() const
Definition BashppParser.cpp:144
std::string input_string_contents
Definition BashppParser.h:48
bool utf16_mode
Definition BashppParser.h:33
FILE * input_file
Definition BashppParser.h:50
void setUTF16Mode(bool enabled)
Definition BashppParser.cpp:102
std::vector< ParserError > errors
Definition BashppParser.h:36
yyscan_t lexer
Definition BashppParser.h:29
Definition AccessModifier.h:9