|
15 | 15 | #include "token.hpp" |
16 | 16 |
|
17 | 17 | /** |
18 | | - * @namespace TINY |
19 | | - * @brief Contains all components of the TINY language scanner. |
| 18 | + * @namespace TINY::SCANNER |
| 19 | + * @brief Contains all components related to the lexical analysis (scanning) of the TINY programming language. |
20 | 20 | * |
21 | | - * The `TINY` namespace organizes all classes, functions, and utilities |
22 | | - * related to the lexical analysis of the TINY programming language. |
| 21 | + * The `TINY::SCANNER` namespace organizes all classes, functions, and utilities |
| 22 | + * that are specifically responsible for the lexical analysis phase of the TINY programming language. |
| 23 | + * This includes tokenization, character stream management, and other related components. |
23 | 24 | */ |
24 | | -namespace TINY |
| 25 | +namespace TINY::SCANNER |
25 | 26 | { |
| 27 | + |
26 | 28 | /** |
27 | | - * @namespace SCANNER |
28 | | - * @brief Contains all components related to the lexical analysis (scanning) of TINY language. |
| 29 | + * @class Scanner |
| 30 | + * @brief Performs lexical analysis on TINY language source code. |
| 31 | + * |
| 32 | + * The `Scanner` processes input source code to produce a sequence of tokens. |
| 33 | + * It identifies keywords, operators, delimiters, and literals, and it reports |
| 34 | + * invalid characters as necessary. |
29 | 35 | */ |
30 | | - namespace SCANNER |
| 36 | + class Scanner |
31 | 37 | { |
32 | | - |
| 38 | + public: |
33 | 39 | /** |
34 | | - * @class Scanner |
35 | | - * @brief Performs lexical analysis on TINY language source code. |
| 40 | + * @brief Constructs a `Scanner` object with the given input string. |
| 41 | + * |
| 42 | + * This constructor initializes the `Scanner` with the source code that |
| 43 | + * needs to be tokenized. |
36 | 44 | * |
37 | | - * The `Scanner` processes input source code to produce a sequence of tokens. |
38 | | - * It identifies keywords, operators, delimiters, and literals, and it reports |
39 | | - * invalid characters as necessary. |
| 45 | + * @param input The source code to be tokenized. |
40 | 46 | */ |
41 | | - class Scanner |
42 | | - { |
43 | | - public: |
44 | | - /** |
45 | | - * @brief Constructs a `Scanner` object with the given input string. |
46 | | - * |
47 | | - * This constructor initializes the `Scanner` with the source code that |
48 | | - * needs to be tokenized. |
49 | | - * |
50 | | - * @param input The source code to be tokenized. |
51 | | - */ |
52 | | - Scanner(const std::string &input); |
| 47 | + Scanner(const std::string &input); |
53 | 48 |
|
54 | | - /** |
55 | | - * @brief Extracts the next token from the input source code. |
56 | | - * |
57 | | - * This method processes the source code and returns the next token |
58 | | - * identified by the `Scanner`. |
59 | | - * |
60 | | - * @return The next token. |
61 | | - */ |
62 | | - Token getNextToken(); |
| 49 | + /** |
| 50 | + * @brief Extracts the next token from the input source code. |
| 51 | + * |
| 52 | + * This method processes the source code and returns the next token |
| 53 | + * identified by the `Scanner`. |
| 54 | + * |
| 55 | + * @return The next token. |
| 56 | + */ |
| 57 | + Token getNextToken(); |
63 | 58 |
|
64 | | - /** |
65 | | - * @brief Checks if there are more tokens to be extracted. |
66 | | - * |
67 | | - * This method determines if the end of the source code has been reached. |
68 | | - * |
69 | | - * @return True if there are more tokens, false otherwise. |
70 | | - */ |
71 | | - bool hasMoreTokens(); |
| 59 | + /** |
| 60 | + * @brief Checks if there are more tokens to be extracted. |
| 61 | + * |
| 62 | + * This method determines if the end of the source code has been reached. |
| 63 | + * |
| 64 | + * @return True if there are more tokens, false otherwise. |
| 65 | + */ |
| 66 | + bool hasMoreTokens(); |
72 | 67 |
|
73 | | - private: |
74 | | - std::string input; /**< The source code to be tokenized. */ |
75 | | - size_t pos = 0; /**< Current position in the input string. */ |
76 | | - int line = 1; /**< Current line number in the source code. */ |
77 | | - int column = 1; /**< Current column number in the source code. */ |
| 68 | + private: |
| 69 | + std::string input; /**< The source code to be tokenized. */ |
| 70 | + size_t pos = 0; /**< Current position in the input string. */ |
| 71 | + int line = 1; /**< Current line number in the source code. */ |
| 72 | + int column = 1; /**< Current column number in the source code. */ |
78 | 73 |
|
79 | | - /** |
80 | | - * @brief Peeks at the next character in the input without advancing the position. |
81 | | - * |
82 | | - * This method allows inspecting the next character in the source code |
83 | | - * without consuming it. |
84 | | - * |
85 | | - * @return The next character in the input, or '\0' if end of input. |
86 | | - */ |
87 | | - char peek() const; |
| 74 | + /** |
| 75 | + * @brief Peeks at the next character in the input without advancing the position. |
| 76 | + * |
| 77 | + * This method allows inspecting the next character in the source code |
| 78 | + * without consuming it. |
| 79 | + * |
| 80 | + * @return The next character in the input, or '\0' if end of input. |
| 81 | + */ |
| 82 | + char peek() const; |
88 | 83 |
|
89 | | - /** |
90 | | - * @brief Gets the next character in the input and advances the position. |
91 | | - * |
92 | | - * This method reads the next character from the source code and moves |
93 | | - * the cursor forward. |
94 | | - * |
95 | | - * @return The next character in the input, or '\0' if end of input. |
96 | | - */ |
97 | | - char get(); |
| 84 | + /** |
| 85 | + * @brief Gets the next character in the input and advances the position. |
| 86 | + * |
| 87 | + * This method reads the next character from the source code and moves |
| 88 | + * the cursor forward. |
| 89 | + * |
| 90 | + * @return The next character in the input, or '\0' if end of input. |
| 91 | + */ |
| 92 | + char get(); |
98 | 93 |
|
99 | | - /** |
100 | | - * @brief Skips over whitespace characters in the input. |
101 | | - * |
102 | | - * This method advances the cursor past any whitespace characters |
103 | | - * encountered in the source code. |
104 | | - */ |
105 | | - void skipWhitespace(); |
| 94 | + /** |
| 95 | + * @brief Skips over whitespace characters in the input. |
| 96 | + * |
| 97 | + * This method advances the cursor past any whitespace characters |
| 98 | + * encountered in the source code. |
| 99 | + */ |
| 100 | + void skipWhitespace(); |
106 | 101 |
|
107 | | - /** |
108 | | - * @brief Skips over nested comments in the input source code. |
109 | | - * |
110 | | - * This method checks if the current position is at the start of a comment (indicated by a '{' character). |
111 | | - * If it is, the method skips over all characters until it finds the corresponding closing '}'. |
112 | | - * It correctly handles **nested comments** by keeping track of the nesting levels. |
113 | | - * For each opening '{', it increases the nesting level, and for each closing '}', it decreases the nesting level. |
114 | | - * The comment is considered closed when the nesting level returns to zero. |
115 | | - * After successfully skipping a comment, it also skips any whitespace characters that follow the comment. |
116 | | - * If the end of the input is reached before all comments are closed (i.e., nesting level does not return to zero), |
117 | | - * the method returns `true` to indicate that an unclosed comment was detected. |
118 | | - * |
119 | | - * @return True if an unclosed comment was detected, false otherwise. |
120 | | - */ |
121 | | - bool skipComments(); |
| 102 | + /** |
| 103 | + * @brief Skips over nested comments in the input source code. |
| 104 | + * |
| 105 | + * This method checks if the current position is at the start of a comment (indicated by a '{' character). |
| 106 | + * If it is, the method skips over all characters until it finds the corresponding closing '}'. |
| 107 | + * It correctly handles **nested comments** by keeping track of the nesting levels. |
| 108 | + * For each opening '{', it increases the nesting level, and for each closing '}', it decreases the nesting level. |
| 109 | + * The comment is considered closed when the nesting level returns to zero. |
| 110 | + * After successfully skipping a comment, it also skips any whitespace characters that follow the comment. |
| 111 | + * If the end of the input is reached before all comments are closed (i.e., nesting level does not return to zero), |
| 112 | + * the method returns `true` to indicate that an unclosed comment was detected. |
| 113 | + * |
| 114 | + * @return True if an unclosed comment was detected, false otherwise. |
| 115 | + */ |
| 116 | + bool skipComments(); |
122 | 117 |
|
123 | | - /** |
124 | | - * @brief Skips over whitespace and comments in the input. |
125 | | - * |
126 | | - * This method continuously skips whitespace and comments until it reaches |
127 | | - * a character that is neither whitespace nor part of a comment. |
128 | | - * If an unclosed comment is detected (i.e., the end of input is reached before a closing '}' is found), |
129 | | - * the method returns `true` to indicate the error. |
130 | | - * |
131 | | - * @return True if an unclosed comment was detected, false otherwise. |
132 | | - */ |
133 | | - bool skipWhitespaceAndComments(); |
| 118 | + /** |
| 119 | + * @brief Skips over whitespace and comments in the input. |
| 120 | + * |
| 121 | + * This method continuously skips whitespace and comments until it reaches |
| 122 | + * a character that is neither whitespace nor part of a comment. |
| 123 | + * If an unclosed comment is detected (i.e., the end of input is reached before a closing '}' is found), |
| 124 | + * the method returns `true` to indicate the error. |
| 125 | + * |
| 126 | + * @return True if an unclosed comment was detected, false otherwise. |
| 127 | + */ |
| 128 | + bool skipWhitespaceAndComments(); |
134 | 129 |
|
135 | | - /** |
136 | | - * @brief Checks if a character is an operator or delimiter. |
137 | | - * |
138 | | - * This method determines if the given character is one of the recognized |
139 | | - * operators or delimiters in the TINY language. |
140 | | - * |
141 | | - * @param c The character to check. |
142 | | - * @return True if the character is an operator or delimiter, false otherwise. |
143 | | - */ |
144 | | - bool isOperatorOrDelimiter(char c) const; |
145 | | - }; |
146 | | - } // namespace SCANNER |
147 | | -} // namespace TINY |
| 130 | + /** |
| 131 | + * @brief Checks if a character is an operator or delimiter. |
| 132 | + * |
| 133 | + * This method determines if the given character is one of the recognized |
| 134 | + * operators or delimiters in the TINY language. |
| 135 | + * |
| 136 | + * @param c The character to check. |
| 137 | + * @return True if the character is an operator or delimiter, false otherwise. |
| 138 | + */ |
| 139 | + bool isOperatorOrDelimiter(char c) const; |
| 140 | + }; |
| 141 | +} // namespace TINY::SCANNER |
148 | 142 |
|
149 | 143 | #endif // SCANNER_HPP |
0 commit comments