STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
fsw::script Namespace Reference

Namespaces

namespace  anonymous_namespace{Lexer.cpp}
namespace  anonymous_namespace{Parser.cpp}
namespace  anonymous_namespace{ScriptConfig.cpp}
namespace  anonymous_namespace{Validate.cpp}

Classes

struct  BadSlug
 A name that could not be turned into a usable slug, reported so config can refuse it loudly. More...
struct  SlugCollision
 Two config names in one namespace that slug to the same identifier — genuinely ambiguous. More...
struct  TableBuild
struct  SlugRef
 One slug reference, with its source span so a rename can rewrite exactly this token. More...
struct  Stmt
struct  Expr
struct  ScriptProgram
 A parsed script, as a flat arena. More...
struct  Diagnostic
struct  ParseResult
struct  SlugTables
 What a script's slugs are allowed to name, built from the loaded config. More...
struct  Token
struct  LexResult

Enumerations

enum class  Ns : uint8_t { Actuator , PtSensor , State }
 Which table a slug is resolved against. More...
enum class  StmtKind : uint8_t {
  Assign , OpenValve , CloseValve , Delay ,
  TransitionTo , If , While
}
enum class  ExprKind : uint8_t {
  Number , Var , Pressure , Elapsed ,
  Unary , Binary
}
enum class  Op : uint8_t {
  Neg , Not , Add , Sub ,
  Mul , Div , Lt , Le ,
  Gt , Ge , Eq , Ne ,
  And , Or
}
enum class  Diag : uint16_t {
  TabIndent = 1 , BadIndentUnit , BadDedent , UnexpectedIndent ,
  UnexpectedChar , BadNumber , ExpectedColon , ExpectedLParen ,
  ExpectedRParen , ExpectedNewline , ExpectedName , ExpectedExpr ,
  ExpectedBlock , UnknownCall , ChainedComparison , CallNotAStatement ,
  AssignToCall , ProgramTooLarge , TooManyLines , TooDeep ,
  TooManyStatements , TooManyVariables , ExprTooDeep , DelayNotPositive ,
  LoopWithoutDelay , VarUsedBeforeAssign , DivideByZeroLiteral , UnknownActuator ,
  UnknownSensor , UnknownState , TransitionNotAllowed , VarShadowsSlug
}
 Diagnostic codes. More...
enum class  Tok : uint8_t {
  Eof , Newline , Indent , Dedent ,
  Ident , Number , Colon , LParen ,
  RParen , Comma , Assign , Plus ,
  Minus , Star , Slash , Lt ,
  Le , Gt , Ge , EqEq ,
  Ne , KwIf , KwElif , KwElse ,
  KwWhile , KwAnd , KwOr , KwNot
}

Functions

TableBuild build_slug_tables (const fsw::config::Config &cfg)
 Build the actuator / sensor / state slug tables from a loaded config.
const char * ns_name (Ns ns)
const char * op_name (Op op)
const char * diag_name (Diag d)
ParseResult parse (const std::string &source)
 Lex and parse, applying every check that does not need config.
std::vector< Diagnostic > validate (const ScriptProgram &program, const SlugTables &tables)
 Config-dependent checks.
std::string slugify (const std::string &name)
 Canonical name -> slug: trim, uppercase, collapse internal whitespace runs to a single '_'.
bool is_valid_slug (const std::string &slug)
 True when a slug is usable as a bare identifier: ^[A-Z][A-Z0-9_]*$.
std::string print_canonical (const ScriptProgram &program)
 A stable s-expression rendering of the parsed program.
const char * tok_name (Tok t)
LexResult lex (const std::string &source)
 Tokenize, emitting INDENT/DEDENT for block structure.

Variables

constexpr size_t kMaxSourceBytes = 4096
constexpr uint32_t kMaxLines = 200
constexpr uint32_t kMaxStatements = 500
constexpr uint32_t kMaxNestingDepth = 8
constexpr uint32_t kMaxVariables = 32
constexpr uint32_t kMaxExprDepth = 32
constexpr uint32_t kMaxIndentUnit = 8
 Widest indent unit accepted.

Enumeration Type Documentation

◆ Diag

enum class fsw::script::Diag : uint16_t
strong

Diagnostic codes.

Tests and the shared corpus assert on the CODE and the LINE, never the message text, so wording can improve without churning them.

Enumerator
TabIndent 
BadIndentUnit 
BadDedent 
UnexpectedIndent 
UnexpectedChar 
BadNumber 
ExpectedColon 
ExpectedLParen 
ExpectedRParen 
ExpectedNewline 
ExpectedName 
ExpectedExpr 
ExpectedBlock 
UnknownCall 
ChainedComparison 
CallNotAStatement 
AssignToCall 
ProgramTooLarge 
TooManyLines 
TooDeep 
TooManyStatements 
TooManyVariables 
ExprTooDeep 
DelayNotPositive 
LoopWithoutDelay 
VarUsedBeforeAssign 
DivideByZeroLiteral 
UnknownActuator 
UnknownSensor 
UnknownState 
TransitionNotAllowed 
VarShadowsSlug 

Definition at line 182 of file StateScript.hpp.

◆ ExprKind

enum class fsw::script::ExprKind : uint8_t
strong
Enumerator
Number 
Var 
Pressure 
Elapsed 
Unary 
Binary 

Definition at line 93 of file StateScript.hpp.

◆ Ns

enum class fsw::script::Ns : uint8_t
strong

Which table a slug is resolved against.

Determined by argument position, never by spelling.

Enumerator
Actuator 
PtSensor 
State 

Definition at line 66 of file StateScript.hpp.

◆ Op

enum class fsw::script::Op : uint8_t
strong
Enumerator
Neg 
Not 
Add 
Sub 
Mul 
Div 
Lt 
Le 
Gt 
Ge 
Eq 
Ne 
And 
Or 

Definition at line 102 of file StateScript.hpp.

◆ StmtKind

enum class fsw::script::StmtKind : uint8_t
strong
Enumerator
Assign 
OpenValve 
CloseValve 
Delay 
TransitionTo 
If 
While 

Definition at line 83 of file StateScript.hpp.

◆ Tok

enum class fsw::script::Tok : uint8_t
strong
Enumerator
Eof 
Newline 
Indent 
Dedent 
Ident 
Number 
Colon 
LParen 
RParen 
Comma 
Assign 
Plus 
Minus 
Star 
Slash 
Lt 
Le 
Gt 
Ge 
EqEq 
Ne 
KwIf 
KwElif 
KwElse 
KwWhile 
KwAnd 
KwOr 
KwNot 

Definition at line 14 of file Lexer.hpp.

Function Documentation

◆ build_slug_tables()

TableBuild fsw::script::build_slug_tables ( const fsw::config::Config & cfg)

Build the actuator / sensor / state slug tables from a loaded config.

allowed_transitions is left empty — it depends on which state owns the script and on state_transitions.csv, neither of which this library reads. The caller fills it.

Collisions are reported per namespace only. Across namespaces they are expected and harmless: on the shipped server profile FUEL_VENT is both a valve and a state, and on digital-twin FUEL_UPSTREAM is both a valve and a sensor. Positional resolution is what makes that fine, and a blanket collision rule would refuse config that runs today.

Definition at line 36 of file ScriptConfig.cpp.

References fsw::config::pt_role_tables().

Referenced by sequencer::load_dynamic_states(), main(), and main().

◆ diag_name()

◆ is_valid_slug()

bool fsw::script::is_valid_slug ( const std::string & slug)

True when a slug is usable as a bare identifier: ^[A-Z][A-Z0-9_]*$.

Definition at line 29 of file Slug.cpp.

References ok.

Referenced by fsw::script::anonymous_namespace{ScriptConfig.cpp}::addName(), and main().

◆ lex()

LexResult fsw::script::lex ( const std::string & source)

Tokenize, emitting INDENT/DEDENT for block structure.

Stops at the first error. Every ambiguity Python resolves by convention is rejected here instead: tabs are refused outright (the editor is a bare <textarea>, where mixed indentation is invisible on screen and the failure mode is a valve opening in the wrong branch), and the first indented line fixes the indent unit that every later indent must be an exact multiple of.

Definition at line 390 of file Lexer.cpp.

References kMaxLines, kMaxSourceBytes, ProgramTooLarge, and TooManyLines.

Referenced by parse().

◆ ns_name()

const char * fsw::script::ns_name ( Ns ns)

Definition at line 10 of file Parser.cpp.

References Actuator, PtSensor, and State.

Referenced by fsw::script::anonymous_namespace{Parser.cpp}::Parser::parseSimple(), and validate().

◆ op_name()

const char * fsw::script::op_name ( Op op)

Definition at line 22 of file Parser.cpp.

References Add, And, Div, Eq, Ge, Gt, Le, Lt, Mul, Ne, Neg, Not, Or, and Sub.

Referenced by fsw::script::anonymous_namespace{Parser.cpp}::printExpr().

◆ parse()

ParseResult fsw::script::parse ( const std::string & source)

Lex and parse, applying every check that does not need config.

Stops at the first error rather than attempting recovery: this is a 200-line config language written a few lines at a time, and a cascade of speculative follow-on errors would bury the one that matters.

Definition at line 813 of file Parser.cpp.

References fsw::script::LexResult::diagnostics, lex(), fsw::script::LexResult::ok(), result, and fsw::script::LexResult::tokens.

Referenced by sequencer::load_dynamic_states(), main(), main(), and run().

◆ print_canonical()

std::string fsw::script::print_canonical ( const ScriptProgram & program)

A stable s-expression rendering of the parsed program.

This exists for the conformance corpus. Two implementations can agree that a script is "accepted" while disagreeing about precedence — a - b - c, not a and b, -x * y — and a precedence disagreement between the validator the operator sees and the interpreter that opens the valve is the worst bug this feature can have. Pinning the shape catches it.

Definition at line 927 of file Parser.cpp.

References fsw::script::ScriptProgram::top_begin, and fsw::script::ScriptProgram::top_end.

Referenced by main().

◆ slugify()

std::string fsw::script::slugify ( const std::string & name)

Canonical name -> slug: trim, uppercase, collapse internal whitespace runs to a single '_'.

The same rule the TS side already uses for sensor entity names (backend/src/sensor-config.ts:104), so the two agree by construction.

Definition at line 8 of file Slug.cpp.

Referenced by fsw::script::anonymous_namespace{ScriptConfig.cpp}::addName(), sequencer::load_dynamic_states(), main(), main(), and validate().

◆ tok_name()

◆ validate()

Variable Documentation

◆ kMaxExprDepth

uint32_t fsw::script::kMaxExprDepth = 32
inlineconstexpr

◆ kMaxIndentUnit

uint32_t fsw::script::kMaxIndentUnit = 8
inlineconstexpr

Widest indent unit accepted.

The first indented line sets the unit; every later indent must be an exact multiple of it, which kills "3 spaces here, 4 there" without a stack of columns.

Definition at line 63 of file StateScript.hpp.

Referenced by fsw::script::anonymous_namespace{Lexer.cpp}::Lexer::handleLineStart().

◆ kMaxLines

uint32_t fsw::script::kMaxLines = 200
inlineconstexpr

Definition at line 56 of file StateScript.hpp.

Referenced by lex(), and main().

◆ kMaxNestingDepth

uint32_t fsw::script::kMaxNestingDepth = 8
inlineconstexpr

◆ kMaxSourceBytes

size_t fsw::script::kMaxSourceBytes = 4096
inlineconstexpr

Definition at line 55 of file StateScript.hpp.

Referenced by lex(), and main().

◆ kMaxStatements

uint32_t fsw::script::kMaxStatements = 500
inlineconstexpr

◆ kMaxVariables

uint32_t fsw::script::kMaxVariables = 32
inlineconstexpr