Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/spider/tdl/parser/SourceLocation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#define SPIDER_TDL_PARSER_SOURCELOCATION_HPP

#include <cstddef>
#include <string>

#include <fmt/format.h>

namespace spider::tdl::parser {
class SourceLocation {
Expand All @@ -14,6 +17,10 @@ class SourceLocation {

[[nodiscard]] auto get_column() const noexcept -> size_t { return m_column; }

[[nodiscard]] auto serialize_to_str() const -> std::string {
return fmt::format("({}:{})", m_line, m_column);
}

[[nodiscard]] auto operator==(SourceLocation const& other) const noexcept -> bool {
return m_line == other.m_line && m_column == other.m_column;
}
Expand Down
106 changes: 105 additions & 1 deletion src/spider/tdl/parser/TaskDefLang.g4
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,110 @@ builtinType returns [std::unique_ptr<spider::tdl::parser::ast::Node> retval]
}
;

ID: [a-zA-Z_][a-zA-Z0-9_]* ;
SPACE: [ \t\r\n] -> skip ;
COMMENT: '//' (~[\r\n])* -> skip;

RESERVED_CONTROL_FLOW_WORDS
: 'if'
| 'else'
| 'elif'
| 'switch'
| 'case'
| 'while'
| 'for'
| 'loop'
| 'do'
| 'break'
| 'continue'
| 'return'
| 'goto'
| 'pass'
| 'yield'
;

RESERVED_DEF_WORDS
: 'class'
| 'struct'
| 'enum'
| 'union'
| 'interface'
| 'namespace'
| 'using'
| 'typedef'
| 'def'
| 'fn'
| 'let'
| 'module'
| 'import'
;

RESERVED_TYPE_AND_STORAGE_WORDS
: 'int'
| 'long'
| 'short'
| 'byte'
| 'signed'
| 'unsigned'
| 'char'
| 'string'
| 'str'
| 'void'
| 'const'
| 'static'
| 'volatile'
| 'register'
| 'final'
| 'abstract'
| 'this'
| 'self'
| 'new'
| 'delete'
| 'null'
| 'nullptr'
| 'true'
| 'false'
| 'True'
| 'False'
;
Comment on lines +325 to +357
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Resolve potential mismatch for float/double/bool between RESERVED_ and builtinType literals*

Similar duplication exists for 'float', 'double', and 'bool': they appear as string literals in builtinType and inside RESERVED_TYPE_AND_STORAGE_WORDS. If the lexer emits RESERVED_TYPE_AND_STORAGE_WORDS for these, builtinType branches expecting T__N ('float', etc.) won’t match. While this may “work by accident” today, it’s fragile.

Preferred fix: introduce dedicated tokens and reference them in builtinType; remove duplicates from RESERVED_TYPE_AND_STORAGE_WORDS.

@@
 builtinType returns [std::unique_ptr<spider::tdl::parser::ast::Node> retval]
@@
-| 'float' {
+| KW_FLOAT {
     $retval = spider::tdl::parser::ast::Float::create(
             spider::tdl::parser::ast::FloatSpec::Float,
             loc
     );
 }
- | 'double' {
+| KW_DOUBLE {
     $retval = spider::tdl::parser::ast::Float::create(
             spider::tdl::parser::ast::FloatSpec::Double,
             loc
     );
 }
-| 'bool' {
+| KW_BOOL {
     $retval = spider::tdl::parser::ast::Bool::create(loc);
 }
@@
 RESERVED_TYPE_AND_STORAGE_WORDS
-: 'int'
+: 'int'
 | 'long'
@@
-| 'float'
-| 'double'
-| 'bool'
+/* 'float'|'double'|'bool' handled by KW_FLOAT|KW_DOUBLE|KW_BOOL */
@@
 ;
+
+// Dedicated tokens for types referenced in parser rules
+KW_FLOAT: 'float';
+KW_DOUBLE: 'double';
+KW_BOOL: 'bool';

If you intentionally want to keep them only as literals, delete them from RESERVED_TYPE_AND_STORAGE_WORDS instead to remove the ambiguity.

Please verify that tests covering float/double/bool parsing still pass after this change.


🏁 Script executed:

#!/bin/bash
# Display the builtinType parser rule (to inspect float/double/bool usage)
rg -n 'builtinType returns' -C20 src/spider/tdl/parser/TaskDefLang.g4

# Check for existing token definitions for dedicated float/double/bool tokens
rg -n 'KW_FLOAT' -g 'src/spider/tdl/parser/TaskDefLang.g4'
rg -n 'KW_DOUBLE' -g 'src/spider/tdl/parser/TaskDefLang.g4'
rg -n 'KW_BOOL' -g 'src/spider/tdl/parser/TaskDefLang.g4'

# Display the RESERVED_TYPE_AND_STORAGE_WORDS lexer rule to confirm duplicates
rg -n 'RESERVED_TYPE_AND_STORAGE_WORDS' -C20 src/spider/tdl/parser/TaskDefLang.g4

Length of output: 2259


Deduplicate float/double/bool tokens in TaskDefLang.g4

To avoid the lexer capturing ‘float’, ‘double’ and ‘bool’ as part of RESERVED_TYPE_AND_STORAGE_WORDS—thus blocking your builtinType parser rule from ever seeing those literals—introduce explicit tokens for these keywords and remove them from the reserved-word set.

Affected locations:

  • src/spider/tdl/parser/TaskDefLang.g4: builtinType parser rule (currently lines 258–…)
  • src/spider/tdl/parser/TaskDefLang.g4: RESERVED_TYPE_AND_STORAGE_WORDS lexer rule (lines 325–337)
  • Add new lexer definitions for KW_FLOAT, KW_DOUBLE, KW_BOOL

Proposed diff:

--- a/src/spider/tdl/parser/TaskDefLang.g4
+++ b/src/spider/tdl/parser/TaskDefLang.g4
@@ builtinType returns [std::unique_ptr<spider::tdl::parser::ast::Node> retval]
- | 'float' {
+ | KW_FLOAT {
     $retval = spider::tdl::parser::ast::Float::create(
             spider::tdl::parser::ast::FloatSpec::Float,
             loc
     );
 }
- | 'double' {
+ | KW_DOUBLE {
     $retval = spider::tdl::parser::ast::Float::create(
             spider::tdl::parser::ast::FloatSpec::Double,
             loc
     );
 }
- | 'bool' {
+ | KW_BOOL {
     $retval = spider::tdl::parser::ast::Bool::create(loc);
 }
@@ RESERVED_TYPE_AND_STORAGE_WORDS
- | 'float'
- | 'double'
- | 'bool'
+ /* 'float'|'double'|'bool' handled by KW_FLOAT|KW_DOUBLE|KW_BOOL */
@@
 ;
+
+// Dedicated tokens for float/double/bool
+KW_FLOAT : 'float';
+KW_DOUBLE: 'double';
+KW_BOOL  : 'bool';

Please verify that all existing tests for parsing float/double/bool still pass after applying this change.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
RESERVED_TYPE_AND_STORAGE_WORDS
: 'int'
| 'long'
| 'short'
| 'byte'
| 'signed'
| 'unsigned'
| 'char'
| 'string'
| 'str'
| 'float'
| 'double'
| 'bool'
| 'void'
| 'const'
| 'static'
| 'auto'
| 'volatile'
| 'register'
| 'final'
| 'abstract'
| 'this'
| 'self'
| 'new'
| 'delete'
| 'null'
| 'nullptr'
| 'None'
| 'true'
| 'false'
| 'True'
| 'False'
;
// --- In the parser rule for builtinType (around line 258) ---
builtinType
returns [std::unique_ptr<spider::tdl::parser::ast::Node> retval]
: /* … other type cases … */
// replace the string‐literal cases for float/double/bool with the new tokens
| KW_FLOAT {
$retval = spider::tdl::parser::ast::Float::create(
spider::tdl::parser::ast::FloatSpec::Float,
loc
);
}
| KW_DOUBLE {
$retval = spider::tdl::parser::ast::Float::create(
spider::tdl::parser::ast::FloatSpec::Double,
loc
);
}
| KW_BOOL {
$retval = spider::tdl::parser::ast::Bool::create(loc);
}
;
// --- In the lexer rule RESERVED_TYPE_AND_STORAGE_WORDS (around line 325) ---
RESERVED_TYPE_AND_STORAGE_WORDS
: 'int'
| 'long'
| 'short'
| 'byte'
| 'signed'
| 'unsigned'
| 'char'
| 'string'
| 'str'
| 'const'
| 'static'
| 'auto'
| 'volatile'
| 'register'
| 'final'
| 'abstract'
| 'this'
| 'self'
| 'new'
| 'delete'
| 'null'
| 'nullptr'
| 'None'
| 'true'
| 'false'
| 'True'
| 'False'
- | 'float'
- | 'double'
/* 'float'|'double'|'bool' handled by KW_FLOAT|KW_DOUBLE|KW_BOOL */
;
// Dedicated tokens for the floating-point and boolean keywords
KW_FLOAT : 'float';
KW_DOUBLE: 'double';
KW_BOOL : 'bool';


RESERVED_ERROR_HANDLING_WORDS
: 'try'
| 'catch'
| 'throw'
| 'throws'
| 'raise'
| 'finally'
| 'assert'
| 'except'
;

RESERVED_ACCESS_CONTROL_WORDS
: 'public'
| 'private'
| 'protected'
| 'internal'
| 'friend'
;

RESERVED_OTHER_WORDS
: 'operator'
| 'inline'
| 'virtual'
| 'override'
| 'extern'
| 'sizeof'
| 'await'
| 'async'
| 'with'
| 'global'
| 'nonlocal'
| 'and'
| 'or'
| 'not'
| 'in'
| 'is'
| 'del'
;

// ID must be defined after RESERVED_* so that the reserved words get higher precedence.
ID: [a-zA-Z_][a-zA-Z0-9_]* ;
Comment on lines +404 to +405
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Good: ID placed after RESERVED_ to ensure precedence. Add guard tests.*

The placement and explanatory comment are correct. To avoid regressions, add unit tests asserting that representative reserved words (e.g., return, class, True) are not lexed as ID, while prefixes/suffixes like returnValue, className, isTrue are lexed as ID.

You can run this repository‑friendly script to detect overlaps between reserved words and parser literals (helps catch the 'struct'/'namespace'/'fn' conflict):

Expected (after fixing): overlap should be empty or limited to literals that are not used as parser tokens. If you still see 'namespace', 'struct', or 'fn' in the overlap, please adjust as suggested above.


🏁 Script executed:

#!/bin/bash
set -euo pipefail

GRAMMAR=src/spider/tdl/parser/TaskDefLang.g4

python - << 'PY'
import re, sys, pathlib
p = pathlib.Path(sys.argv[1]).read_text()

# Collect reserved words (the right-hand side literals in RESERVED_* rules)
reserved = set(re.findall(r"RESERVED_[A-Z_]+\s*:[^;]*;", p, flags=re.S))
reserved = set(sum([re.findall(r"'([^']+)'", block) for block in reserved], []))

# Collect all single-quoted literals in the grammar
literals = set(re.findall(r"'([^']+)'", p))

# Intersection shows potential lexer/parser literal conflicts
overlap = sorted(reserved & literals)
print("Overlap between RESERVED_* and parser literals:")
for s in overlap:
    print(" -", s)
PY
"$GRAMMAR"

Length of output: 186


🏁 Script executed:

#!/bin/bash
set -euo pipefail

GRAMMAR=src/spider/tdl/parser/TaskDefLang.g4

python3 - "$GRAMMAR" << 'PY'
import re, pathlib, sys

# Read the grammar file
p = pathlib.Path(sys.argv[1]).read_text()

# Extract RESERVED_* rule literals
reserved_blocks = re.findall(r"RESERVED_[A-Z_]+\s*:[^;]*;", p, flags=re.S)
reserved = set(sum([re.findall(r"'([^']+)'", block) for block in reserved_blocks], []))

# Extract all single-quoted literals
literals = set(re.findall(r"'([^']+)'", p))

# Compute overlap
overlap = sorted(reserved & literals)

print("Overlap between RESERVED_* and parser literals:")
for word in overlap:
    print(" -", word)
PY

Length of output: 931


Address Reserved vs Literal Token Conflicts in Grammar

The overlap detection script reveals that numerous reserved words (e.g. return, class, namespace, struct, fn, etc.) are still being lexed as implicit parser literals rather than as your explicit RESERVED_* tokens. This will cause reserved keywords to never match their intended token rules.

• File requiring fixes:

  • src/spider/tdl/parser/TaskDefLang.g4
    – Replace every string literal occurrence of a reserved word in parser rules with its corresponding RESERVED_* token.
    – Remove or refactor implicit literals for keywords so they no longer generate T__N tokens before your named lexer rules.
    • After correcting the grammar, re-run the overlap-detection script to confirm no reserved words intersect with literals.
    • Retain the suggestion to add guard tests ensuring that:
  • Representative reserved words (e.g., return, class, True) are not recognized as ID.
  • Identifiers containing those words as prefixes or suffixes (e.g., returnValue, className, isTrue) still lex as ID.
🤖 Prompt for AI Agents
In src/spider/tdl/parser/TaskDefLang.g4 around lines 386-387, parser rules still
include string literal keywords which get turned into implicit T__N tokens and
conflict with your explicit RESERVED_* lexer rules; update every parser rule
that currently uses a keyword string (e.g. "return", "class", "namespace",
"struct", "fn", "True", etc.) to use the corresponding RESERVED_* token name
instead, remove or refactor any remaining implicit literal occurrences so they
no longer produce T__N tokens (ensure all RESERVED_* lexer rules remain
positioned before the ID rule), re-run the overlap-detection script to confirm
no overlaps, and add unit tests asserting reserved words are not lexed as ID
while identifiers containing those words as substrings still lex as ID.

277 changes: 223 additions & 54 deletions src/spider/tdl/parser/antlr_generated/TaskDefLangLexer.cpp

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/spider/tdl/parser/antlr_generated/TaskDefLangLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class TaskDefLangLexer : public antlr4::Lexer {
T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7,
T__7 = 8, T__8 = 9, T__9 = 10, T__10 = 11, T__11 = 12, T__12 = 13, T__13 = 14,
T__14 = 15, T__15 = 16, T__16 = 17, T__17 = 18, T__18 = 19, T__19 = 20,
T__20 = 21, T__21 = 22, T__22 = 23, ID = 24, SPACE = 25, COMMENT = 26
T__20 = 21, T__21 = 22, T__22 = 23, SPACE = 24, COMMENT = 25, RESERVED_CONTROL_FLOW_WORDS = 26,
RESERVED_DEF_WORDS = 27, RESERVED_TYPE_AND_STORAGE_WORDS = 28, RESERVED_ERROR_HANDLING_WORDS = 29,
RESERVED_ACCESS_CONTROL_WORDS = 30, RESERVED_OTHER_WORDS = 31, ID = 32
};

explicit TaskDefLangLexer(antlr4::CharStream *input);
Expand Down
8 changes: 5 additions & 3 deletions src/spider/tdl/parser/antlr_generated/TaskDefLangParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ void taskdeflangParserInitialize() {
},
std::vector<std::string>{
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "ID", "SPACE", "COMMENT"
"", "", "", "", "", "", "", "SPACE", "COMMENT", "RESERVED_CONTROL_FLOW_WORDS",
"RESERVED_DEF_WORDS", "RESERVED_TYPE_AND_STORAGE_WORDS", "RESERVED_ERROR_HANDLING_WORDS",
"RESERVED_ACCESS_CONTROL_WORDS", "RESERVED_OTHER_WORDS", "ID"
}
);
static const int32_t serializedATNSegment[] = {
4,1,26,186,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,
4,1,32,186,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,
7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,7,
14,2,15,7,15,2,16,7,16,1,0,1,0,1,0,1,0,1,0,1,0,5,0,41,8,0,10,0,12,0,44,
9,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,2,4,2,58,8,2,11,2,12,
Expand Down Expand Up @@ -114,7 +116,7 @@ void taskdeflangParserInitialize() {
96,94,1,0,0,0,96,97,1,0,0,0,97,15,1,0,0,0,98,96,1,0,0,0,99,100,5,11,0,
0,100,101,3,18,9,0,101,102,5,2,0,0,102,104,3,14,7,0,103,105,5,10,0,0,
104,103,1,0,0,0,104,105,1,0,0,0,105,106,1,0,0,0,106,107,5,3,0,0,107,108,
5,7,0,0,108,109,6,8,-1,0,109,17,1,0,0,0,110,111,5,24,0,0,111,112,6,9,
5,7,0,0,108,109,6,8,-1,0,109,17,1,0,0,0,110,111,5,32,0,0,111,112,6,9,
-1,0,112,19,1,0,0,0,113,114,3,32,16,0,114,115,6,10,-1,0,115,120,1,0,0,
0,116,117,3,18,9,0,117,118,6,10,-1,0,118,120,1,0,0,0,119,113,1,0,0,0,
119,116,1,0,0,0,120,21,1,0,0,0,121,122,3,20,10,0,122,123,6,11,-1,0,123,
Expand Down
4 changes: 3 additions & 1 deletion src/spider/tdl/parser/antlr_generated/TaskDefLangParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class TaskDefLangParser : public antlr4::Parser {
T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7,
T__7 = 8, T__8 = 9, T__9 = 10, T__10 = 11, T__11 = 12, T__12 = 13, T__13 = 14,
T__14 = 15, T__15 = 16, T__16 = 17, T__17 = 18, T__18 = 19, T__19 = 20,
T__20 = 21, T__21 = 22, T__22 = 23, ID = 24, SPACE = 25, COMMENT = 26
T__20 = 21, T__21 = 22, T__22 = 23, SPACE = 24, COMMENT = 25, RESERVED_CONTROL_FLOW_WORDS = 26,
RESERVED_DEF_WORDS = 27, RESERVED_TYPE_AND_STORAGE_WORDS = 28, RESERVED_ERROR_HANDLING_WORDS = 29,
RESERVED_ACCESS_CONTROL_WORDS = 30, RESERVED_OTHER_WORDS = 31, ID = 32
};

enum {
Expand Down
14 changes: 10 additions & 4 deletions src/spider/tdl/parser/ast/node_impl/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,27 @@ auto Function::serialize_to_str(size_t indentation_level) const

if (false == serialized_params.empty()) {
return fmt::format(
"{}[Function]:\n{}Name:{}\n{}Return:\n{}\n{}",
"{}[Function]{}:\n{}Name:\n{}\n{}Return:\n{}\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
get_name(),
YSTDLIB_ERROR_HANDLING_TRYX(
get_child_unsafe(0)->serialize_to_str(indentation_level + 2)
),
create_indentation(indentation_level + 1),
serialized_return_type,
fmt::join(serialized_params, "\n")
);
}

return fmt::format(
"{}[Function]:\n{}Name:{}\n{}Return:\n{}\n{}No Params",
"{}[Function]{}:\n{}Name:\n{}\n{}Return:\n{}\n{}No Params",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
get_name(),
YSTDLIB_ERROR_HANDLING_TRYX(
get_child_unsafe(0)->serialize_to_str(indentation_level + 2)
),
create_indentation(indentation_level + 1),
serialized_return_type,
create_indentation(indentation_level + 1)
Expand Down
7 changes: 6 additions & 1 deletion src/spider/tdl/parser/ast/node_impl/Identifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
namespace spider::tdl::parser::ast::node_impl {
auto Identifier::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format("{}[Identifier]:{}", create_indentation(indentation_level), m_name);
return fmt::format(
"{}[Identifier]{}:{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
m_name
);
}
} // namespace spider::tdl::parser::ast::node_impl
3 changes: 2 additions & 1 deletion src/spider/tdl/parser/ast/node_impl/NamedVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ auto NamedVar::create(
auto NamedVar::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format(
"{}[NamedVar]:\n{}Id:\n{}\n{}Type:\n{}",
"{}[NamedVar]{}:\n{}Id:\n{}\n{}Type:\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
YSTDLIB_ERROR_HANDLING_TRYX(get_id()->serialize_to_str(indentation_level + 2)),
create_indentation(indentation_level + 1),
Expand Down
7 changes: 5 additions & 2 deletions src/spider/tdl/parser/ast/node_impl/Namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ auto Namespace::serialize_to_str(size_t indentation_level) const
);

return fmt::format(
"{}[Namespace]:\n{}Name:{}\n{}",
"{}[Namespace]{}:\n{}Name:\n{}\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
get_name(),
YSTDLIB_ERROR_HANDLING_TRYX(
get_child_unsafe(0)->serialize_to_str(indentation_level + 2)
),
fmt::join(serialized_funcs, "\n")
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/spider/tdl/parser/ast/node_impl/StructSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,13 @@ auto StructSpec::serialize_to_str(size_t indentation_level) const
})
);
return fmt::format(
"{}[StructSpec]:\n{}Name:{}\n{}",
"{}[StructSpec]{}:\n{}Name:\n{}\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
get_name(),
YSTDLIB_ERROR_HANDLING_TRYX(
get_child_unsafe(0)->serialize_to_str(indentation_level + 2)
),
fmt::join(serialized_fields, "\n")
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/spider/tdl/parser/ast/node_impl/TranslationUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ auto TranslationUnit::serialize_to_str(size_t indentation_level) const
);

return fmt::format(
"{}[TranslationUnit]:\n{}StructSpecs:\n{}\n{}Namespaces:\n{}",
"{}[TranslationUnit]{}:\n{}StructSpecs:\n{}\n{}Namespaces:\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
fmt::join(serialized_struct_specs, "\n"),
create_indentation(indentation_level + 1),
Expand Down
3 changes: 2 additions & 1 deletion src/spider/tdl/parser/ast/node_impl/type_impl/Struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ auto Struct::create(std::unique_ptr<Node> name, SourceLocation source_location)
auto Struct::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format(
"{}[Type[Struct]]:\n{}Name:\n{}",
"{}[Type[Struct]]{}:\n{}Name:\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
YSTDLIB_ERROR_HANDLING_TRYX(
// The factory function ensures that the first child is of type `Identifier`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ auto List::create(std::unique_ptr<Node> element_type, SourceLocation source_loca
auto List::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format(
"{}[Type[Container[List]]]:\n{}ElementType:\n{}",
"{}[Type[Container[List]]]{}:\n{}ElementType:\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
YSTDLIB_ERROR_HANDLING_TRYX(get_element_type()->serialize_to_str(indentation_level + 2))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ auto Map::create(
auto Map::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format(
"{}[Type[Container[Map]]]:\n{}KeyType:\n{}\n{}ValueType:\n{}",
"{}[Type[Container[Map]]]{}:\n{}KeyType:\n{}\n{}ValueType:\n{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
create_indentation(indentation_level + 1),
YSTDLIB_ERROR_HANDLING_TRYX(get_key_type()->serialize_to_str(indentation_level + 2)),
create_indentation(indentation_level + 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ auto Tuple::serialize_to_str(size_t indentation_level) const
constexpr std::string_view cTypeTag{"[Type[Container[Tuple]]]"};

if (is_empty()) {
return fmt::format("{}{}:Empty", create_indentation(indentation_level), cTypeTag);
return fmt::format(
"{}{}{}:Empty",
create_indentation(indentation_level),
cTypeTag,
get_source_location().serialize_to_str()
);
}

std::vector<std::string> serialized_children;
Expand All @@ -55,9 +60,10 @@ auto Tuple::serialize_to_str(size_t indentation_level) const
})
);
return fmt::format(
"{}{}:\n{}",
"{}{}{}:\n{}",
create_indentation(indentation_level),
cTypeTag,
get_source_location().serialize_to_str(),
fmt::join(serialized_children, "\n")
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
namespace spider::tdl::parser::ast::node_impl::type_impl::primitive_impl {
auto Bool::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format("{}[Type[Primitive[Bool]]]", create_indentation(indentation_level));
return fmt::format(
"{}[Type[Primitive[Bool]]]{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str()
);
}
} // namespace spider::tdl::parser::ast::node_impl::type_impl::primitive_impl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ namespace spider::tdl::parser::ast::node_impl::type_impl::primitive_impl {
auto Float::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format(
"{}[Type[Primitive[Float]]]:{}",
"{}[Type[Primitive[Float]]]{}:{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
YSTDLIB_ERROR_HANDLING_TRYX(serialize_float_spec(m_spec))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ namespace spider::tdl::parser::ast::node_impl::type_impl::primitive_impl {
auto Int::serialize_to_str(size_t indentation_level) const
-> ystdlib::error_handling::Result<std::string> {
return fmt::format(
"{}[Type[Primitive[Int]]]:{}",
"{}[Type[Primitive[Int]]]{}:{}",
create_indentation(indentation_level),
get_source_location().serialize_to_str(),
YSTDLIB_ERROR_HANDLING_TRYX(serialize_int_spec(m_spec))
);
}
Expand Down
Loading
Loading