Skip to content

Commit

Permalink
fix: go fmt with actual go version
Browse files Browse the repository at this point in the history
  • Loading branch information
tessig committed Sep 1, 2023
1 parent 59e1309 commit 3e3ef9e
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 69 deletions.
3 changes: 1 addition & 2 deletions otto/ast/node.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/*
Package ast declares types representing a JavaScript AST.
Warning
# Warning
The parser and AST interfaces are still works-in-progress (particularly where
node types are concerned) and may change in the future.
*/
package ast

Expand Down
2 changes: 0 additions & 2 deletions otto/file/file.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package file encapsulates the file abstractions used by the ast & parser.
//
package file

import (
Expand Down Expand Up @@ -36,7 +35,6 @@ func (self *Position) isValid() bool {
// line:column A valid position without filename
// file An invalid position with filename
// - An invalid position without filename
//
func (self *Position) String() string {
str := self.Filename
if self.isValid() {
Expand Down
1 change: 0 additions & 1 deletion otto/parser/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func (self *_parser) errorUnexpectedToken(tkn token.Token) error {
}

// ErrorList is a list of *Errors.
//
type ErrorList []*Error

// Add adds an Error with given position and message to an ErrorList.
Expand Down
45 changes: 21 additions & 24 deletions otto/parser/parser.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
/*
Package parser implements a parser for JavaScript.
import (
"flamingo.me/pugtemplate/otto/parser"
)
import (
"flamingo.me/pugtemplate/otto/parser"
)
Parse and return an AST
filename := "" // A filename is optional
src := `
// Sample xyzzy example
(function(){
if (3.14159 > 0) {
console.log("Hello, World.");
return;
}
filename := "" // A filename is optional
src := `
// Sample xyzzy example
(function(){
if (3.14159 > 0) {
console.log("Hello, World.");
return;
}
var xyzzy = NaN;
console.log("Nothing happens.");
return xyzzy;
})();
`
var xyzzy = NaN;
console.log("Nothing happens.");
return xyzzy;
})();
`
// Parse some JavaScript, yielding a *ast.Program and/or an ErrorList
program, err := parser.ParseFile(nil, filename, src, 0)
// Parse some JavaScript, yielding a *ast.Program and/or an ErrorList
program, err := parser.ParseFile(nil, filename, src, 0)
Warning
# Warning
The parser and AST interfaces are still works-in-progress (particularly where
node types are concerned) and may change in the future.
*/
package parser

Expand Down Expand Up @@ -203,9 +202,8 @@ func ParseFileWithSourceMap(fileSet *file.FileSet, filename string, javascriptSo
//
// src may be a string, a byte slice, a bytes.Buffer, or an io.Reader, but it MUST always be in UTF-8.
//
// // Parse some JavaScript, yielding a *ast.Program and/or an ErrorList
// program, err := parser.ParseFile(nil, "", `if (abc > 1) {}`, 0)
//
// // Parse some JavaScript, yielding a *ast.Program and/or an ErrorList
// program, err := parser.ParseFile(nil, "", `if (abc > 1) {}`, 0)
func ParseFile(fileSet *file.FileSet, filename string, src interface{}, mode Mode) (*ast.Program, error) {
return ParseFileWithSourceMap(fileSet, filename, src, nil, mode)
}
Expand All @@ -214,7 +212,6 @@ func ParseFile(fileSet *file.FileSet, filename string, src interface{}, mode Mod
// corresponding ast.FunctionLiteral node.
//
// The parameter list, if any, should be a comma-separated list of identifiers.
//
func ParseFunction(parameterList, body string) (*ast.FunctionLiteral, error) {

src := "(function(" + parameterList + ") {\n" + body + "\n})"
Expand Down
32 changes: 15 additions & 17 deletions otto/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type Token int
// token string (e.g., for the token PLUS, the String() is
// "+"). For all other tokens the string corresponds to the token
// name (e.g. for the token IDENTIFIER, the string is "IDENTIFIER").
//
func (tkn Token) String() string {
if 0 == tkn {
return "UNKNOWN"
Expand Down Expand Up @@ -86,25 +85,24 @@ type _keyword struct {
//
// 7.6.1.2 Future Reserved Words:
//
// const
// class
// enum
// export
// extends
// import
// super
// const
// class
// enum
// export
// extends
// import
// super
//
// 7.6.1.2 Future Reserved Words (strict):
//
// implements
// interface
// let
// package
// private
// protected
// public
// static
//
// implements
// interface
// let
// package
// private
// protected
// public
// static
func IsKeyword(literal string) (Token, bool) {
if keyword, exists := keywordTable[literal]; exists {
if keyword.futureKeyword {
Expand Down
72 changes: 49 additions & 23 deletions pugjs/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ func (t *Tree) parseDefinition() {
}

// itemList:
// textOrAction*
//
// textOrAction*
//
// Terminates at {{end}} or {{else}}, returned separately.
func (t *Tree) itemList() (list *ListNode, next Node) {
list = t.newList(t.peekNonSpace().pos)
Expand All @@ -344,7 +346,8 @@ func (t *Tree) itemList() (list *ListNode, next Node) {
}

// textOrAction:
// text | action
//
// text | action
func (t *Tree) textOrAction() Node {
switch token := t.nextNonSpace(); token.typ {
case itemText:
Expand All @@ -358,8 +361,10 @@ func (t *Tree) textOrAction() Node {
}

// Action:
// control
// command ("|" command)*
//
// control
// command ("|" command)*
//
// Left delim is past. Now get actions.
// First word could be a keyword such as range.
func (t *Tree) action() (n Node) {
Expand Down Expand Up @@ -392,7 +397,8 @@ func (t *Tree) action() (n Node) {
}

// Pipeline:
// declarations? command ('|' command)*
//
// declarations? command ('|' command)*
func (t *Tree) pipeline(context string) (pipe *PipeNode) {
var decl []*VariableNode
token := t.peekNonSpace()
Expand Down Expand Up @@ -494,24 +500,30 @@ func (t *Tree) parseControl(allowElseIf bool, context string) (pos Pos, line int
}

// If:
// {{if pipeline}} itemList {{end}}
// {{if pipeline}} itemList {{else}} itemList {{end}}
//
// {{if pipeline}} itemList {{end}}
// {{if pipeline}} itemList {{else}} itemList {{end}}
//
// If keyword is past.
func (t *Tree) ifControl() Node {
return t.newIf(t.parseControl(true, "if"))
}

// Range:
// {{range pipeline}} itemList {{end}}
// {{range pipeline}} itemList {{else}} itemList {{end}}
//
// {{range pipeline}} itemList {{end}}
// {{range pipeline}} itemList {{else}} itemList {{end}}
//
// Range keyword is past.
func (t *Tree) rangeControl() Node {
return t.newRange(t.parseControl(false, "range"))
}

// With:
// {{with pipeline}} itemList {{end}}
// {{with pipeline}} itemList {{else}} itemList {{end}}
//
// {{with pipeline}} itemList {{end}}
// {{with pipeline}} itemList {{else}} itemList {{end}}
//
// If keyword is past.
func (t *Tree) withControl() Node {
return t.newWith(t.parseControl(false, "with"))
Expand Down Expand Up @@ -545,14 +557,18 @@ func (t *Tree) catchControl() Node {
//}

// End:
// {{end}}
//
// {{end}}
//
// End keyword is past.
func (t *Tree) endControl() Node {
return t.newEnd(t.expect(itemRightDelim, "end").pos)
}

// Else:
// {{else}}
//
// {{else}}
//
// Else keyword is past.
func (t *Tree) elseControl() Node {
// Special case for "else if".
Expand All @@ -566,7 +582,9 @@ func (t *Tree) elseControl() Node {
}

// Block:
// {{block stringValue pipeline}}
//
// {{block stringValue pipeline}}
//
// Block keyword is past.
// The name must be something that can evaluate to a string.
// The pipeline is mandatory.
Expand All @@ -593,7 +611,9 @@ func (t *Tree) blockControl() Node {
}

// Template:
// {{template stringValue pipeline}}
//
// {{template stringValue pipeline}}
//
// Template keyword is past. The name must be something that can evaluate
// to a string.
func (t *Tree) templateControl() Node {
Expand Down Expand Up @@ -626,7 +646,9 @@ func (t *Tree) parseTemplateName(token item, context string) (name string) {
}

// command:
// operand (space operand)*
//
// operand (space operand)*
//
// 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 *Tree) command() *CommandNode {
Expand Down Expand Up @@ -657,7 +679,9 @@ func (t *Tree) command() *CommandNode {
}

// operand:
// term .Field*
//
// term .Field*
//
// An operand is a space-separated component of a command,
// a term possibly followed by field accesses.
// A nil return means the next item is not an operand.
Expand Down Expand Up @@ -691,12 +715,14 @@ func (t *Tree) operand() Node {
}

// term:
// literal (number, string, nil, boolean)
// function (identifier)
// .
// .Field
// $
// '(' pipeline ')'
//
// literal (number, string, nil, boolean)
// function (identifier)
// .
// .Field
// $
// '(' pipeline ')'
//
// A term is a simple "expression".
// A nil return means the next item is not a term.
func (t *Tree) term() Node {
Expand Down
2 changes: 2 additions & 0 deletions pugjs/tpl_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,9 @@ func URLQueryEscaper(args ...interface{}) string {
}

// evalArgs formats the list of arguments into a string. It is therefore equivalent to
//
// fmt.Sprint(args...)
//
// except that each argument is indirected (if a pointer), as required,
// using the same rules as the default string evaluation during template
// execution.
Expand Down

0 comments on commit 3e3ef9e

Please sign in to comment.