Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
b3dd3277
Commit
b3dd3277
authored
Oct 06, 2011
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
template: fix comments with different delimiters.
R=golang-dev, dsymonds CC=golang-dev
https://golang.org/cl/5208042
parent
dcf53189
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
11 deletions
+18
-11
src/pkg/template/exec_test.go
src/pkg/template/exec_test.go
+12
-5
src/pkg/template/parse/lex.go
src/pkg/template/parse/lex.go
+5
-5
src/pkg/template/parse/lex_test.go
src/pkg/template/parse/lex_test.go
+1
-1
No files found.
src/pkg/template/exec_test.go
View file @
b3dd3277
...
...
@@ -507,14 +507,21 @@ func TestDelims(t *testing.T) {
for
i
:=
0
;
i
<
len
(
delimPairs
);
i
+=
2
{
text
:=
".Str"
left
:=
delimPairs
[
i
+
0
]
trueLeft
:=
left
right
:=
delimPairs
[
i
+
1
]
trueRight
:=
right
if
left
==
""
{
// default case
t
ext
=
"{{"
+
text
t
rueLeft
=
"{{"
}
if
right
==
""
{
// default case
t
ext
=
text
+
"}}"
t
rueRight
=
"}}"
}
text
=
left
+
text
+
right
text
=
trueLeft
+
text
+
trueRight
// Now add a comment
text
+=
trueLeft
+
"/*comment*/"
+
trueRight
// Now add an action containing a string.
text
+=
trueLeft
+
`"`
+
trueLeft
+
`"`
+
trueRight
// At this point text looks like `{{.Str}}{{/*comment*/}}{{"{{"}}`.
tmpl
,
err
:=
New
(
"delims"
)
.
Delims
(
left
,
right
)
.
Parse
(
text
)
if
err
!=
nil
{
t
.
Fatalf
(
"delim %q text %q parse err %s"
,
left
,
text
,
err
)
...
...
@@ -524,8 +531,8 @@ func TestDelims(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"delim %q exec err %s"
,
left
,
err
)
}
if
b
.
String
()
!=
hello
{
t
.
Error
(
"expected %q got %q"
,
hello
,
b
.
String
())
if
b
.
String
()
!=
hello
+
trueLeft
{
t
.
Error
(
"expected %q got %q"
,
hello
+
trueLeft
,
b
.
String
())
}
}
}
...
...
src/pkg/template/parse/lex.go
View file @
b3dd3277
...
...
@@ -230,8 +230,8 @@ func lex(name, input, left, right string) *lexer {
const
(
leftDelim
=
"{{"
rightDelim
=
"}}"
leftComment
=
"
{{
/*"
rightComment
=
"*/
}}
"
leftComment
=
"/*"
rightComment
=
"*/"
)
// lexText scans until an opening action delimiter, "{{".
...
...
@@ -257,7 +257,7 @@ func lexText(l *lexer) stateFn {
// lexLeftDelim scans the left delimiter, which is known to be present.
func
lexLeftDelim
(
l
*
lexer
)
stateFn
{
if
strings
.
HasPrefix
(
l
.
input
[
l
.
pos
:
],
leftComment
)
{
if
strings
.
HasPrefix
(
l
.
input
[
l
.
pos
:
],
l
.
leftDelim
+
l
eftComment
)
{
return
lexComment
}
l
.
pos
+=
len
(
l
.
leftDelim
)
...
...
@@ -267,11 +267,11 @@ func lexLeftDelim(l *lexer) stateFn {
// lexComment scans a comment. The left comment marker is known to be present.
func
lexComment
(
l
*
lexer
)
stateFn
{
i
:=
strings
.
Index
(
l
.
input
[
l
.
pos
:
],
rightComment
)
i
:=
strings
.
Index
(
l
.
input
[
l
.
pos
:
],
rightComment
+
l
.
rightDelim
)
if
i
<
0
{
return
l
.
errorf
(
"unclosed comment"
)
}
l
.
pos
+=
i
+
len
(
rightComment
)
l
.
pos
+=
i
+
len
(
rightComment
)
+
len
(
l
.
rightDelim
)
l
.
ignore
()
return
lexText
}
...
...
src/pkg/template/parse/lex_test.go
View file @
b3dd3277
...
...
@@ -222,7 +222,7 @@ func TestLex(t *testing.T) {
}
}
// Some easy cases from above, but with delimiters
are
$$ and @@
// Some easy cases from above, but with delimiters $$ and @@
var
lexDelimTests
=
[]
lexTest
{
{
"punctuation"
,
"$$,@%{{}}@@"
,
[]
item
{
tLeftDelim
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment