func()

in wstl1/mapping_language/transpiler/path.go [55:97]


func (t *transpiler) VisitTargetPathHead(ctx *parser.TargetPathHeadContext) interface{} {
	if ctx.TOKEN() != nil && ctx.TOKEN().GetText() != "" {
		return pathSpec{
			arg: getTokenText(ctx.TOKEN()),
		}
	}

	// ROOT_INPUT is a special case path segment since normally they cannot contain $.
	if ctx.ROOT_INPUT() != nil && ctx.ROOT_INPUT().GetText() != "" {
		return pathSpec{
			arg: ctx.ROOT_INPUT().GetText(),
		}
	}

	// ROOT is a special case path segment since it is a keyword and does not get tokenized as a TOKEN
	// TODO(): Remove after sunset.
	if ctx.ROOT() != nil && ctx.ROOT().GetText() != "" {
		return pathSpec{
			arg: ctx.ROOT().GetText(),
		}
	}

	if ctx.Index() != nil && ctx.Index().GetText() != "" {
		return pathSpec{
			index: ctx.Index().GetText(),
		}
	}

	if ctx.WILDCARD() != nil && ctx.WILDCARD().GetText() != "" {
		return pathSpec{
			index: ctx.WILDCARD().GetText(),
		}
	}

	if ctx.ArrayMod() != nil && ctx.ArrayMod().GetText() != "" {
		return pathSpec{
			index: ctx.ArrayMod().GetText(),
		}
	}

	t.fail(ctx, fmt.Errorf("invalid target path head - no token, index, arraymod, or wildcard"))
	return nil
}