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
10
11namespace fsw {
12namespace script {
13
49
50const char* tok_name(Tok t);
51
52struct Token {
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
61struct 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 */
78LexResult lex(const std::string& source);
79
80} // namespace script
81} // namespace fsw
const char * tok_name(Tok t)
Definition Lexer.cpp:9
LexResult lex(const std::string &source)
Tokenize, emitting INDENT/DEDENT for block structure.
Definition Lexer.cpp:390
Motorized ball valve position: raw ADC counts -> % open.
bool ok() const
Definition Lexer.hpp:65
std::vector< Diagnostic > diagnostics
Definition Lexer.hpp:63
std::vector< Token > tokens
Definition Lexer.hpp:62
uint32_t line
Definition Lexer.hpp:56
std::string text
Definition Lexer.hpp:54