载入中...
搜索中...
未找到
DnutCompiler.cpp
浏览该文件的文档.
2
4
5#include <cstdlib>
6#include <map>
7#include <string>
8#include <unordered_set>
9#include <utility>
10#include <vector>
11
12namespace eve::dnut {
13
15
16namespace {
17
19struct ParseAbort {};
20
21struct CompiledOption;
22
23struct CompiledStatement {
24 enum class Kind { Step, If, Choice, Loop, Parallel, Break, Continue, Label, Jump };
25
26 Kind kind = Kind::Step;
27 std::string nodeId;
29 std::string type;
32 std::vector<CompiledStatement> thenBody;
33 std::vector<CompiledStatement> elseBody;
34 std::vector<CompiledOption> options;
36 std::vector<std::vector<CompiledStatement>> lanes;
38 std::string name;
39 int sourceLine = 0;
40 int sourceColumn = 0;
41};
42
44struct CompiledOption {
45 std::string label;
47 std::vector<CompiledStatement> body;
48 std::string nodeId;
49};
50
52struct LoopEmitFrame {
53 std::string loopNodeId;
54 std::string afterNodeId;
55};
56
57eve::Value numberValue(const std::string& raw) {
58 if (raw.find_first_of(".eE") != std::string::npos) return eve::Value::number(std::strtod(raw.c_str(), nullptr));
59 return eve::Value::integer(std::strtoll(raw.c_str(), nullptr, 10));
60}
61
62bool isComparisonOperator(const std::string& text) {
63 return text == "==" || text == "!=" || text == ">" || text == "<" || text == ">=" || text == "<=";
64}
65
66const char* comparisonSpelling(const std::string& text) {
67 if (text == "==") return "eq";
68 if (text == "!=") return "ne";
69 if (text == ">") return "gt";
70 if (text == "<") return "lt";
71 if (text == ">=") return "ge";
72 return "le";
73}
74
75class StoryParser {
76public:
77 StoryParser(std::vector<DnutToken> tokens, std::string path, const StepKindRegistry& registry,
78 DnutCompileOutput& output)
79 : tokens_(std::move(tokens)), path_(std::move(path)), registry_(registry), output_(output) {}
80
81 void run() {
82 while (!atEnd()) {
83 if (isIdentifier("story") || isIdentifier("common")) {
84 try {
85 parseStory();
86 } catch (const ParseAbort&) {
88 }
89 continue;
90 }
91 skipForeignBlock();
92 }
93 }
94
95private:
96 const DnutToken& cur() const { return tokens_[index_]; }
97 const DnutToken& peek(std::size_t offset) const {
98 const std::size_t position = index_ + offset;
99 return tokens_[position < tokens_.size() ? position : tokens_.size() - 1];
100 }
101 bool atEnd() const { return cur().kind == DnutTokenKind::EndOfFile; }
103 DnutToken advance() {
104 const DnutToken token = tokens_[index_];
105 if (!atEnd()) ++index_;
106 return token;
107 }
108 bool isPunct(const std::string& text) const {
109 return cur().kind == DnutTokenKind::Punctuator && cur().text == text;
110 }
111 bool isIdentifier(const std::string& text) const {
112 return cur().kind == DnutTokenKind::Identifier && cur().text == text;
113 }
114
115 [[noreturn]] void error(const DnutToken& token, std::string message) {
116 output_.diagnostics.push_back(
117 {DnutSeverity::Error, path_, token.line, token.column, std::move(message)});
118 errorLine_ = token.line;
119 throw ParseAbort{};
120 }
121 [[noreturn]] void errorHere(std::string message) { error(cur(), std::move(message)); }
122
123 void expectPunct(const std::string& text) {
124 if (!isPunct(text)) errorHere("expected '" + text + "'");
125 advance();
126 }
127 std::string expectIdentifier(const std::string& what) {
128 if (cur().kind != DnutTokenKind::Identifier) errorHere("expected " + what);
129 return advance().text;
130 }
131 std::string nextNodeId() { return "n" + std::to_string(++nodeCounter_); }
132
134 void synchronize() {
135 int depth = 0;
136 bool consumed = false;
137 while (!atEnd()) {
138 if (depth == 0) {
139 if (isPunct("}")) return;
140 if (consumed && cur().kind == DnutTokenKind::Identifier && cur().line > errorLine_) return;
141 }
142 if (isPunct("{")) {
143 ++depth;
144 } else if (isPunct("}")) {
145 if (depth == 0) return;
146 --depth;
147 }
148 advance();
149 consumed = true;
150 }
151 }
152
154 void skipForeignBlock() {
155 int depth = 0;
156 while (!atEnd()) {
157 if (depth == 0 && (isIdentifier("story") || isIdentifier("common"))) return;
158 if (isPunct("{")) {
159 ++depth;
160 } else if (isPunct("}")) {
161 if (depth > 0) --depth;
162 }
163 advance();
164 }
165 }
166
167 void parseStory() {
168 const bool isCommon = isIdentifier("common");
169 advance(); // 'story' | 'common'
170 invalidStep_ = false;
171 const std::string id = expectIdentifier(isCommon ? "a common-event id" : "a story id");
172 bool repeatable = isCommon; // common events are reusable by default
173 int version = 1;
174 while (cur().kind == DnutTokenKind::Identifier) {
175 const std::string modifier = cur().text;
176 if (modifier == "repeatable") {
177 repeatable = true;
178 advance();
179 continue;
180 }
181 if (modifier == "version") {
182 advance();
183 expectPunct("=");
184 if (cur().kind != DnutTokenKind::Number) errorHere("version requires an integer");
185 version = static_cast<int>(std::strtol(advance().text.c_str(), nullptr, 10));
186 if (version < 1) errorHere("version must be positive");
187 continue;
188 }
189 errorHere(std::string("unknown ") + (isCommon ? "common" : "story") + " modifier '" + modifier + "'");
190 }
191
192 std::vector<CompiledStatement> body;
193 parseBlockBody(body);
194
195 SequenceAsset asset;
196 asset.id = id;
197 asset.version = version;
198 asset.repeatable = repeatable;
199 const std::string endId = nextNodeId();
200 SequenceNode endNode;
201 endNode.id = endId;
202 endNode.type = "end";
203 loopStack_.clear();
204 pendingJumps_.clear();
205 labels_.clear();
206 const std::string entry = emitBlock(body, endId, asset);
207 asset.entry = entry.empty() ? endId : entry;
208 asset.nodes.push_back(std::move(endNode));
209 resolveJumps(asset);
210
211 bool publishable = !invalidStep_;
212 if (auto validated = asset.validate(); !validated.ok()) {
213 const auto* diagnostic = validated.error();
214 output_.diagnostics.push_back(
215 {DnutSeverity::Error, path_, 0, 0, diagnostic ? diagnostic->message() : "invalid sequence asset"});
216 publishable = false;
217 }
218 if (!publishedIds_.insert(asset.id).second) {
219 output_.diagnostics.push_back(
220 {DnutSeverity::Error, path_, 0, 0,
221 std::string("duplicate ") + (isCommon ? "common" : "story") + " id '" + asset.id + "'"});
222 publishable = false;
223 }
224 if (publishable) output_.assets.push_back(std::move(asset));
225 }
226
227 void parseBlockBody(std::vector<CompiledStatement>& out) {
228 expectPunct("{");
229 while (true) {
230 if (atEnd()) errorHere("unterminated block");
231 if (isPunct("}")) {
232 advance();
233 return;
234 }
235 try {
236 out.push_back(parseStatement());
237 } catch (const ParseAbort&) {
238 synchronize();
239 }
240 }
241 }
242
243 CompiledStatement parseStatement() {
244 if (cur().kind != DnutTokenKind::Identifier) errorHere("expected a statement");
245 const std::string keyword = cur().text;
246 if (keyword == "if") return parseIf();
247 if (keyword == "choice") return parseChoice();
248 if (keyword == "wait") return parseWait();
249 if (keyword == "call" || keyword == "common") return parseCall();
250 if (keyword == "loop") return parseLoop();
251 if (keyword == "break") return parseBreakOrContinue(true);
252 if (keyword == "continue") return parseBreakOrContinue(false);
253 if (keyword == "label") return parseLabel();
254 if (keyword == "jump") return parseJump();
255 if (keyword == "parallel") return parseParallel();
256 if (keyword == "end") {
257 advance();
258 CompiledStatement statement;
259 statement.type = "end";
260 statement.nodeId = nextNodeId();
261 return statement;
262 }
263 return parseStep();
264 }
265
266 CompiledStatement parseStep() {
267 const DnutToken start = cur();
268 CompiledStatement statement;
269 statement.type = advance().text;
270 statement.nodeId = nextNodeId();
271 while (cur().kind == DnutTokenKind::Identifier && peek(1).kind == DnutTokenKind::Punctuator &&
272 peek(1).text == "=") {
273 const std::string field = advance().text;
274 advance(); // '='
275 statement.payload.set(field, parseValue());
276 }
277
278 // Validate against the vocabulary here, while the statement's own source
279 // location is still available, so a bad field points at the authored line
280 // instead of at the whole document.
281 SequenceNode candidate;
282 candidate.id = statement.nodeId;
283 candidate.type = statement.type;
284 candidate.payload = statement.payload;
285 if (auto validated = registry_.validate(candidate); !validated.ok()) {
286 const auto* diagnostic = validated.error();
287 output_.diagnostics.push_back({DnutSeverity::Error, path_, start.line, start.column,
288 diagnostic ? diagnostic->message() : "invalid step"});
289 invalidStep_ = true;
290 }
291 return statement;
292 }
293
294 CompiledStatement parseWait() {
295 advance(); // 'wait'
296 CompiledStatement statement;
297 statement.type = "wait";
298 statement.nodeId = nextNodeId();
299 if (cur().kind == DnutTokenKind::Number) {
300 statement.payload.set("duration", numberValue(advance().text));
301 return statement;
302 }
303 if (isIdentifier("duration")) {
304 advance();
305 expectPunct("=");
306 statement.payload.set("duration", parseValue());
307 return statement;
308 }
309 errorHere("wait requires a duration");
310 }
311
312 CompiledStatement parseCall() {
313 advance(); // 'call' | 'common' (CallCommonEvent)
314 CompiledStatement statement;
315 statement.type = "call";
316 statement.nodeId = nextNodeId();
317 statement.payload.set("target", eve::Value::string(expectIdentifier("a called sequence id")));
318 return statement;
319 }
320
321 CompiledStatement parseLoop() {
322 const DnutToken start = cur();
323 advance(); // 'loop'
324 CompiledStatement statement;
325 statement.kind = CompiledStatement::Kind::Loop;
326 statement.nodeId = nextNodeId();
327 statement.sourceLine = start.line;
328 statement.sourceColumn = start.column;
329 statement.name = "forever";
330 if (isIdentifier("while")) {
331 advance();
332 statement.name = "while";
333 statement.condition = parseCondition();
334 } else if (isIdentifier("times")) {
335 advance();
336 expectPunct("=");
337 statement.name = "times";
338 statement.payload.set("count", parseValue());
339 }
340 parseBlockBody(statement.thenBody);
341 return statement;
342 }
343
344 CompiledStatement parseBreakOrContinue(bool isBreak) {
345 const DnutToken start = cur();
346 advance();
347 CompiledStatement statement;
348 statement.kind = isBreak ? CompiledStatement::Kind::Break : CompiledStatement::Kind::Continue;
349 statement.type = isBreak ? "break" : "continue";
350 statement.nodeId = nextNodeId();
351 statement.sourceLine = start.line;
352 statement.sourceColumn = start.column;
353 return statement;
354 }
355
356 CompiledStatement parseLabel() {
357 const DnutToken start = cur();
358 advance(); // 'label'
359 CompiledStatement statement;
360 statement.kind = CompiledStatement::Kind::Label;
361 statement.type = "label";
362 statement.nodeId = nextNodeId();
363 statement.name = expectIdentifier("a label name");
364 statement.sourceLine = start.line;
365 statement.sourceColumn = start.column;
366 return statement;
367 }
368
369 CompiledStatement parseJump() {
370 const DnutToken start = cur();
371 advance(); // 'jump'
372 CompiledStatement statement;
373 statement.kind = CompiledStatement::Kind::Jump;
374 statement.type = "jump";
375 statement.nodeId = nextNodeId();
376 statement.name = expectIdentifier("a label name");
377 statement.sourceLine = start.line;
378 statement.sourceColumn = start.column;
379 return statement;
380 }
381
382 CompiledStatement parseParallel() {
383 const DnutToken start = cur();
384 advance(); // 'parallel'
385 CompiledStatement statement;
386 statement.kind = CompiledStatement::Kind::Parallel;
387 statement.type = "parallel";
388 statement.nodeId = nextNodeId();
389 statement.sourceLine = start.line;
390 statement.sourceColumn = start.column;
391 expectPunct("{");
392 while (!isPunct("}")) {
393 if (atEnd()) errorHere("unterminated parallel block");
394 if (!isIdentifier("lane")) errorHere("parallel accepts only lane blocks");
395 advance();
396 std::vector<CompiledStatement> lane;
397 parseBlockBody(lane);
398 statement.lanes.push_back(std::move(lane));
399 }
400 advance(); // '}'
401 if (statement.lanes.size() < 2) errorHere("parallel requires at least two lanes");
402 return statement;
403 }
404
405 CompiledStatement parseIf() {
406 advance(); // 'if'
407 CompiledStatement statement;
408 statement.kind = CompiledStatement::Kind::If;
409 statement.nodeId = nextNodeId();
410 statement.condition = parseCondition();
411 parseBlockBody(statement.thenBody);
412 if (isIdentifier("else")) {
413 advance();
414 parseBlockBody(statement.elseBody);
415 }
416 return statement;
417 }
418
419 CompiledStatement parseChoice() {
420 advance(); // 'choice'
421 CompiledStatement statement;
422 statement.kind = CompiledStatement::Kind::Choice;
423 statement.nodeId = nextNodeId();
424 expectPunct("{");
425 while (!isPunct("}")) {
426 if (atEnd()) errorHere("unterminated choice block");
427 if (!isIdentifier("option")) errorHere("choice accepts only option statements");
428 advance();
429 CompiledOption option;
430 option.nodeId = nextNodeId();
431 if (cur().kind != DnutTokenKind::String) errorHere("option requires a quoted label");
432 option.label = advance().text;
433 if (isIdentifier("when")) {
434 advance();
435 option.condition = parseCondition();
436 }
437 parseBlockBody(option.body);
438 statement.options.push_back(std::move(option));
439 }
440 advance(); // '}'
441 if (statement.options.empty()) errorHere("choice requires at least one option");
442 return statement;
443 }
444
445 eve::Value parseCondition() { return parseOr(); }
446
447 eve::Value parseOr() {
448 eve::Value left = parseAnd();
449 while (isPunct("||")) {
450 advance();
451 eve::Value right = parseAnd();
452 if (auto* object = left.getIf<eve::Value::Object>();
453 object != nullptr && object->contains("any") && object->at("any").isArray()) {
454 object->at("any").pushBack(std::move(right));
455 } else {
456 eve::Value::Array operands;
457 operands.reserve(2);
458 operands.emplace_back(std::move(left));
459 operands.emplace_back(std::move(right));
460 eve::Value::Object combined;
461 combined.emplace("any", std::move(operands));
462 left = eve::Value(std::move(combined));
463 }
464 }
465 return left;
466 }
467
468 eve::Value parseAnd() {
469 eve::Value left = parseNot();
470 while (isPunct("&&")) {
471 advance();
472 eve::Value right = parseNot();
473 if (auto* object = left.getIf<eve::Value::Object>();
474 object != nullptr && object->contains("all") && object->at("all").isArray()) {
475 object->at("all").pushBack(std::move(right));
476 } else {
477 eve::Value::Array operands;
478 operands.reserve(2);
479 operands.emplace_back(std::move(left));
480 operands.emplace_back(std::move(right));
481 eve::Value::Object combined;
482 combined.emplace("all", std::move(operands));
483 left = eve::Value(std::move(combined));
484 }
485 }
486 return left;
487 }
488
489 eve::Value parseNot() {
490 if (isPunct("!")) {
491 advance();
492 return eve::Value(eve::Value::Object{{"not", parseNot()}});
493 }
494 if (isPunct("(")) {
495 advance();
496 eve::Value inner = parseOr();
497 expectPunct(")");
498 return inner;
499 }
500 return parseComparison();
501 }
502
503 eve::Value parseComparison() {
504 if (cur().kind != DnutTokenKind::Identifier) errorHere("condition must start with a variable name");
505 const std::string variable = advance().text;
506 if (cur().kind != DnutTokenKind::Punctuator || !isComparisonOperator(cur().text))
507 errorHere("condition requires a comparison operator (== != > < >= <=)");
508 const std::string operation = advance().text;
509 eve::Value expected = parseValue();
510 return eve::Value(eve::Value::Object{{"var", eve::Value::string(variable)},
511 {"op", eve::Value::string(comparisonSpelling(operation))},
512 {"value", std::move(expected)}});
513 }
514
515 eve::Value parseValue() {
516 if (isPunct("-")) {
517 advance();
518 if (cur().kind != DnutTokenKind::Number) errorHere("'-' must be followed by a number");
519 eve::Value magnitude = numberValue(advance().text);
520 if (magnitude.isInt64()) return eve::Value::integer(-magnitude.asInt());
521 return eve::Value::number(-magnitude.asDouble());
522 }
523 switch (cur().kind) {
524 case DnutTokenKind::String: return eve::Value::string(advance().text);
525 case DnutTokenKind::Number: return numberValue(advance().text);
527 if (isIdentifier("true")) {
528 advance();
529 return eve::Value::boolean(true);
530 }
531 if (isIdentifier("false")) {
532 advance();
533 return eve::Value::boolean(false);
534 }
535 return eve::Value::string(advance().text);
536 default: errorHere("expected a literal value"); break;
537 }
538 }
539
540 std::string emitBlock(const std::vector<CompiledStatement>& statements, const std::string& next,
541 SequenceAsset& asset) {
542 std::string continuation = next;
543 for (auto it = statements.rbegin(); it != statements.rend(); ++it)
544 continuation = emitStatement(*it, continuation, asset);
545 return continuation;
546 }
547
548 std::string emitStatement(const CompiledStatement& statement, const std::string& next, SequenceAsset& asset) {
549 if (statement.kind == CompiledStatement::Kind::Step) {
550 SequenceNode node;
551 node.id = statement.nodeId;
552 node.type = statement.type;
553 node.next = next;
554 node.payload = statement.payload;
555 asset.nodes.push_back(std::move(node));
556 return statement.nodeId;
557 }
558 if (statement.kind == CompiledStatement::Kind::If) {
559 const std::string thenEntry = emitBlock(statement.thenBody, next, asset);
560 const std::string elseEntry = emitBlock(statement.elseBody, next, asset);
561 SequenceNode node;
562 node.id = statement.nodeId;
563 node.type = "branch";
564 node.next = elseEntry;
565 SequenceRoute route;
566 route.condition = statement.condition;
567 route.target = thenEntry;
568 node.routes.push_back(std::move(route));
569 asset.nodes.push_back(std::move(node));
570 return statement.nodeId;
571 }
572 if (statement.kind == CompiledStatement::Kind::Choice) {
573 SequenceNode node;
574 node.id = statement.nodeId;
575 node.type = "choice";
576 node.next = next;
577 for (const auto& option : statement.options) {
578 SequenceRoute route;
579 route.label = option.label;
580 route.condition = option.condition;
581 route.target = emitBlock(option.body, next, asset);
582 node.routes.push_back(std::move(route));
583 }
584 asset.nodes.push_back(std::move(node));
585 return statement.nodeId;
586 }
587 if (statement.kind == CompiledStatement::Kind::Loop) {
588 loopStack_.push_back({statement.nodeId, next});
589 const std::string bodyEntry = emitBlock(statement.thenBody, statement.nodeId, asset);
590 loopStack_.pop_back();
591 SequenceNode node;
592 node.id = statement.nodeId;
593 node.type = "loop";
594 node.next = next;
595 node.payload.set("mode", eve::Value::string(statement.name));
596 if (statement.name == "times") {
597 if (const eve::Value* count = statement.payload.find("count")) node.payload.set("count", *count);
598 }
599 SequenceRoute route;
600 if (statement.name == "while") route.condition = statement.condition;
601 route.target = bodyEntry;
602 node.routes.push_back(std::move(route));
603 asset.nodes.push_back(std::move(node));
604 return statement.nodeId;
605 }
606 if (statement.kind == CompiledStatement::Kind::Break ||
607 statement.kind == CompiledStatement::Kind::Continue) {
608 if (loopStack_.empty()) {
609 output_.diagnostics.push_back({DnutSeverity::Error, path_, statement.sourceLine,
610 statement.sourceColumn,
611 statement.type + " is not inside a loop"});
612 invalidStep_ = true;
613 }
614 SequenceNode node;
615 node.id = statement.nodeId;
616 node.type = statement.type;
617 node.next = loopStack_.empty()
618 ? next
619 : (statement.kind == CompiledStatement::Kind::Break ? loopStack_.back().afterNodeId
620 : loopStack_.back().loopNodeId);
621 asset.nodes.push_back(std::move(node));
622 return statement.nodeId;
623 }
624 if (statement.kind == CompiledStatement::Kind::Label) {
625 if (!labels_.emplace(statement.name, statement.nodeId).second) {
626 output_.diagnostics.push_back({DnutSeverity::Error, path_, statement.sourceLine,
627 statement.sourceColumn, "duplicate label '" + statement.name + "'"});
628 invalidStep_ = true;
629 }
630 SequenceNode node;
631 node.id = statement.nodeId;
632 node.type = "label";
633 node.next = next;
634 node.payload.set("name", eve::Value::string(statement.name));
635 asset.nodes.push_back(std::move(node));
636 return statement.nodeId;
637 }
638 if (statement.kind == CompiledStatement::Kind::Jump) {
639 SequenceNode node;
640 node.id = statement.nodeId;
641 node.type = "jump";
642 node.next = next;
643 node.payload.set("name", eve::Value::string(statement.name));
644 asset.nodes.push_back(std::move(node));
645 pendingJumps_.push_back({statement.nodeId, statement.name, statement.sourceLine, statement.sourceColumn});
646 return statement.nodeId;
647 }
648 if (statement.kind == CompiledStatement::Kind::Parallel) {
649 const std::string joinId = nextNodeId();
650 SequenceNode join;
651 join.id = joinId;
652 join.type = "join";
653 asset.nodes.push_back(std::move(join));
654
655 SequenceNode node;
656 node.id = statement.nodeId;
657 node.type = "parallel";
658 node.next = next;
659 node.payload.set("join", eve::Value::string(joinId));
660 for (const auto& lane : statement.lanes) {
661 SequenceRoute route;
662 route.target = emitBlock(lane, joinId, asset);
663 node.routes.push_back(std::move(route));
664 }
665 asset.nodes.push_back(std::move(node));
666 return statement.nodeId;
667 }
668 output_.diagnostics.push_back(
669 {DnutSeverity::Error, path_, 0, 0, "internal: unhandled compiled statement kind"});
670 invalidStep_ = true;
671 return next;
672 }
673
674 void resolveJumps(SequenceAsset& asset) {
675 for (const auto& jump : pendingJumps_) {
676 auto found = labels_.find(jump.name);
677 if (found == labels_.end()) {
678 output_.diagnostics.push_back({DnutSeverity::Error, path_, jump.line, jump.column,
679 "jump targets unknown label '" + jump.name + "'"});
680 invalidStep_ = true;
681 continue;
682 }
683 SequenceNode* node = nullptr;
684 for (auto& candidate : asset.nodes) {
685 if (candidate.id == jump.nodeId) {
686 node = &candidate;
687 break;
688 }
689 }
690 if (!node) continue;
691 node->payload.set("target", eve::Value::string(found->second));
692 node->next = found->second;
693 }
694 }
695
696 struct PendingJump {
697 std::string nodeId;
698 std::string name;
699 int line = 0;
700 int column = 0;
701 };
702
703 std::vector<DnutToken> tokens_;
704 std::size_t index_ = 0;
705 std::string path_;
706 const StepKindRegistry& registry_;
707 DnutCompileOutput& output_;
708 int nodeCounter_ = 0;
709 int errorLine_ = 0;
711 bool invalidStep_ = false;
712 std::unordered_set<std::string> publishedIds_;
713 std::vector<LoopEmitFrame> loopStack_;
714 // Prefer std::map over unordered_map<string,string>: that specialization is
715 // exported from EVFoundation on Windows SHARED and collides (LNK2005/LNK1169)
716 // when instantiated again in the Platform group (see windows-ccache-hardlinks.md).
717 std::map<std::string, std::string> labels_;
718 std::vector<PendingJump> pendingJumps_;
719};
720
721} // namespace
722
723DnutCompileOutput compileDnut(std::string_view source, const std::string& path,
724 const StepKindRegistry& registry) {
726 auto tokens = lexDnut(source, path);
727 if (!tokens.ok()) {
728 const auto* diagnostic = tokens.error();
729 output.diagnostics.push_back({DnutSeverity::Error, path, 0, 0,
730 diagnostic ? diagnostic->message() : "could not lex the document"});
731 return output;
732 }
733 StoryParser parser(std::move(tokens).takeValue(), path, registry, output);
734 parser.run();
735 return output;
736}
737
738} // namespace eve::dnut
ActionParameterOperation operation
Value::Object payload
Duration start
std::string output
std::string loopNodeId
std::vector< CompiledStatement > thenBody
std::vector< std::vector< CompiledStatement > > lanes
Parallel lane bodies (parallel { lane {…} lane {…} }).
std::string afterNodeId
int sourceLine
int sourceColumn
eve::Value condition
std::string nodeId
std::vector< CompiledStatement > elseBody
Registry-driven compiler for the `.dnut` story dialect.
Shared lexer for every `.dnut` dialect.
std::string name
Definition ECS.cpp:154
double raw
std::string message
HexVec3 left
HexVec3 right
size_t offset
std::array< float, 3 > position
std::string label
std::map< std::string, Node > nodes
std::string id
OceanGpuFrameToken token
std::weak_ptr< Run > run
Definition OnnxGpgpu.cpp:25
std::string error
Definition Package.cpp:174
std::string path
Definition PlayHost.cpp:111
const eve::script::BindingContractRegistry & registry
std::string body
const RoadNode * node
bool found
unsigned line
std::string text
ScriptStructure out
std::string_view source
unsigned column
std::string kind
std::vector< Token > tokens
const SquirrelValueOptions & options
int count
std::uint32_t depth
std::uint64_t statements
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
bool isInt64() const noexcept
Return true when this value is an Int64.
Definition Value.h:102
std::map< std::string, Value > Object
Definition Value.h:34
double asDouble() const
Return the Double payload; the caller must have checked the kind.
Definition Value.cpp:195
static Value number(double value)
Compatibility factory for a Double value.
Definition Value.h:117
static Value string(std::string value)
Compatibility factory for a string value.
Definition Value.h:121
std::int64_t asInt() const
Return the Int64 payload; the caller must have checked the kind.
Definition Value.cpp:189
std::vector< Value > Array
Definition Value.h:33
static Value integer(std::int64_t value)
Compatibility factory for an Int64 value.
Definition Value.h:115
static Value boolean(bool value)
Compatibility factory for a boolean value.
Definition Value.h:119
Canonical step vocabulary owner and runtime handler router.
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
EVENGINE_API_PLATFORM bool hasErrors(const std::vector< DnutDiagnostic > &diagnostics)
Return whether any diagnostic is an error.
eve::Result< std::vector< DnutToken > > lexDnut(std::string_view source, const std::string &path)
Lex one .dnut source buffer into owned tokens.
Definition DnutLexer.cpp:96
DnutCompileOutput compileDnut(std::string_view source, const std::string &path, const StepKindRegistry &registry)
Compile every story block of one .dnut document.
@ String
Quoted string with escapes already resolved.
@ Identifier
Bare word: keyword, field name, identifier, or bare enum value.
@ Punctuator
One- or two-character punctuator such as {, =, ==, ->.
@ EndOfFile
Synthetic terminal token; always the last element.
@ Number
Unsigned numeric literal; sign handling belongs to the parser.
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Definition HexMetrics.h:76
Result< VehiclePhysicsStatus > synchronize(VehicleEntity &vehicle, std::shared_ptr< VehicleWheelRuntime > &runtime)
Owning outcome of compiling one .dnut document.
std::vector< DnutDiagnostic > diagnostics
bool hasErrors() const
Return whether any collected diagnostic has error severity.
bool consumed
Definition Graphics.cpp:201