STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
Lexer.hpp
Go to the documentation of this file.
1
#pragma once
2
3
// Internal to the script library. Not installed, not included outside lib/src/script.
4
5
#include <cstdint>
6
#include <string>
7
#include <vector>
8
9
#include "
script/StateScript.hpp
"
10
11
namespace
fsw
{
12
namespace
script
{
13
14
enum class
Tok
: uint8_t {
15
Eof
,
16
Newline
,
17
Indent
,
18
Dedent
,
19
20
Ident
,
21
Number
,
22
23
Colon
,
24
LParen
,
25
RParen
,
26
Comma
,
27
Assign
,
28
29
Plus
,
30
Minus
,
31
Star
,
32
Slash
,
33
34
Lt
,
35
Le
,
36
Gt
,
37
Ge
,
38
EqEq
,
39
Ne
,
40
41
KwIf
,
42
KwElif
,
43
KwElse
,
44
KwWhile
,
45
KwAnd
,
46
KwOr
,
47
KwNot
,
48
};
49
50
const
char
*
tok_name
(
Tok
t);
51
52
struct
Token
{
53
Tok
kind
=
Tok::Eof
;
54
std::string
text
;
// Ident spelling; Number source text
55
double
number
= 0.0;
// Number value
56
uint32_t
line
= 1;
// 1-based
57
uint32_t
col
= 1;
// 1-based
58
uint32_t
len
= 0;
59
};
60
61
struct
LexResult
{
62
std::vector<Token>
tokens
;
63
std::vector<Diagnostic>
diagnostics
;
64
65
bool
ok
()
const
{
66
return
diagnostics
.empty();
67
}
68
};
69
70
/**
71
* Tokenize, emitting INDENT/DEDENT for block structure.
72
*
73
* Stops at the first error. Every ambiguity Python resolves by convention is rejected here
74
* instead: tabs are refused outright (the editor is a bare <textarea>, where mixed indentation is
75
* invisible on screen and the failure mode is a valve opening in the wrong branch), and the first
76
* indented line fixes the indent unit that every later indent must be an exact multiple of.
77
*/
78
LexResult
lex
(
const
std::string& source);
79
80
}
// namespace script
81
}
// namespace fsw
StateScript.hpp
fsw::script
Definition
ScriptConfig.hpp:17
fsw::script::StmtKind::Assign
@ Assign
Definition
StateScript.hpp:84
fsw::script::tok_name
const char * tok_name(Tok t)
Definition
Lexer.cpp:9
fsw::script::ExprKind::Number
@ Number
Definition
StateScript.hpp:94
fsw::script::lex
LexResult lex(const std::string &source)
Tokenize, emitting INDENT/DEDENT for block structure.
Definition
Lexer.cpp:390
fsw::script::Op::Gt
@ Gt
Definition
StateScript.hpp:111
fsw::script::Op::Ne
@ Ne
Definition
StateScript.hpp:114
fsw::script::Op::Lt
@ Lt
Definition
StateScript.hpp:109
fsw::script::Op::Le
@ Le
Definition
StateScript.hpp:110
fsw::script::Op::Ge
@ Ge
Definition
StateScript.hpp:112
fsw::script::Tok
Tok
Definition
Lexer.hpp:14
fsw::script::Tok::KwIf
@ KwIf
Definition
Lexer.hpp:41
fsw::script::Tok::KwNot
@ KwNot
Definition
Lexer.hpp:47
fsw::script::Tok::Star
@ Star
Definition
Lexer.hpp:31
fsw::script::Tok::KwOr
@ KwOr
Definition
Lexer.hpp:46
fsw::script::Tok::Plus
@ Plus
Definition
Lexer.hpp:29
fsw::script::Tok::Slash
@ Slash
Definition
Lexer.hpp:32
fsw::script::Tok::Ident
@ Ident
Definition
Lexer.hpp:20
fsw::script::Tok::Colon
@ Colon
Definition
Lexer.hpp:23
fsw::script::Tok::Minus
@ Minus
Definition
Lexer.hpp:30
fsw::script::Tok::Eof
@ Eof
Definition
Lexer.hpp:15
fsw::script::Tok::Indent
@ Indent
Definition
Lexer.hpp:17
fsw::script::Tok::Comma
@ Comma
Definition
Lexer.hpp:26
fsw::script::Tok::Dedent
@ Dedent
Definition
Lexer.hpp:18
fsw::script::Tok::Newline
@ Newline
Definition
Lexer.hpp:16
fsw::script::Tok::KwElse
@ KwElse
Definition
Lexer.hpp:43
fsw::script::Tok::LParen
@ LParen
Definition
Lexer.hpp:24
fsw::script::Tok::KwElif
@ KwElif
Definition
Lexer.hpp:42
fsw::script::Tok::KwWhile
@ KwWhile
Definition
Lexer.hpp:44
fsw::script::Tok::KwAnd
@ KwAnd
Definition
Lexer.hpp:45
fsw::script::Tok::EqEq
@ EqEq
Definition
Lexer.hpp:38
fsw::script::Tok::RParen
@ RParen
Definition
Lexer.hpp:25
fsw
Motorized ball valve position: raw ADC counts -> % open.
Definition
AllanVariance.hpp:7
fsw::script::LexResult
Definition
Lexer.hpp:61
fsw::script::LexResult::ok
bool ok() const
Definition
Lexer.hpp:65
fsw::script::LexResult::diagnostics
std::vector< Diagnostic > diagnostics
Definition
Lexer.hpp:63
fsw::script::LexResult::tokens
std::vector< Token > tokens
Definition
Lexer.hpp:62
fsw::script::Token
Definition
Lexer.hpp:52
fsw::script::Token::col
uint32_t col
Definition
Lexer.hpp:57
fsw::script::Token::number
double number
Definition
Lexer.hpp:55
fsw::script::Token::line
uint32_t line
Definition
Lexer.hpp:56
fsw::script::Token::kind
Tok kind
Definition
Lexer.hpp:53
fsw::script::Token::text
std::string text
Definition
Lexer.hpp:54
fsw::script::Token::len
uint32_t len
Definition
Lexer.hpp:58
daq-server
diablo_server
lib
src
script
Lexer.hpp
Generated by
1.15.0