Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions cmd/chore/gopminispec/minispec.gop
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

package main

import (
"gop/doc/spec/mini"
"os"
Expand All @@ -26,4 +24,4 @@ if len(os.Args) < 2 {
return
}

echo mini.parseFile(nil, os.Args[1], nil, 0)
echo mini.parseFile(nil, os.Args[1], nil)
7 changes: 1 addition & 6 deletions doc/spec/mini/mini.gop
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package mini

import (
"github.com/goplus/gop/parser"
"github.com/goplus/gop/token"
"github.com/goplus/gop/tpl"
)
Expand Down Expand Up @@ -180,11 +179,7 @@ IndexOrSlice = "[" (":" ?Expression | Expression (":" ?Expression | ?",")) "]"

// -----------------------------------------------------------------

// A Mode value is a set of flags (or 0). They control the amount of source code
// parsed and other optional parser functionality.
type Mode = parser.Mode

func ParseFile(fset *token.FileSet, filename string, src any, _ Mode) (f any, err error) {
func ParseFile(fset *token.FileSet, filename string, src any) (f any, err error) {
return cl.Parse(filename, src, &tpl.Config{
Fset: fset,
})
Expand Down
5 changes: 4 additions & 1 deletion tpl/cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,13 @@ func compileExpr(expr ast.Expr, ctx *context) (matcher.Matcher, bool) {
return tokenExpr(token.Token(v), expr, ctx)
case token.STRING:
v, e := strconv.Unquote(lit)
if e != nil || len(v) == 0 {
if e != nil {
ctx.addError(expr.Pos(), "invalid literal "+lit)
break
}
if v == "" {
return matcher.True(), true
}
if c := v[0]; c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '_' {
return matcher.Literal(token.IDENT, v), true
}
Expand Down
17 changes: 17 additions & 0 deletions tpl/matcher/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,23 @@ type Matcher interface {

// -----------------------------------------------------------------------------

type gTrue struct{}

func (p gTrue) Match(src []*types.Token, ctx *Context) (n int, result any, err error) {
return 0, nil, nil
}

func (p gTrue) IsList() bool {
return false
}

// True returns a matcher that always succeeds.
func True() Matcher {
return gTrue{}
}

// -----------------------------------------------------------------------------

type gToken struct {
tok token.Token
}
Expand Down