How to use resolve method of parser Package

Best Gauge code snippet using parser.resolve

semantic.go

Source:semantic.go Github

copy

Full Screen

...26 if ast.Name2Category != nil {27 return nil28 }29 ast.Name2Category = make(map[string]parser.Category)30 r := &resolver{ast: ast}31 return r.ResolveAST()32}33// typedefPair contains a type and the AST it belongs to. This struct is used34// to record types that resolved to a typedef instead of a concrete type so35// a post process is required to do further resolution.36type typedefPair struct {37 Type *parser.Type38 AST *parser.Thrift39 Name string40}41type resolver struct {42 ast *parser.Thrift43 typedefs []*typedefPair44}45// guard is used to simplify error-checking.46func guard(err error) (ok bool) {47 if err != nil {48 panic(err)49 }50 return true51}52func (r *resolver) AddName(name string, category parser.Category) error {53 if _, exist := r.ast.Name2Category[name]; exist {54 return fmt.Errorf("%s: multiple definition of %q", r.ast.Filename, name)55 }56 r.ast.Name2Category[name] = category57 return nil58}59// RegisterNames adds all locally defined names into Name2Category.60// It panics when encounters any error.61func (r *resolver) RegisterNames() {62 r.ast.ForEachTypedef(func(v *parser.Typedef) bool {63 return guard(r.AddName(v.Alias, parser.Category_Typedef))64 })65 r.ast.ForEachConstant(func(v *parser.Constant) bool {66 return guard(r.AddName(v.Name, parser.Category_Constant))67 })68 r.ast.ForEachEnum(func(v *parser.Enum) bool {69 return guard(r.AddName(v.Name, parser.Category_Enum))70 })71 r.ast.ForEachStructLike(func(v *parser.StructLike) bool {72 switch v.Category {73 case "struct":74 return guard(r.AddName(v.Name, parser.Category_Struct))75 case "union":76 return guard(r.AddName(v.Name, parser.Category_Union))77 case "exception":78 return guard(r.AddName(v.Name, parser.Category_Exception))79 }80 return false81 })82 r.ast.ForEachService(func(v *parser.Service) bool {83 return guard(r.AddName(v.Name, parser.Category_Service))84 })85}86// ResolveAST iterates the current AST and checks the legitimacy of each symbol.87func (r *resolver) ResolveAST() (err error) {88 defer func() {89 if x := recover(); x != nil {90 if e, ok := x.(error); ok {91 err = e92 } else {93 err = fmt.Errorf("%+v", x)94 }95 }96 }()97 r.ast.ForEachInclude(func(v *parser.Include) bool {98 if v.Reference == nil {99 panic(fmt.Errorf("reference %q of %q is not parsed", v.Path, r.ast.Filename))100 }101 if err = ResolveSymbols(v.Reference); err != nil {102 panic(fmt.Errorf("resolve include %q: %w", v.Path, err))103 }104 return true105 })106 // register all names defined in the current IDL to make type resolution107 // irrelevant with the order of definitions.108 r.RegisterNames()109 r.ast.ForEachTypedef(func(v *parser.Typedef) bool {110 return guard(r.ResolveType(v.Type))111 })112 r.ast.ForEachConstant(func(v *parser.Constant) bool {113 return guard(r.ResolveType(v.Type)) && guard(r.ResolveConstValue(v.Value))114 })115 r.ast.ForEachStructLike(func(v *parser.StructLike) bool {116 if v.Category == "union" {117 v.ForEachField(func(f *parser.Field) bool {118 f.Requiredness = parser.FieldType_Optional119 return true120 })121 }122 v.ForEachField(func(f *parser.Field) bool {123 return guard(r.ResolveStructField(v.Name, f))124 })125 return true126 })127 r.ast.ForEachService(func(v *parser.Service) bool {128 v.ForEachFunction(func(f *parser.Function) bool {129 guard(r.ResolveFunction(v.Name, f))130 return true131 })132 return guard(r.ResolveBaseService(v))133 })134 guard(r.ResolveTypedefs())135 return136}137func (r *resolver) ResolveBaseService(v *parser.Service) error {138 switch tmp := SplitType(v.Extends); len(tmp) {139 case 1:140 if c, exist := r.ast.Name2Category[tmp[0]]; exist && c == parser.Category_Service {141 break142 }143 return fmt.Errorf("base service %q not found for %q", v.Extends, v.Name)144 case 2:145 for idx, inc := range r.ast.Includes {146 if IDLPrefix(inc.Path) == tmp[0] {147 if c, exist := inc.Reference.Name2Category[tmp[1]]; exist && c == parser.Category_Service {148 v.Reference = &parser.Reference{149 Name: tmp[1],150 Index: int32(idx),151 }152 r.ast.Includes[idx].Used = &yes153 break154 }155 }156 }157 if v.Reference == nil {158 return fmt.Errorf("base service %q not found for %q", v.Extends, v.Name)159 }160 }161 return nil162}163func (r *resolver) ResolveStructField(s string, f *parser.Field) (err error) {164 if err = r.ResolveType(f.Type); err != nil {165 return fmt.Errorf("resolve field %q of %q: %w", f.Name, s, err)166 }167 if f.IsSetDefault() {168 if err = r.ResolveConstValue(f.Default); err != nil {169 return fmt.Errorf("resolve default value of %q of %q: %w", f.Name, s, err)170 }171 }172 return173}174func (r *resolver) ResolveFunction(s string, f *parser.Function) (err error) {175 if !f.Void {176 if err = r.ResolveType(f.FunctionType); err != nil {177 return fmt.Errorf("function %q of service %q: %w", f.Name, s, err)178 }179 }180 for _, v := range f.Arguments {181 if err := r.ResolveType(v.Type); err != nil {182 return fmt.Errorf("resolve argument %q of %q of %q: %w", v.Name, f.Name, s, err)183 }184 }185 for _, v := range f.Throws {186 if err := r.ResolveType(v.Type); err != nil {187 return fmt.Errorf("resolve exception %q of %q of %q: %w", v.Name, f.Name, s, err)188 }189 }190 return191}192var categoryMap = map[string]parser.Category{193 "bool": parser.Category_Bool,194 "byte": parser.Category_Byte,195 "i8": parser.Category_Byte,196 "i16": parser.Category_I16,197 "i32": parser.Category_I32,198 "i64": parser.Category_I64,199 "double": parser.Category_Double,200 "string": parser.Category_String,201 "binary": parser.Category_Binary,202 "map": parser.Category_Map,203 "list": parser.Category_List,204 "set": parser.Category_Set,205}206var yes bool = true207func (r *resolver) ResolveType(t *parser.Type) (err error) {208 switch t.Name {209 case "bool", "byte", "i8", "i16", "i32", "i64", "double", "string", "binary":210 t.Category = categoryMap[t.Name]211 case "map", "list", "set":212 t.Category = categoryMap[t.Name]213 if t.Name == "map" {214 if err = r.ResolveType(t.KeyType); err != nil {215 return216 }217 }218 return r.ResolveType(t.ValueType)219 default:220 tmp := SplitType(t.Name)221 switch len(tmp) {222 case 1: // typedef, enum, struct, union, exception223 if c, exist := r.ast.Name2Category[tmp[0]]; exist {224 if c >= parser.Category_Enum && c <= parser.Category_Typedef {225 if c == parser.Category_Typedef {226 r.typedefs = append(r.typedefs, &typedefPair{227 Type: t,228 AST: r.ast,229 Name: tmp[0],230 })231 t.IsTypedef = &yes232 }233 t.Category = c234 break235 }236 return fmt.Errorf("unexpected type category '%s' of type '%s'", c, t.Name)237 }238 return fmt.Errorf("undefined type: %q", t.Name)239 case 2: // an external type240 for i, inc := range r.ast.Includes {241 if IDLPrefix(inc.Path) != tmp[0] {242 continue243 }244 if c, exist := inc.Reference.Name2Category[tmp[1]]; exist {245 if c >= parser.Category_Enum && c <= parser.Category_Typedef {246 if c == parser.Category_Typedef {247 r.typedefs = append(r.typedefs, &typedefPair{248 Type: t,249 AST: inc.Reference,250 Name: tmp[1],251 })252 t.IsTypedef = &yes253 }254 t.Category = c255 t.Reference = &parser.Reference{256 Name: tmp[1],257 Index: int32(i),258 }259 r.ast.Includes[i].Used = &yes260 break261 }262 }263 }264 if t.Reference == nil {265 return fmt.Errorf("undefined type: %q", t.Name)266 }267 default:268 return fmt.Errorf("invalid type name %q", t.Name)269 }270 }271 return272}273// getEnum searches in the given AST and its includes an enum definition that matches the274// given name. If the name refers to a typedef, then its original type will be considered.275// The return value contains the target enum definition and the index of the **first**276// included IDL or -1 if the enum is defined in the given AST.277// When such an enum is not found, getEnum returns (nil, -1).278func getEnum(ast *parser.Thrift, name string) (enum *parser.Enum, includeIndex int32) {279 c, exist := ast.Name2Category[name]280 if !exist {281 return nil, -1282 }283 if c == parser.Category_Enum {284 x, ok := ast.GetEnum(name)285 if !ok {286 panic(fmt.Errorf("expect %q to be an enum in %q, not found", name, ast.Filename))287 }288 return x, -1289 }290 if c == parser.Category_Typedef {291 if x, ok := ast.GetTypedef(name); !ok {292 panic(fmt.Errorf("expect %q to be an typedef in %q, not found", name, ast.Filename))293 } else {294 if r := x.Type.Reference; r != nil {295 e, _ := getEnum(ast.Includes[r.Index].Reference, r.Name)296 if e != nil {297 return e, r.Index298 }299 }300 return getEnum(ast, x.Type.Name)301 }302 }303 return nil, -1304}305func (r *resolver) ResolveConstValue(t *parser.ConstValue) (err error) {306 switch t.Type {307 case parser.ConstType_ConstIdentifier:308 id := t.TypedValue.GetIdentifier()309 if id == "true" || id == "false" {310 return311 }312 sss := SplitValue(id)313 var ref []*parser.ConstValueExtra314 for _, ss := range sss {315 switch len(ss) {316 case 1: // constant317 if c, exist := r.ast.Name2Category[ss[0]]; exist {318 if c == parser.Category_Constant {319 ref = append(ref, &parser.ConstValueExtra{320 IsEnum: false, Index: -1, Name: ss[0],321 })322 }323 }324 continue325 case 2: // enum.value or someinclude.constant326 // TODO: if enum.value is written in typedef.value?327 // enum.value328 if enum, idx := getEnum(r.ast, ss[0]); enum != nil {329 for _, v := range enum.Values {330 if v.Name == ss[1] {331 ref = append(ref, &parser.ConstValueExtra{332 IsEnum: true, Index: idx, Name: ss[1], Sel: ss[0],333 })334 }335 }336 }337 for idx, inc := range r.ast.Includes {338 if IDLPrefix(inc.Path) != ss[0] {339 continue340 }341 if c, exist := inc.Reference.Name2Category[ss[1]]; exist {342 if c == parser.Category_Constant {343 ref = append(ref, &parser.ConstValueExtra{344 IsEnum: false, Index: int32(idx), Name: ss[1], Sel: ss[0],345 })346 r.ast.Includes[idx].Used = &yes347 }348 }349 }350 case 3: // someinclude.enum.value351 for idx, inc := range r.ast.Includes {352 if IDLPrefix(inc.Path) != ss[0] {353 continue354 }355 if enum, _ := getEnum(inc.Reference, ss[1]); enum != nil {356 for _, v := range enum.Values {357 if v.Name == ss[2] {358 ref = append(ref, &parser.ConstValueExtra{359 IsEnum: true, Index: int32(idx), Name: ss[2], Sel: ss[1],360 })361 r.ast.Includes[idx].Used = &yes362 }363 }364 }365 }366 }367 }368 switch len(ref) {369 case 0:370 return fmt.Errorf("undefined value: %q", t.TypedValue.GetIdentifier())371 case 1:372 t.Extra = ref[0]373 default:374 return fmt.Errorf("ambiguous const value %q (%d possible explainations)", t.TypedValue.GetIdentifier(), len(ref))375 }376 case parser.ConstType_ConstList:377 for _, v := range t.TypedValue.List {378 if err = r.ResolveConstValue(v); err != nil {379 return380 }381 }382 case parser.ConstType_ConstMap:383 for _, m := range t.TypedValue.Map {384 if err = r.ResolveConstValue(m.Key); err != nil {385 return386 }387 if err = r.ResolveConstValue(m.Value); err != nil {388 return389 }390 }391 default: // parser.ConstType_ConstDouble, parser.ConstType_ConstInt, parser.ConstType_ConstLiteral392 return393 }394 return395}396func (r *resolver) ResolveTypedefs() error {397 tds := r.typedefs398 cnt := len(tds)399 // a typedef may depend on another one, so we use an infinite400 // loop to process them and check if the unresolved tasks is401 // lessen by each iteration402 for len(tds) > 0 {403 var tmp []*typedefPair404 for _, t := range tds {405 if err := r.ResolveTypedef(t); err != nil {406 return err407 }408 if t.Type.Category == parser.Category_Typedef {409 // unchanged410 tmp = append(tmp, t)411 }412 }413 if len(tmp) == cnt {414 var ss []string415 for _, t := range tmp {416 ss = append(ss, fmt.Sprintf(417 "%q in %q", t.Type.Name, t.AST.Filename,418 ))419 }420 return fmt.Errorf("typedefs can not be resolved: %s", strings.Join(ss, ", "))421 }422 tds = tmp423 }424 return nil425}426func (r *resolver) ResolveTypedef(t *typedefPair) error {427 td, ok := t.AST.GetTypedef(t.Name)428 if !ok {429 return fmt.Errorf("expected %q in %q a typedef, not found", t.Name, t.AST.Filename)430 }431 if td.Type.Category != parser.Category_Typedef {432 t.Type.Category = td.Type.Category433 }434 return nil435}436// Deref returns the target type that t refers to and the AST it belongs to.437// Typedef will be dereferenced.438func Deref(ast *parser.Thrift, t *parser.Type) (*parser.Thrift, *parser.Type, error) {439 if !t.IsSetReference() && !t.GetIsTypedef() {440 return ast, t, nil441 }442 if !t.IsSetReference() { // is a typedef443 if td, ok := ast.GetTypedef(t.Name); ok {444 return Deref(ast, td.Type)445 }446 return nil, nil, fmt.Errorf("expect %q a typedef in %q", t.Name, ast.Filename)447 }448 // refer to an external type449 ref := t.GetReference()450 if ref.Index < 0 || ref.Index >= int32(len(ast.Includes)) {451 return nil, nil, fmt.Errorf("(%+v) invalid ref.Index for %q: %d", t, ast.Filename, ref.Index)452 }453 ast = ast.Includes[ref.Index].Reference454 if ast.Name2Category == nil {455 return nil, nil, fmt.Errorf("AST %q is not semantically resolved", ast.Filename)456 }457 cat := ast.Name2Category[ref.Name]458 switch {459 case cat == parser.Category_Typedef:460 if td, ok := ast.GetTypedef(ref.Name); ok {461 return Deref(ast, td.Type)462 }463 return nil, nil, fmt.Errorf("expect %q a typedef in %q", ref.Name, ast.Filename)464 case parser.Category_Enum <= cat && cat <= parser.Category_Exception:465 t = &parser.Type{466 Name: ref.Name,467 Category: cat,468 }469 return ast, t, nil...

Full Screen

Full Screen

resolver.go

Source:resolver.go Github

copy

Full Screen

1// Package resolver implements identifer resolution semantic analysis,2// as well as some syntax checks (e.g. ensuring that continues and breaks3// are within a loop construct). Identifier resolution works by recording4// the distance from the current environment where an identifier can be5// found.6package resolver7import (8 "errors"9 "fmt"10 "toe/lexer"11 "toe/parser"12)13var TooManyErrors = errors.New("too many errors")14type ResolverError struct {15 Filename string16 Token lexer.Token17 Message string18}19func (re ResolverError) Error() string { return re.String() }20func (re ResolverError) String() string {21 return fmt.Sprintf("%s:%d:%d: %s", re.Filename, re.Token.Line, re.Token.Column, re.Message)22}23type Scope map[string]bool24// Control flags -- whether we are in a loop, or a function.25const (26 LOOP = 1 << iota27 FUNC28)29type Resolver struct {30 module *parser.Module31 // each scope is a map from varname to a boolean, corresponding32 // to whether the variable was already initialised.33 scopes []Scope34 Errors []error35 ctrl uint836}37func New(module *parser.Module) *Resolver {38 r := &Resolver{39 module: module,40 scopes: []Scope{},41 Errors: []error{},42 ctrl: 0,43 }44 r.push() // the global scope.45 return r46}47func (r *Resolver) AddGlobals(globals []string) {48 for _, x := range globals {49 r.scopes[0][x] = true50 }51}52func (r *Resolver) curr() Scope { return r.scopes[len(r.scopes)-1] }53func (r *Resolver) push() { r.scopes = append(r.scopes, Scope{}) }54func (r *Resolver) pop() { r.scopes = r.scopes[:len(r.scopes)-1] }55func (r *Resolver) err(tok lexer.Token, msg string) {56 r.Errors = append(r.Errors, ResolverError{57 Filename: r.module.Filename,58 Token: tok,59 Message: msg,60 })61}62// Clean up frees memory used by the resolver -- this can only be done63// after reporting errors, as it clears the errors as well.64func (r *Resolver) Cleanup() {65 r.scopes = nil66 r.Errors = nil67}68// ResolveOne resolves the given node -- it is mainly for69// interactive usage.70func (r *Resolver) ResolveOne(node parser.Node) {71 r.resolve(node)72}73// Resolve resolves the given module.74// This method can only be called once.75func (r *Resolver) Resolve() {76 for _, stmt := range r.module.Stmts {77 r.resolve(stmt)78 if len(r.Errors) >= 10 {79 r.Errors = append(r.Errors, TooManyErrors)80 break81 }82 }83 if len(r.scopes) != 1 || r.ctrl != 0 {84 panic("something gone wrong!")85 }86}87func (r *Resolver) resolve(node parser.Node) {88 switch node := node.(type) {89 // Statements90 case *parser.Let:91 r.resolveLet(node)92 case *parser.Block:93 r.resolveBlock(node)94 case *parser.For:95 r.resolveFor(node)96 case *parser.While:97 r.resolveWhile(node)98 case *parser.If:99 r.resolveIf(node)100 case *parser.ExprStmt:101 r.resolveExprStmt(node)102 case *parser.Break:103 r.resolveBreak(node)104 case *parser.Continue:105 r.resolveContinue(node)106 case *parser.Return:107 r.resolveReturn(node)108 // Expressions109 case *parser.Binary:110 r.resolveBinary(node)111 case *parser.And:112 r.resolveAnd(node)113 case *parser.Or:114 r.resolveOr(node)115 case *parser.Assign:116 r.resolveAssign(node)117 case *parser.Unary:118 r.resolveUnary(node)119 case *parser.Get:120 r.resolveGet(node)121 case *parser.Set:122 r.resolveSet(node)123 case *parser.Method:124 r.resolveMethod(node)125 case *parser.Call:126 r.resolveCall(node)127 case *parser.Identifier:128 r.resolveIdentifier(node)129 case *parser.Literal:130 return131 case *parser.Array:132 r.resolveArray(node)133 case *parser.Hash:134 r.resolveHash(node)135 case *parser.Function:136 r.resolveFunction(node)137 case *parser.Super:138 r.resolveSuper(node)139 default:140 panic(fmt.Sprintf("unhandled node: %#+v", node))141 }142}143// ==========144// Statements145// ==========146func (r *Resolver) resolveLet(node *parser.Let) {147 name := node.Name.Lexeme148 curr := r.curr()149 if _, ok := curr[name]; ok {150 // is there already an existing let?151 r.err(node.Name, "already a variable with this name in scope.")152 }153 curr[name] = false154 r.resolve(node.Value)155 curr[name] = true156 addFunctionName(node.Value, name)157}158func (r *Resolver) resolveBlock(node *parser.Block) {159 r.push()160 for _, x := range node.Stmts {161 r.resolve(x)162 }163 r.pop()164}165func (r *Resolver) resolveFor(node *parser.For) {166 name := node.Name.Lexeme167 r.resolve(node.Iter)168 r.push()169 ctrl := r.ctrl170 r.ctrl |= LOOP171 r.curr()[name] = true172 r.resolve(node.Stmt)173 r.ctrl = ctrl174 r.pop()175}176func (r *Resolver) resolveWhile(node *parser.While) {177 r.resolve(node.Cond)178 ctrl := r.ctrl179 r.ctrl |= LOOP180 r.resolve(node.Stmt)181 r.ctrl = ctrl182}183func (r *Resolver) resolveIf(node *parser.If) {184 r.resolve(node.Cond)185 r.resolve(node.Then)186 if node.Else != nil {187 r.resolve(node.Else)188 }189}190func (r *Resolver) resolveExprStmt(node *parser.ExprStmt) {191 r.resolve(node.Expr)192}193func (r *Resolver) resolveBreak(node *parser.Break) {194 if r.ctrl&LOOP == 0 {195 r.err(node.Keyword, "break outside of loop")196 }197}198func (r *Resolver) resolveContinue(node *parser.Continue) {199 if r.ctrl&LOOP == 0 {200 r.err(node.Keyword, "continue outside of loop")201 }202}203func (r *Resolver) resolveReturn(node *parser.Return) {204 if r.ctrl&FUNC == 0 {205 r.err(node.Keyword, "return outside of function")206 }207 if node.Expr != nil {208 r.resolve(node.Expr)209 }210}211// ===========212// Expressions213// ===========214func (r *Resolver) resolveBinary(node *parser.Binary) {215 r.resolve(node.Left)216 r.resolve(node.Right)217}218func (r *Resolver) resolveAnd(node *parser.And) {219 r.resolve(node.Left)220 r.resolve(node.Right)221}222func (r *Resolver) resolveOr(node *parser.Or) {223 r.resolve(node.Left)224 r.resolve(node.Right)225}226func (r *Resolver) resolveAssign(node *parser.Assign) {227 r.resolve(node.Right)228 addFunctionName(node.Right, node.Name.Lexeme)229 r.lookup(node, node.Name)230}231func (r *Resolver) resolveUnary(node *parser.Unary) {232 r.resolve(node.Right)233}234func (r *Resolver) resolveGet(node *parser.Get) {235 r.resolve(node.Object)236}237func (r *Resolver) resolveSet(node *parser.Set) {238 r.resolve(node.Right)239 addFunctionName(node.Right, node.Name.Lexeme)240 r.resolve(node.Object)241}242func (r *Resolver) resolveMethod(node *parser.Method) {243 r.resolve(node.Object)244 for _, arg := range node.Args {245 r.resolve(arg)246 }247}248func (r *Resolver) resolveCall(node *parser.Call) {249 r.resolve(node.Callee)250 for _, arg := range node.Args {251 r.resolve(arg)252 }253}254func (r *Resolver) resolveIdentifier(node *parser.Identifier) {255 r.lookup(node, node.Id)256}257func (r *Resolver) resolveArray(node *parser.Array) {258 for _, expr := range node.Exprs {259 r.resolve(expr)260 }261}262func (r *Resolver) resolveHash(node *parser.Hash) {263 for _, pair := range node.Pairs {264 r.resolve(pair.Key)265 r.resolve(pair.Value)266 }267}268func (r *Resolver) resolveFunction(node *parser.Function) {269 // Function expressions -- we first push a new scope containing all270 // of the parameters, and then we resolve the body.271 ctrl := r.ctrl272 r.ctrl |= FUNC273 r.push()274 scope := r.curr()275 scope["this"] = true276 for _, name := range node.Params {277 scope[name.Lexeme] = true278 }279 r.resolveBlock(node.Body)280 r.pop()281 r.ctrl = ctrl282}283func (r *Resolver) resolveSuper(node *parser.Super) {284 if r.ctrl&FUNC == 0 {285 r.err(node.Tok, "super outside of function")286 }287}288func (r *Resolver) lookup(node parser.Expr, token lexer.Token) {289 name := token.Lexeme290 curr := len(r.scopes) - 1291 // loop until we find a closest scope containing the name.292 for i := curr; i >= 0; i-- {293 initialised, ok := r.scopes[i][name]294 if ok {295 // if we're referring to an uninitialised variable, e.g.296 // let a = a, then we can return an error -- unless:297 // 1. we're in a function AND...

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fset := token.NewFileSet()4 f, err := parser.ParseFile(fset, "1.go", nil, parser.ParseComments)5 if err != nil {6 fmt.Println(err)7 }8 fmt.Println("f.Name:", f.Name)9 fmt.Println("f.Decls:", f.Decls)10 fmt.Println("f.Scope:", f.Scope)11 fmt.Println("f.Unresolved:", f.Unresolved)12 fmt.Println("f.Comments:", f.Comments)13 fmt.Println("f.Imports:", f.Imports)14 fmt.Println("f.Name:", f.Name)15 fmt.Println("f.Name:", f.Name)16 fmt.Println("f.Name:", f.Name)17 fmt.Println("f.Name:", f.Name)18 fmt.Println("f.Name:", f.Name)19 fmt.Println("f.Name:", f.Name)

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fset := token.NewFileSet()4 f, err := parser.ParseFile(fset, "1.go", nil, parser.ImportsOnly)5 if err != nil {6 fmt.Println(err)7 }8 for _, s := range f.Imports {9 fmt.Println(s.Path.Value)10 }11}

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1package com.example.parser;2import java.io.IOException;3import java.nio.file.Path;4import java.nio.file.Paths;5public class ResolveMethod {6 public static void main(String[] args) throws IOException {7 Path path1 = Paths.get("/Users/surajkumar/Desktop/1.txt");8 Path path2 = Paths.get("/Users/surajkumar/Desktop/2.txt");9 Path path3 = Paths.get("/Users/surajkumar/Desktop/3.txt");10 Path path4 = Paths.get("/Users/surajkumar/Desktop/4.txt");11 Path path5 = Paths.get("/Users/surajkumar/Desktop/5.txt");12 System.out.println("path1: " + path1);13 System.out.println("path2: " + path2);14 System.out.println("path3: " + path3);15 System.out.println("path4: " + path4);16 System.out.println("path5: " + path5);17 System.out.println("path1.resolve(path2): " + path1.resolve(path2));18 System.out.println("path1.resolve(path3): " + path1.resolve(path3));19 System.out.println("path1.resolve(path4): " + path1.resolve(path4));20 System.out.println("path1.resolve(path5): " + path1.resolve(path5));21 }22}

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 parser := parser.Parser{}4 result := parser.Resolve("1+2*3")5 fmt.Println(result)6}

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(filepath.Abs("1.go"))4}5import (6func main() {7 fmt.Println(filepath.Abs("C:\\Users\\HP\\Desktop\\Golang\\1.go"))8}9import (10func main() {11 fmt.Println(filepath.Abs("C:/Users/HP/Desktop/Golang/1.go"))12}13import (14func main() {15 fmt.Println(filepath.Abs("C:\\Users\\HP\\Desktop\\Golang\\"))16}17import (18func main() {19 fmt.Println(filepath.Abs("C:/Users/HP/Desktop/Golang/"))20}21import (22func main() {23 fmt.Println(filepath.Abs("C:\\Users\\HP\\Desktop\\G

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful