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

Change interpolation syntax #28

Open
kynikos opened this issue Aug 9, 2015 · 2 comments
Open

Change interpolation syntax #28

kynikos opened this issue Aug 9, 2015 · 2 comments

Comments

@kynikos
Copy link
Owner

kynikos commented Aug 9, 2015

The current interpolation syntax is very flexible but probably unnecessarily complicated: the characters allowed in section and option names are already very limited by default, so only the interpolation start character could be introduced by a special character. Also, the configured section separator could be used to separate the sections in the path and the option name too. For example:

${section1.section2.option}
${.section1.section2.option}

In this case a leading . should mean a relative path.

${section1/section2/option}
${/section1/section2/option}

In this case a leading / should mean an absolute path.

Note that this change would create a backward incompatibility!

Edit: if using something like:

${section1.section2:option}
${section1/section2:option}

The option name shouldn't need to forbid the section separator, although section names should also forbid the :.

@lahwaacz
Copy link
Contributor

lahwaacz commented Aug 9, 2015

I always thought it was funny that options in a Section object are accessed using the square brackets syntax, but sections in a ConfigFile objects are accessed using round brackets, even though they are denoted as [name] in the config file itself. And on top of that interpolation introduces braces...

To avoid the : problem in the last example, the specification could be something like

$[section1.section2]${option}

where the ${} group is optionally preceded by the $[] group. The type of the brackets could be adjusted with regard to the note above.

@kynikos
Copy link
Owner Author

kynikos commented Aug 9, 2015

Sections must be accessed with round brackets because that's Python's (and not only its) syntax for function calls. In config files, though, it's more standard to use square brackets, but you can monkey-patch the setting with the latest commits in the develop branch, and #5 will give a cleaner way to do it.
About your alternative, it's of course another valid idea, maybe I'll end up making interpolation an integer value allowing to choose between various styles ;)

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

No branches or pull requests

2 participants