Written in 10 minutes:
```js
var object = {
name: 'bu++',
cflags: '-stdlib=libc++',
deps: [ 'lib$name' ],
rule: [
{
name: 'cxx',
command: 'gcc $cflags -c <in> -o <out>',
}
]
}
function expand_variables(object, value) {
if (typeof(value) === 'string') {
return value.replace(/\$\w+/g, function(key) {
return object[key.replace(/^\$/, '')]
})
} else if (typeof(value) === 'object') {
for (var i in value) {
value[i] = expand_variables(object, value[i])
}
return value
} else {
return value
}
}
for (var i=0; i<1000; i++) object = expand_variables(object, object)
console.log(object)
name: 'bu++',
cflags: '-stdlib=libc++',
deps: [ 'lib$name' ],
rule: [
{
name: 'cxx',
command: 'gcc $cflags -c <in> -o <out>',
}
]
}
function expand_variables(object, value) {
if (typeof(value) === 'string') {
return value.replace(/\$\w+/g, function(key) {
return object[key.replace(/^\$/, '')]
})
} else if (typeof(value) === 'object') {
for (var i in value) {
value[i] = expand_variables(object, value[i])
}
return value
} else {
return value
}
}
for (var i=0; i<1000; i++) object = expand_variables(object, object)
console.log(object)
```
04.02.2014, 04:58, "Kevin Ingwersen" <[email protected]>:
I have not sen any post-processing in nodejs - or cpp - yet. o.o--Can you point one out, maybe?Am Di. Feb. 04 2014 01:54:42 schrieb Alex Kocharin:You can do that with any configuration parser and some post-processing...04.02.2014, 04:43, "Kevin Ingwersen" <[email protected]>:I am still waiting for one special kind of configuration file parser…but nobody did it yet, and I am not good enough with parsing myself, yet XD. But for anybody interested - consider the following:mame = bu++cflags = -stdlib=libc++deps: [ lib{$name} ]rule: [{name: cxx,command: gcc $cflags -c <in> -o <out>}]Should result into a js object like:{ deps: [ libbu++ ],rule: [ { name: cxx,command: gcc -stdlib=libc++ -c <in> -o <out>}]}The important part being the $ syntax. The name and cflags parts arent even parsed as part of the resulting object…its like, templating. I am trying to archieve this for a buidl tool that I am working on. I wanted to use YAML - but it’s „variable“ syntax is weird as -…. yknow. And I havent found any C/C++ library to do exactly that kind of thing.So yeah, if anybody knows a native library - or would write that kidn of parser, i woudl be hapyp to see that :)Kind regards, IngwieAm Mo. Feb. 03 2014 22:24:52 schrieb Alex Kocharin:04.02.2014, 01:22, "Gary Katsevman" <[email protected]>:On Mon, Feb 3, 2014 at 4:18 PM, Alex Kocharin <[email protected]> wrote:PS: why not simply use "require('js-yaml').safeLoad(require('fs').readFileSync('config', 'utf8'))" anyway ?Or for really simple things, just `require('packge.json')` or `require('./config.json')`;In this case you should make that require('./config.js') and write "module.exports = {...}" in there.As I said multiple times here, using JSON for a configuration file is a terrible idea.----
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.----
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
