Skip to content

ATN construction#65

Draft
Lotes wants to merge 21 commits intomainfrom
lotes/atn-construction
Draft

ATN construction#65
Lotes wants to merge 21 commits intomainfrom
lotes/atn-construction

Conversation

@Lotes
Copy link
Copy Markdown
Collaborator

@Lotes Lotes commented Apr 29, 2026

There is a big Compile Time ATN for construction and a slim Runtime ATN.

I also added a Markdown generator to be able to debug the ATN visually.

Lotes and others added 4 commits April 29, 2026 14:16
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Co-authored-by: Copilot <copilot@github.com>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Comment thread internal/grammar/atn.md
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Comment thread cmd/fastbelt/main.go Outdated
Comment thread parser/allstar/grammar.go Outdated
Comment thread parser/allstar/atn.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggestion: Since we need all of this code in other parts of the parser (not just the lookahead), it might make sense to move it to the parser parent directory.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

FTM a lot of stuff is inside the generator package. Only the Runtime ATN is in the parser package.

Comment thread parser/atn_runtime.go Outdated
// Go code in external packages can construct them as struct literals.
type RuntimeAtomTransition struct {
Target *RuntimeATNState
TokenTypeID int
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggestion: I don't think it's enough to just pass the target token type ID here, because we eventually want to implement token categories like in Chevrotain - see #49. For this, we need an actual reference to the token type.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

FTM I removed the CategoryMatches. Eventually, we can link token types here, if needed.

Comment thread parser/allstar/grammar.go Outdated
Comment thread parser/allstar/atn.go Outdated
Comment thread parser/allstar/grammar.go Outdated
Comment thread internal/generator/atn_md_emit.go Outdated
"typefox.dev/fastbelt/generator"
)

func EmitMarkdownSource(pkgName string, rtn *RuntimeATN, tokenTypeNames map[int]string) generator.Node {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggestion: This part of the code should live in the internal part of the framework - adopters shouldn't be able to call this function IMO.

Comment thread internal/generator/atn_emit.go Outdated
// pkgName – Go package name for the generated file (e.g. "myparser")
// funcName – name of the generated constructor function
// importPath – import path of the allstar package (e.g. "typefox.dev/fastbelt/parser/allstar")
func EmitGoSource(pkgName, funcName, importPath string, rtn *RuntimeATN) generator.Node {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggestion: This part of the code should live in the internal part of the framework - adopters shouldn't be able to call this function IMO.

Comment thread internal/generator/atn_emit.go Outdated
Lotes and others added 12 commits April 30, 2026 17:22
Co-authored-by: Copilot <copilot@github.com>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Co-authored-by: Copilot <copilot@github.com>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Comment thread parser/atn_runtime.go Outdated
// Go code in external packages can construct them as struct literals.
type RuntimeAtomTransition struct {
Target *RuntimeATNState
TokenTypeID int
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

FTM I removed the CategoryMatches. Eventually, we can link token types here, if needed.

Comment thread internal/grammar/atn_gen.go
}

// TokenType carries the type ID and category-match IDs for a token type.
type TokenType struct {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Need to replace this one...

Lotes added 3 commits May 5, 2026 17:54
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Action_Alternatives_1 ATNDecisionId = 0
Action_Group_2 ATNDecisionId = 1
Alternatives_Group_2 ATNDecisionId = 2
Alternatives_Group_3 ATNDecisionId = 3
Copy link
Copy Markdown
Collaborator Author

@Lotes Lotes May 5, 2026

Choose a reason for hiding this comment

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

The counter inside the name looks broken...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The counter refers to the index of all parts in a rule. Only a few are used for the decision map.

Signed-off-by: Markus Rudolph <markus.rudolph@typefox.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants