Best Syzkaller code snippet using ast.scanIdent
parse.go
Source:parse.go
...22 return t, err23}24func (t *Tree) parseAny() (Node, error) {25 t.scanner.accept = acceptRune26 t.scanner.mode = scanIdent | scanLbrack | scanEscape27 switch t.scanner.scan() {28 case tokenIdent:29 left := newTextNode(30 t.scanner.string(),31 )32 right, err := t.parseAny()33 switch {34 case err != nil:35 return nil, err36 case right == empty:37 return left, nil38 }39 return newListNode(left, right), nil40 case tokenEOF:41 return empty, nil42 case tokenLbrack:43 left, err := t.parseFunc()44 if err != nil {45 return nil, err46 }47 right, err := t.parseAny()48 switch {49 case err != nil:50 return nil, err51 case right == empty:52 return left, nil53 }54 return newListNode(left, right), nil55 }56 return nil, ErrBadSubstitution57}58func (t *Tree) parseFunc() (Node, error) {59 switch t.scanner.peek() {60 case '#':61 return t.parseLenFunc()62 }63 var name string64 t.scanner.accept = acceptIdent65 t.scanner.mode = scanIdent66 switch t.scanner.scan() {67 case tokenIdent:68 name = t.scanner.string()69 default:70 return nil, ErrBadSubstitution71 }72 switch t.scanner.peek() {73 case ':':74 return t.parseDefaultOrSubstr(name)75 case '=':76 return t.parseDefaultFunc(name)77 case ',', '^':78 return t.parseCasingFunc(name)79 case '/':80 return t.parseReplaceFunc(name)81 case '#':82 return t.parseRemoveFunc(name, acceptHashFunc)83 case '%':84 return t.parseRemoveFunc(name, acceptPercentFunc)85 }86 t.scanner.accept = acceptIdent87 t.scanner.mode = scanRbrack88 switch t.scanner.scan() {89 case tokenRbrack:90 return newFuncNode(name), nil91 default:92 return nil, ErrBadSubstitution93 }94}95// parse a substitution function parameter.96func (t *Tree) parseParam(accept acceptFunc, mode byte) (Node, error) {97 t.scanner.accept = accept98 t.scanner.mode = mode | scanLbrack99 switch t.scanner.scan() {100 case tokenLbrack:101 return t.parseFunc()102 case tokenIdent:103 return newTextNode(104 t.scanner.string(),105 ), nil106 default:107 return nil, ErrBadSubstitution108 }109}110// parse either a default or substring substitution function.111func (t *Tree) parseDefaultOrSubstr(name string) (Node, error) {112 t.scanner.read()113 r := t.scanner.peek()114 t.scanner.unread()115 switch r {116 case '=', '-', '?', '+':117 return t.parseDefaultFunc(name)118 default:119 return t.parseSubstrFunc(name)120 }121}122// parses the ${param:offset} string function123// parses the ${param:offset:length} string function124func (t *Tree) parseSubstrFunc(name string) (Node, error) {125 node := new(FuncNode)126 node.Param = name127 t.scanner.accept = acceptOneColon128 t.scanner.mode = scanIdent129 switch t.scanner.scan() {130 case tokenIdent:131 node.Name = t.scanner.string()132 default:133 return nil, ErrBadSubstitution134 }135 // scan arg[1]136 {137 param, err := t.parseParam(rejectColonClose, scanIdent)138 if err != nil {139 return nil, err140 }141 // param.Value = t.scanner.string()142 node.Args = append(node.Args, param)143 }144 // expect delimiter or close145 t.scanner.accept = acceptColon146 t.scanner.mode = scanIdent | scanRbrack147 switch t.scanner.scan() {148 case tokenRbrack:149 return node, nil150 case tokenIdent:151 // no-op152 default:153 return nil, ErrBadSubstitution154 }155 // scan arg[2]156 {157 param, err := t.parseParam(acceptNotClosing, scanIdent)158 if err != nil {159 return nil, err160 }161 node.Args = append(node.Args, param)162 }163 return node, t.consumeRbrack()164}165// parses the ${param%word} string function166// parses the ${param%%word} string function167// parses the ${param#word} string function168// parses the ${param##word} string function169func (t *Tree) parseRemoveFunc(name string, accept acceptFunc) (Node, error) {170 node := new(FuncNode)171 node.Param = name172 t.scanner.accept = accept173 t.scanner.mode = scanIdent174 switch t.scanner.scan() {175 case tokenIdent:176 node.Name = t.scanner.string()177 default:178 return nil, ErrBadSubstitution179 }180 // scan arg[1]181 {182 param, err := t.parseParam(acceptNotClosing, scanIdent)183 if err != nil {184 return nil, err185 }186 // param.Value = t.scanner.string()187 node.Args = append(node.Args, param)188 }189 return node, t.consumeRbrack()190}191// parses the ${param/pattern/string} string function192// parses the ${param//pattern/string} string function193// parses the ${param/#pattern/string} string function194// parses the ${param/%pattern/string} string function195func (t *Tree) parseReplaceFunc(name string) (Node, error) {196 node := new(FuncNode)197 node.Param = name198 t.scanner.accept = acceptReplaceFunc199 t.scanner.mode = scanIdent200 switch t.scanner.scan() {201 case tokenIdent:202 node.Name = t.scanner.string()203 default:204 return nil, ErrBadSubstitution205 }206 // scan arg[1]207 {208 param, err := t.parseParam(acceptNotSlash, scanIdent|scanEscape)209 if err != nil {210 return nil, err211 }212 node.Args = append(node.Args, param)213 }214 // expect delimiter215 t.scanner.accept = acceptSlash216 t.scanner.mode = scanIdent217 switch t.scanner.scan() {218 case tokenIdent:219 // no-op220 default:221 return nil, ErrBadSubstitution222 }223 // check for blank string224 switch t.scanner.peek() {225 case '}':226 return node, t.consumeRbrack()227 }228 // scan arg[2]229 {230 param, err := t.parseParam(acceptNotClosing, scanIdent|scanEscape)231 if err != nil {232 return nil, err233 }234 node.Args = append(node.Args, param)235 }236 return node, t.consumeRbrack()237}238// parses the ${parameter=word} string function239// parses the ${parameter:=word} string function240// parses the ${parameter:-word} string function241// parses the ${parameter:?word} string function242// parses the ${parameter:+word} string function243func (t *Tree) parseDefaultFunc(name string) (Node, error) {244 node := new(FuncNode)245 node.Param = name246 t.scanner.accept = acceptDefaultFunc247 if t.scanner.peek() == '=' {248 t.scanner.accept = acceptOneEqual249 }250 t.scanner.mode = scanIdent251 switch t.scanner.scan() {252 case tokenIdent:253 node.Name = t.scanner.string()254 default:255 return nil, ErrBadSubstitution256 }257 // check for blank string258 switch t.scanner.peek() {259 case '}':260 return node, t.consumeRbrack()261 }262 // scan arg[1]263 {264 param, err := t.parseParam(acceptNotClosing, scanIdent)265 if err != nil {266 return nil, err267 }268 // param.Value = t.scanner.string()269 node.Args = append(node.Args, param)270 }271 return node, t.consumeRbrack()272}273// parses the ${param,} string function274// parses the ${param,,} string function275// parses the ${param^} string function276// parses the ${param^^} string function277func (t *Tree) parseCasingFunc(name string) (Node, error) {278 node := new(FuncNode)279 node.Param = name280 t.scanner.accept = acceptCasingFunc281 t.scanner.mode = scanIdent282 switch t.scanner.scan() {283 case tokenIdent:284 node.Name = t.scanner.string()285 default:286 return nil, ErrBadSubstitution287 }288 return node, t.consumeRbrack()289}290// parses the ${#param} string function291func (t *Tree) parseLenFunc() (Node, error) {292 node := new(FuncNode)293 t.scanner.accept = acceptOneHash294 t.scanner.mode = scanIdent295 switch t.scanner.scan() {296 case tokenIdent:297 node.Name = t.scanner.string()298 default:299 return nil, ErrBadSubstitution300 }301 t.scanner.accept = acceptIdent302 t.scanner.mode = scanIdent303 switch t.scanner.scan() {304 case tokenIdent:305 node.Param = t.scanner.string()306 default:307 return nil, ErrBadSubstitution308 }309 return node, t.consumeRbrack()310}311// consumeRbrack consumes a right closing bracket. If a closing312// bracket token is not consumed an ErrBadSubstitution is returned.313func (t *Tree) consumeRbrack() error {314 t.scanner.mode = scanRbrack315 if t.scanner.scan() != tokenRbrack {316 return ErrBadSubstitution...
scanIdent
Using AI Code Generation
1import (2func main() {3 fset := token.NewFileSet()4 f, err := parser.ParseFile(fset, "2.go", nil, parser.ParseComments)5 if err != nil {6 fmt.Println(err)7 }8 for _, d := range f.Decls {9 switch d := d.(type) {10 fmt.Println(d.Name.Name)11 }12 }13}
scanIdent
Using AI Code Generation
1import (2func main() {3import "fmt"4func main() {5 fmt.Println("Hello, playground")6}`7 fset := token.NewFileSet()8 f, err := parser.ParseFile(fset, "", src, parser.ParseComments)9 if err != nil {10 fmt.Println(err)11 }12 ast.Inspect(f, func(n ast.Node) bool {13 switch x := n.(type) {14 fmt.Println(x.Name)15 }16 })17}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!