Skip to content

Commit e90978c

Browse files
authored
Merge pull request #40 from spekary/backtick
Backtick quote for parameters
2 parents fcb6b64 + e655bf5 commit e90978c

8 files changed

Lines changed: 35 additions & 9 deletions

File tree

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
matrix:
1717
os: [ubuntu-latest, windows-latest]
18-
go: ['1.23', '1.22']
18+
go: ['1.25', '1.24']
1919
steps:
2020
- uses: actions/checkout@v4
2121

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func staticTest(_w io.Writer) {
224224
225225
}
226226
227-
func translateTest(t Translater, buf *bytes.Buffer) {
227+
func translateTest(t Translater, _w io.Writer) {
228228
229229
{{t Translate me to some language }}
230230
@@ -562,7 +562,7 @@ import {
562562
}
563563
564564
565-
func writeTemplate(ctx context.Context, buf *bytes.Buffer) {
565+
func writeTemplate(ctx context.Context, _w io.Writer) {
566566
567567
{{# Define the body that will be inserted into the template }}
568568
{{< body }}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/goradd/got
22

33
require (
4-
github.com/goradd/gofile v1.2.0
5-
github.com/stretchr/testify v1.8.4
4+
github.com/goradd/gofile v1.2.1
5+
github.com/stretchr/testify v1.11.1
66
)
77

88
require (

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/goradd/gofile v1.2.0 h1:sCHG3icAFGO8gwl5Yy8llvhlIl8k5uaYa6uE23Z56MA=
44
github.com/goradd/gofile v1.2.0/go.mod h1:ZjSvnGak2csGsJgEu8AgQc06eaoonhg2MzbqXON9o1M=
5+
github.com/goradd/gofile v1.2.1 h1:rbUJ6HIoYWJxDqqRftceb48COv4M0HxkU5d8PdRElD4=
6+
github.com/goradd/gofile v1.2.1/go.mod h1:ZjSvnGak2csGsJgEu8AgQc06eaoonhg2MzbqXON9o1M=
57
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
68
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
79
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
810
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
11+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
12+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
913
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1014
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1115
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

internal/got/lexer.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,16 @@ func splitParams(paramString string) (params []string, err error) {
524524
s.Init(strings.NewReader(paramString))
525525
for tok := s.Scan(); tok != scanner.EOF; tok = s.Scan() {
526526
text := s.TokenText()
527-
if len(text) > 0 && text[0] == '"' && (len(text) == 1 || text[len(text)-1] != '"') {
527+
if len(text) > 0 &&
528+
(text[0] == '"' && (len(text) == 1 || text[len(text)-1] != '"') ||
529+
(text[0] == '`' && (len(text) == 1 || text[len(text)-1] != '`'))) {
528530
err = fmt.Errorf("parameter has a beginning quote with no ending quote: %s", text)
529531
return
530532
}
531533
if text == "," {
532534
currentItem = strings.TrimSpace(currentItem)
533535
if currentItem != "" {
534-
if currentItem[0] == '"' {
536+
if currentItem[0] == '"' || currentItem[0] == '`' {
535537
currentItem, err = strconv.Unquote(currentItem)
536538
if err != nil {
537539
return
@@ -548,7 +550,7 @@ func splitParams(paramString string) (params []string, err error) {
548550
}
549551
}
550552
if currentItem != "" {
551-
if currentItem[0] == '"' {
553+
if currentItem[0] == '"' || currentItem[0] == '`' {
552554
currentItem, err = strconv.Unquote(currentItem)
553555
if err != nil {
554556
return

internal/got/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (p *parser) parseIf(item tokenItem) (items []tokenItem) {
293293

294294
default:
295295
item.typ = itemError
296-
item.val = "unexpected end block item"
296+
item.val = "unexpected end block item: " + endItem.val
297297
return []tokenItem{item}
298298
}
299299
}

internal/testdata/expected/TestSub.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ MeSubstituted:
66
You
77
Not Substituted:
88

9+
Substituted:
10+
You,"Me"
11+
Not Substituted:
12+
,

internal/testdata/src/testSub.tpl.got

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestSub(_w io.Writer) (err error) {
2525
if err = myTest2(_w); err != nil {return}
2626
if err = myTest3(_w); err != nil {return}
2727
if err = myTest4(_w); err != nil {return}
28+
if err = myTest5(_w); err != nil {return}
2829
return
2930
}
3031

@@ -59,6 +60,21 @@ Not Substituted:
5960
return
6061
}
6162

63+
{{define fourth 2}}
64+
$1,$2
65+
{{end fourth}}
66+
67+
func myTest5(_w io.Writer) (err error) {
68+
{{
69+
Substituted:
70+
{{fourth "You", `"Me"`}}
71+
Not Substituted:
72+
{{fourth}}
73+
}}
74+
return
75+
}
76+
77+
6278
func init() {
6379
registry.RegisterTest(TestSub, "TestSub")
6480
}

0 commit comments

Comments
 (0)