feat(struct): add StructDef and dot-access MVP#41
Open
Conversation
Move reserved type-name source to a shared types package and use it from parser + compiler validations. Also reject reserved function names (e.g. Int/I64) while keeping such identifiers valid for variables.
…ecks Introduce StructStatement as a first-class code statement and wire it through parser/codecompiler/compiler flows. Track immutable names via Code.ConstNames for shared redeclaration and CFG write-protection checks. Allow repeated struct type definitions when headers match, and reject only conflicting headers across parse and merged compile validation. Refactor codeparser const-binding validation to operate on identifier lists directly (remove temporary ConstStatement wrapper), and align struct-header comparison helper naming. Update parser/compiler tests for repeated vs conflicting struct definitions and struct statement expectations.
Update StructLiteral.String to print multiline output with indented header and row blocks. Add parser assertion for struct statement string rendering. Validated with go test -race ./parser ./compiler and go test ./...
Remove the defensive nil check when emitting struct row expressions in StructLiteral.String. Validated with go test -race ./parser ./compiler and go test ./...
Use singular Row for Phase 1 struct literals to reflect single-instance semantics and reduce ambiguity with future struct arrays. Update parser/compiler/solver/cfg references and struct parser tests accordingly. Validated with go test -race ./parser ./compiler and go test ./...
Remove trivial isGlobalConst helper and perform ConstNames lookup directly inside isDefined. No behavior change; validated with go test ./compiler.
Guard unknown-header validation when the first-seen struct entry has empty headers. Remove dead seenHeaders tracking in codecompiler and drop unreachable lexer dot-number branch. Add parser regression test for empty init before full struct definition.
Rename validateAndTrackStructHeaders to validateStructHeaders for readability. No behavior changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
StructDefsupport in.ptusing header-row + single value row syntax.sptdot field access (p.name) with parser/type-solver/compiler supportextractvalueCode.Struct(parallel toCode.ConstandCode.Func)Struct_namespace prefix)Syntax covered
p = Person :name age height "Tejas" 35 184.5Implementation notes
.tokenization with.5float compatibilityStructLiteral,DotExpression,StructDefcontainerTests
go test ./...python3 test.py tests/structpython3 test.py