parse icon indicating copy to clipboard operation
parse copied to clipboard

Document usage of JS parsers

Open RayLuxembourg opened this issue 3 years ago • 1 comments

please provide an example so I could PR to add into readme.

discovered

func pareJSFile(path string) {
	jsStr, err := ioutil.ReadFile(path)
	if err != nil {
		fmt.Println(err)
		return
	}
	jsAst,err:= js.Parse(parse.NewInputBytes(jsStr))
	if err != nil {
		log.Fatal(err)
	}
	v:= Visitor{}
	js.Walk(v,jsAst)
}

RayLuxembourg avatar Aug 09 '21 12:08 RayLuxembourg

@RayLuxembourg

	l := js.NewLexer(parse.NewInputString(script))
	for {
		tt, text := l.Next()
		switch tt {
		case js.ErrorToken:
			if l.Err() != io.EOF {
				fmt.Println("Error on line:", l.Err())
			}
			return params
		case js.VarToken:
			vardiscover = true
		case js.StringToken:
			str := string(text)
			if vardiscover {
				params = append(params, str)
			}
			vardiscover = false
		}
	}

wrenchonline avatar Sep 25 '21 05:09 wrenchonline