Sen API
Sen Libraries
Loading...
Searching...
No Matches
stl_scanner.h
Go to the documentation of this file.
1// === stl_scanner.h ===================================================================================================
2// Sen Infrastructure
3// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4// See the LICENSE.txt file for more information.
5// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6// =====================================================================================================================
7
8#ifndef SEN_CORE_LANG_STL_SCANNER_H
9#define SEN_CORE_LANG_STL_SCANNER_H
10
14
15// std
16#include <string>
17
18namespace sen
19{
20struct Var;
21}
22
23namespace sen::lang
24{
25
28
31{
32 SEN_NOCOPY_NOMOVE(StlScanner)
33
34public:
36 explicit StlScanner(const std::string& program);
37 ~StlScanner() = default;
38
39public:
41 [[nodiscard]] const StlTokenList& scanTokens();
42
43private:
44 enum class Sign
45 {
46 positive,
47 negative
48 };
49
50private:
51 void scanToken();
52 void addToken(StlTokenType type, const Var& value);
53 void error(const std::string& message) const;
54 void string(char endingChar);
55 void comment();
56 void ruler();
57 void number(Sign sign);
58 void identifier();
59
60private: // utility
61 [[nodiscard]] bool isAtEnd() const;
62 [[nodiscard]] char advance();
63 [[nodiscard]] bool match(char expected);
64 [[nodiscard]] char peek() const;
65 [[nodiscard]] char peekNext() const;
66 [[nodiscard]] StlToken identifierToken() const;
67 [[nodiscard]] static std::string formatNumber(const std::string& lexeme);
68
69private:
70 const std::string& program_;
71 StlTokenList tokens_;
72 std::size_t start_ = 0U;
73 CodeLocation current_;
74};
75
77
78} // namespace sen::lang
79
80#endif // SEN_CORE_LANG_STL_SCANNER_H
Here we define a set of template meta-programming helpers to let the compiler take some decisions bas...
StlScanner(const std::string &program)
The string is stored for eventual scanning.
const StlTokenList & scanTokens()
Scans the string. Throws in case of error.
std::vector< StlToken > StlTokenList
Definition stl_token.h:121
StlTokenType
Supported tokens.
Definition stl_token.h:28
Location of a character in a program.
Definition code_location.h:21
Definition code_location.h:14
Definition assert.h:17
Can hold any supported value type. Wraps std::variant to allow recursion and implements some helpers.
Definition var.h:119
Definition stl_token.h:98