Repository: a-h/templ (go)

Issue:
Raw go errors if block ends with a comment
**Describe the bug**
Comments in the middle of a raw code block is fine, but a comment at the end will cause an error when generating templates

**To Reproduce**
```templ
// example.templ

package bingo

templ innerDataPatient() {
    {{
        one := "one"
        two := "two"
        // fine
        four := "four"
        // breaks
    }}
    <div></div>
}
```
Then run:
```bash
$ TEMPL_EXPERIMENT=rawgo templ generate
(✗) Error generating code [ file=input.templ error=input.templ parsing error: go code: missing close braces: line 8, col 8 ]
(✗) Event handler failed [ error=failed to generate code for "input.templ": input.templ parsing error: go code: missing close braces: line 8, col 8 ]
(✗) Error [ error=failed to generate code for "input.templ": input.templ parsing error: go code: missing close braces: line 8, col 8 ]
```
**Expected behavior**
A comment at the end of a raw go code block should not cause an error

**Desktop (please complete the following information):**
 - OS: MacOS
 - templ CLI version: v0.2.7.47
- Go version: 1.22.5 darwin/arm64

**Additional context**
I suspect it's a simple parser error

Pull request:
fix: advance past comments in raw go expressions
Fixes #870 

When looking into the internal go/scanner package, I found the final comments are skipped. It works by scanning til the end of a comment, then a goto to the beginning of the Scan function if the mode is not set to ScanComments. If the scanner encounters the final closing brace, the position returned has not advanced. 

I implemented a solution that scans comments and advances the length of the token literal. While writing this description I realized the `end` variable in the go expression extractor probably just needs to be updated properly. Essentially I have implemented 2 fixes. Please review both (small) commits, in case one is a better solution than the other.

Patch:
diff --git a/.version b/.version
index 5cc385c..1148158 100644
--- a/.version
+++ b/.version
@@ -1,1 +1,1 @@
-0.2.759
\ No newline at end of file
+0.2.763
\ No newline at end of file
diff --git a/parser/v2/goexpression/parse.go b/parser/v2/goexpression/parse.go
index 77c413c..22e2db1 100644
--- a/parser/v2/goexpression/parse.go
+++ b/parser/v2/goexpression/parse.go
@@ -112,7 +112,7 @@ func TemplExpression(src string) (start, end int, err error) {
 	errorHandler := func(pos token.Position, msg string) {
 		err = fmt.Errorf("error parsing expression: %v", msg)
 	}
-	s.Init(file, []byte(src), errorHandler, 0)
+	s.Init(file, []byte(src), errorHandler, scanner.ScanComments)
 
 	// Read chains of identifiers, e.g.:
 	// components.Variable
@@ -140,7 +140,7 @@ func Expression(src string) (start, end int, err error) {
 	errorHandler := func(pos token.Position, msg string) {
 		err = fmt.Errorf("error parsing expression: %v", msg)
 	}
-	s.Init(file, []byte(src), errorHandler, 0)
+	s.Init(file, []byte(src), errorHandler, scanner.ScanComments)
 
 	// Read chains of identifiers and constants up until RBRACE, e.g.:
 	// true
@@ -183,6 +183,8 @@ loop:
 			end = int(pos) + len(lit) - 1
 		case token.SEMICOLON:
 			continue
+		case token.COMMENT:
+			end = int(pos) + len(lit) - 1
 		case token.ILLEGAL:
 			return 0, 0, fmt.Errorf("illegal token: %v", lit)
 		default:


Test patch:
diff --git a/parser/v2/gocodeparser_test.go b/parser/v2/gocodeparser_test.go
index dff1443..19fada8 100644
--- a/parser/v2/gocodeparser_test.go
+++ b/parser/v2/gocodeparser_test.go
@@ -91,6 +91,32 @@ func TestGoCodeParser(t *testing.T) {
 				Multiline: true,
 			},
 		},
+		{
+			name: "comments in expression",
+			input: `{{
+	one := "one"
+	two := "two"
+	// Comment in middle of expression.
+	four := "four"
+	// Comment at end of expression.
+}}`,
+			expected: GoCode{
+				Expression: Expression{
+					Value: `
+	one := "one"
+	two := "two"
+	// Comment in middle of expression.
+	four := "four"
+	// Comment at end of expression.`,
+					Range: Range{
+						From: Position{Index: 2, Line: 0, Col: 2},
+						To:   Position{Index: 117, Line: 5, Col: 33},
+					},
+				},
+				TrailingSpace: SpaceNone,
+				Multiline:     true,
+			},
+		},
 	}
 	for _, tt := range tests {
 		tt := tt