diff options
Diffstat (limited to 'src/cmd/asm/internal/lex')
-rw-r--r-- | src/cmd/asm/internal/lex/input.go | 3 | ||||
-rw-r--r-- | src/cmd/asm/internal/lex/lex.go | 12 | ||||
-rw-r--r-- | src/cmd/asm/internal/lex/lex_test.go | 3 | ||||
-rw-r--r-- | src/cmd/asm/internal/lex/tokenizer.go | 11 |
4 files changed, 20 insertions, 9 deletions
diff --git a/src/cmd/asm/internal/lex/input.go b/src/cmd/asm/internal/lex/input.go index a43953b515..da4ebe6d6e 100644 --- a/src/cmd/asm/internal/lex/input.go +++ b/src/cmd/asm/internal/lex/input.go @@ -109,6 +109,9 @@ func (in *Input) Next() ScanToken { in.Error("'#' must be first item on line") } in.beginningOfLine = in.hash() + in.text = "#" + return '#' + case scanner.Ident: // Is it a macro name? name := in.Stack.Text() diff --git a/src/cmd/asm/internal/lex/lex.go b/src/cmd/asm/internal/lex/lex.go index f1f7da7911..7cd41a55a9 100644 --- a/src/cmd/asm/internal/lex/lex.go +++ b/src/cmd/asm/internal/lex/lex.go @@ -22,11 +22,13 @@ type ScanToken rune const ( // Asm defines some two-character lexemes. We make up // a rune/ScanToken value for them - ugly but simple. - LSH ScanToken = -1000 - iota // << Left shift. - RSH // >> Logical right shift. - ARR // -> Used on ARM for shift type 3, arithmetic right shift. - ROT // @> Used on ARM for shift type 4, rotate right. - macroName // name of macro that should not be expanded + LSH ScanToken = -1000 - iota // << Left shift. + RSH // >> Logical right shift. + ARR // -> Used on ARM for shift type 3, arithmetic right shift. + ROT // @> Used on ARM for shift type 4, rotate right. + Include // included file started here + BuildComment // //go:build or +build comment + macroName // name of macro that should not be expanded ) // IsRegisterShift reports whether the token is one of the ARM register shift operators. diff --git a/src/cmd/asm/internal/lex/lex_test.go b/src/cmd/asm/internal/lex/lex_test.go index f606ffe07b..51679d2fbc 100644 --- a/src/cmd/asm/internal/lex/lex_test.go +++ b/src/cmd/asm/internal/lex/lex_test.go @@ -281,6 +281,9 @@ func drain(input *Input) string { if tok == scanner.EOF { return buf.String() } + if tok == '#' { + continue + } if buf.Len() > 0 { buf.WriteByte('.') } diff --git a/src/cmd/asm/internal/lex/tokenizer.go b/src/cmd/asm/internal/lex/tokenizer.go index aef9ea8636..861a2d421d 100644 --- a/src/cmd/asm/internal/lex/tokenizer.go +++ b/src/cmd/asm/internal/lex/tokenizer.go @@ -107,10 +107,13 @@ func (t *Tokenizer) Next() ScanToken { if t.tok != scanner.Comment { break } - length := strings.Count(s.TokenText(), "\n") - t.line += length - // TODO: If we ever have //go: comments in assembly, will need to keep them here. - // For now, just discard all comments. + text := s.TokenText() + t.line += strings.Count(text, "\n") + // TODO: Use constraint.IsGoBuild once it exists. + if strings.HasPrefix(text, "//go:build") { + t.tok = BuildComment + break + } } switch t.tok { case '\n': |