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

View File

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

View File

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

View File

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

View File

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