1
0
mirror of https://github.com/golang/go synced 2024-11-21 20:54:45 -07:00

exp/template: change the name from 'metacharacter' to 'delimiter',

because that's what they are.
No semantic change.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4675060
This commit is contained in:
Rob Pike 2011-07-07 10:56:33 +10:00
parent 582d6e5848
commit 8d538c6d3d
5 changed files with 34 additions and 34 deletions

View File

@ -41,11 +41,11 @@ const (
itemEOF
itemField // alphanumeric identifier, starting with '.', possibly chained ('.x.y')
itemIdentifier // alphanumeric identifier
itemLeftMeta // left meta-string
itemLeftDelim // left action delimiter
itemNumber // simple number, including imaginary
itemPipe // pipe symbol
itemRawString // raw quoted string (includes quotes)
itemRightMeta // right meta-string
itemRightDelim // right action delimiter
itemString // quoted string (includes quotes)
itemText // plain text
// Keywords appear after all the rest.
@ -68,11 +68,11 @@ var itemName = map[itemType]string{
itemEOF: "EOF",
itemField: "field",
itemIdentifier: "identifier",
itemLeftMeta: "left meta",
itemLeftDelim: "left delim",
itemNumber: "number",
itemPipe: "pipe",
itemRawString: "raw string",
itemRightMeta: "rightMeta",
itemRightDelim: "right delim",
itemString: "string",
// keywords
itemDot: ".",
@ -210,20 +210,20 @@ func lex(name, input string) *lexer {
// state functions
const (
leftMeta = "{{"
rightMeta = "}}"
leftDelim = "{{"
rightDelim = "}}"
leftComment = "{{/*"
rightComment = "*/}}"
)
// lexText scans until a metacharacter
// lexText scans until an opening action delimiter, "{{".
func lexText(l *lexer) stateFn {
for {
if strings.HasPrefix(l.input[l.pos:], leftMeta) {
if strings.HasPrefix(l.input[l.pos:], leftDelim) {
if l.pos > l.start {
l.emit(itemText)
}
return lexLeftMeta
return lexLeftDelim
}
if l.next() == eof {
break
@ -237,13 +237,13 @@ func lexText(l *lexer) stateFn {
return nil
}
// leftMeta scans the left "metacharacter", which is known to be present.
func lexLeftMeta(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) {
return lexComment
}
l.pos += len(leftMeta)
l.emit(itemLeftMeta)
l.pos += len(leftDelim)
l.emit(itemLeftDelim)
return lexInsideAction
}
@ -258,21 +258,21 @@ func lexComment(l *lexer) stateFn {
return lexText
}
// rightMeta scans the right "metacharacter", which is known to be present.
func lexRightMeta(l *lexer) stateFn {
l.pos += len(rightMeta)
l.emit(itemRightMeta)
// lexRightDelim scans the right delimiter, which is known to be present.
func lexRightDelim(l *lexer) stateFn {
l.pos += len(rightDelim)
l.emit(itemRightDelim)
return lexText
}
// lexInsideAction scans the elements inside "metacharacters".
// lexInsideAction scans the elements inside action delimiters.
func lexInsideAction(l *lexer) stateFn {
// Either number, quoted string, or identifier.
// Spaces separate and are ignored.
// Pipe symbols separate and are emitted.
for {
if strings.HasPrefix(l.input[l.pos:], rightMeta) {
return lexRightMeta
if strings.HasPrefix(l.input[l.pos:], rightDelim) {
return lexRightDelim
}
switch r := l.next(); {
case r == eof || r == '\n':

View File

@ -17,8 +17,8 @@ type lexTest struct {
var (
tEOF = item{itemEOF, ""}
tLeft = item{itemLeftMeta, "{{"}
tRight = item{itemRightMeta, "}}"}
tLeft = item{itemLeftDelim, "{{"}
tRight = item{itemRightDelim, "}}"}
tRange = item{itemRange, "range"}
tPipe = item{itemPipe, "|"}
tFor = item{itemIdentifier, "for"}

View File

@ -122,7 +122,7 @@ func (t *textNode) String() string {
return fmt.Sprintf("(text: %q)", t.text)
}
// actionNode holds an action (something bounded by metacharacters).
// actionNode holds an action (something bounded by delimiters).
type actionNode struct {
nodeType
line int
@ -594,7 +594,7 @@ func (t *Template) textOrAction() node {
switch token := t.next(); token.typ {
case itemText:
return newText(token.val)
case itemLeftMeta:
case itemLeftDelim:
return t.action()
default:
t.unexpected(token, "input")
@ -605,7 +605,7 @@ func (t *Template) textOrAction() node {
// Action:
// control
// command ("|" command)*
// Left meta is past. Now get actions.
// Left delim is past. Now get actions.
// First word could be a keyword such as range.
func (t *Template) action() (n node) {
switch token := t.next(); token.typ {
@ -632,7 +632,7 @@ func (t *Template) action() (n node) {
func (t *Template) pipeline(context string) (pipe []*commandNode) {
for {
switch token := t.next(); token.typ {
case itemRightMeta:
case itemRightDelim:
if len(pipe) == 0 {
t.errorf("missing value for %s", context)
}
@ -693,7 +693,7 @@ func (t *Template) withControl() node {
// {{end}}
// End keyword is past.
func (t *Template) endControl() node {
t.expect(itemRightMeta, "end")
t.expect(itemRightDelim, "end")
return newEnd()
}
@ -701,7 +701,7 @@ func (t *Template) endControl() node {
// {{else}}
// Else keyword is past.
func (t *Template) elseControl() node {
t.expect(itemRightMeta, "else")
t.expect(itemRightDelim, "else")
return newElse(t.lex.lineNumber())
}
@ -735,14 +735,14 @@ func (t *Template) templateControl() node {
}
// command:
// space-separated arguments up to a pipeline character or right metacharacter.
// we consume the pipe character but leave the right meta to terminate the action.
// space-separated arguments up to a pipeline character or right delimiter.
// we consume the pipe character but leave the right delim to terminate the action.
func (t *Template) command() *commandNode {
cmd := newCommand()
Loop:
for {
switch token := t.next(); token.typ {
case itemRightMeta:
case itemRightDelim:
t.backup()
break Loop
case itemPipe:

View File

@ -140,7 +140,7 @@ var parseTests = []parseTest{
`[(text: " \t\n")]`},
{"text", "some text", noError,
`[(text: "some text")]`},
{"emptyMeta", "{{}}", hasError,
{"emptyAction", "{{}}", hasError,
`[(action: [])]`},
{"field", "{{.X}}", noError,
`[(action: [(command: [F=[X]])])]`},

View File

@ -93,14 +93,14 @@ func (s *Set) Parse(text string) (err os.Error) {
if t.atEOF() {
return
}
t.expect(itemLeftMeta, context)
t.expect(itemLeftDelim, context)
t.expect(itemDefine, context)
name := t.expect(itemString, context)
t.name, err = strconv.Unquote(name.val)
if err != nil {
t.error(err)
}
t.expect(itemRightMeta, context)
t.expect(itemRightDelim, context)
end := t.parse(false)
if end == nil {
t.errorf("unexpected EOF in %s", context)