Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow "simple names" to start with an integer #3

Open
Parzival-3141 opened this issue Jan 17, 2024 · 0 comments · May be fixed by #4
Open

Allow "simple names" to start with an integer #3

Parzival-3141 opened this issue Jan 17, 2024 · 0 comments · May be fixed by #4

Comments

@Parzival-3141
Copy link

Parzival-3141 commented Jan 17, 2024

This would enable expansions for shell script positional arguments, e.g.

> cat print.sh
echo $1

> print.sh foo
foo # $1 expanded to foo

It would directly solve our use case in Wanix where we use go-posix for shell preprocessing.

mapping := posix.Map{}
for i, scriptArg := range os.Args {
    mapping[strconv.Itoa(i)] = scriptArg
}
posix.Expand(shellScript, mapping)

Here's a possible implementation:

func lexStartExpansion(l *lexer) stateFn {
	c := l.next()
	switch {
	case c == eof:
		l.emit(itemText("$"))
		return nil
	case c == '{':
		l.ignore()
		l.depth++
		return lexBracketName
-	case isAlpha(c):
+	case isAlphaNum(c):
		return lexSimpleName
	}
	return nil // FIXME
}
@Parzival-3141 Parzival-3141 changed the title Allow "simple names to start with an integer Allow "simple names" to start with an integer Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant