Sen API
Sen Libraries
Toggle main menu visibility
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
11
#include "
sen/core/base/class_helpers.h
"
12
#include "
sen/core/lang/code_location.h
"
13
#include "
sen/core/lang/stl_token.h
"
14
15
// std
16
#include <string>
17
18
namespace
sen
19
{
20
struct
Var
;
21
}
22
23
namespace
sen::lang
24
{
25
28
30
class
StlScanner
31
{
32
SEN_NOCOPY_NOMOVE(
StlScanner
)
33
34
public
:
36
explicit
StlScanner
(
const
std::string& program);
37
~StlScanner
() =
default
;
38
39
public
:
41
[[nodiscard]]
const
StlTokenList
&
scanTokens
();
42
43
private
:
44
enum class
Sign
45
{
46
positive,
47
negative
48
};
49
50
private
:
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
60
private
:
// 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
69
private
:
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
class_helpers.h
Here we define a set of template meta-programming helpers to let the compiler take some decisions bas...
sen::lang::StlScanner::~StlScanner
~StlScanner()=default
sen::lang::StlScanner::StlScanner
StlScanner(const std::string &program)
The string is stored for eventual scanning.
sen::lang::StlScanner::scanTokens
const StlTokenList & scanTokens()
Scans the string. Throws in case of error.
sen::lang::StlToken
Definition
stl_token.h:102
code_location.h
sen::lang::StlTokenList
std::vector< StlToken > StlTokenList
Definition
stl_token.h:132
sen::lang::StlTokenType
StlTokenType
Supported tokens.
Definition
stl_token.h:29
sen::lang::CodeLocation
Location of a character in a program.
Definition
code_location.h:21
sen::lang
Definition
code_location.h:14
sen
Definition
assert.h:17
stl_token.h
sen::Var
Can hold any supported value type. Wraps std::variant to allow recursion and implements some helpers.
Definition
var.h:119
libs
core
include
sen
core
lang
stl_scanner.h
Generated by
1.17.0