]> Cypherpunks repositories - gostls13.git/commitdiff
exp/template: change the name from 'metacharacter' to 'delimiter',
authorRob Pike <r@golang.org>
Thu, 7 Jul 2011 00:56:33 +0000 (10:56 +1000)
committerRob Pike <r@golang.org>
Thu, 7 Jul 2011 00:56:33 +0000 (10:56 +1000)
because that's what they are.
No semantic change.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4675060

src/pkg/exp/template/lex.go
src/pkg/exp/template/lex_test.go
src/pkg/exp/template/parse.go
src/pkg/exp/template/parse_test.go
src/pkg/exp/template/set.go

index 7230f5b02522bd68498716e8c2a6a500e4727739..d78152979f248f9986f8149e2e6a2785dbd45af9 100644 (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':
index ba0568ef3cea07f0640822819558e7ce12b4f4c3..256ec04d853abc569367891f3cb2f2f7f7b15a73 100644 (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"}
index 2ef95fd45722e5bf93de2af78416f78b802ec311..8b2d60207514d244f8949f77adcf751771bae42e 100644 (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:
index 34b0da6ebf97b27cce9c2d0a1e74d05f2b0416b9..71580f8b60344321d6883a568776a01b45deb137 100644 (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]])])]`},
index 58bbb0c1296d014dfd296e5daeac67ed5d608da2..492e270e1297c3ce9c0c41f4f571ef822269bbb7 100644 (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)