feat(asm): symbol-valued DATA, division slash in symbols and plain semicolons
Assisted-by: GLM 5.3 Flash
This commit is contained in:
+41
-2
@@ -32,9 +32,8 @@ func (e Error) Error() string {
|
||||
// returned file is usable even when errors is non-empty.
|
||||
func Parse(path, src string) (*ast.File, []error) {
|
||||
tokens := lexer.Tokenize(src)
|
||||
lines := splitLines(tokens)
|
||||
p := &state{path: path}
|
||||
p.parse(lines)
|
||||
p.parse(statementLines(tokens))
|
||||
return p.file, p.errs
|
||||
}
|
||||
|
||||
@@ -73,6 +72,46 @@ func splitLines(tokens []token.Token) [][]token.Token {
|
||||
return lines
|
||||
}
|
||||
|
||||
// statementLines turns the token stream into the logical lines the parser
|
||||
// reads: physical lines split at the ';' statement separators, exactly the
|
||||
// way the expansion path treats the expanded bodies. The runtime writes
|
||||
// "ROLQ $3, DI; ROLQ $13, DI" and "REP; MOVSB" in plain files, and the
|
||||
// separator carries no meaning beyond the break. Comments are statement
|
||||
// text, not structure: the lexer delivers a whole comment as one token, so
|
||||
// a ';' inside a comment is never a separator; a comment after a statement
|
||||
// stays on that statement's line; and a comment that sits between
|
||||
// statements (the runtime's "NO_LOCAL_POINTERS; /* … */" style) stands as
|
||||
// its own logical line, like a whole-line comment.
|
||||
func statementLines(tokens []token.Token) [][]token.Token {
|
||||
var out [][]token.Token
|
||||
var cur []token.Token
|
||||
flush := func() {
|
||||
if len(cur) > 0 {
|
||||
out = append(out, cur)
|
||||
cur = nil
|
||||
}
|
||||
}
|
||||
for _, t := range tokens {
|
||||
switch t.Kind {
|
||||
case token.EOF:
|
||||
// The stream's terminator is not statement content.
|
||||
case token.Newline, token.Semicolon:
|
||||
flush()
|
||||
case token.Comment:
|
||||
if len(cur) > 0 {
|
||||
cur = append(cur, t)
|
||||
} else {
|
||||
out = append(out, []token.Token{t})
|
||||
}
|
||||
flush()
|
||||
default:
|
||||
cur = append(cur, t)
|
||||
}
|
||||
}
|
||||
flush()
|
||||
return out
|
||||
}
|
||||
|
||||
func (p *state) parse(lines [][]token.Token) {
|
||||
p.file = &ast.File{Path: p.path, Macros: map[string]bool{}}
|
||||
for _, line := range lines {
|
||||
|
||||
Reference in New Issue
Block a user