I started to write a sscanf %O, which I believe we have discussed previously, to match sprintf %O (and generic Pike constants).
So far, it understands integers, strings and character constants:
array_sscanf("17 "hepp" 'x' gurka","%O%O%O%s");
(3) Result: ({ /* 4 elements */ 17, "hepp", 120, " gurka" })
But sprintf won't produce 'x', so you are not aiming (exactly) for a reversed sprintf("%O"). I think you should.
/ Martin Nilsson (Åskblod)
Previous text:
2003-02-11 14:54: Subject: sscanf %O
I started to write a sscanf %O, which I believe we have discussed previously, to match sprintf %O (and generic Pike constants).
So far, it understands integers, strings and character constants:
array_sscanf("17 "hepp" 'x' gurka","%O%O%O%s");
(3) Result: ({ /* 4 elements */ 17, "hepp", 120, " gurka" })
/ Mirar
I actually aim for something that understands all non-expression constants that you can use in the Pike language, as well as the output of sprintf %O on constants that aren't objects, functions or programs.
The first almost gives the second. I believe it's only the possibility of recursive datatypes in the latter that has to expand the functionality.
/ Mirar
Previous text:
2003-02-11 14:57: Subject: sscanf %O
But sprintf won't produce 'x', so you are not aiming (exactly) for a reversed sprintf("%O"). I think you should.
/ Martin Nilsson (Åskblod)
Like this?
private object compile_handler = class { mapping(string:mixed) get_default_module() { return ([ "this_program":0, "aggregate":aggregate, "aggregate_mapping":aggregate_mapping, "aggregate_multiset":aggregate_multiset ]); }
mixed resolv(string id, void|string fn, void|string ch) { error( "The symbol %O is forbidden.\n", id ); } }();
mixed eval(string what) { what -= "lambda"; what -= "class"; return compile_string( "mixed foo=" + what + ";", 0, compile_handler )()->foo; }
/ Martin Nilsson (Åskblod)
Previous text:
2003-02-11 15:03: Subject: sscanf %O
I actually aim for something that understands all non-expression constants that you can use in the Pike language, as well as the output of sprintf %O on constants that aren't objects, functions or programs.
The first almost gives the second. I believe it's only the possibility of recursive datatypes in the latter that has to expand the functionality.
/ Mirar
Det där torde väl göra fel på till exempel indatat
({ "class", "lambda" })
/ Niels Möller ()
Previous text:
2003-02-11 15:11: Subject: sscanf %O
Like this?
private object compile_handler = class { mapping(string:mixed) get_default_module() { return ([ "this_program":0, "aggregate":aggregate, "aggregate_mapping":aggregate_mapping, "aggregate_multiset":aggregate_multiset ]); }
mixed resolv(string id, void|string fn, void|string ch) { error( "The symbol %O is forbidden.\n", id ); } }();
mixed eval(string what) { what -= "lambda"; what -= "class"; return compile_string( "mixed foo=" + what + ";", 0, compile_handler )()->foo; }
/ Martin Nilsson (Åskblod)
Yes, the whole approach reminds me of the Roxen eval tag, which removed the letter "s" from the input code so that it would not be possible to call the system() function... :-)
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
Previous text:
2003-02-11 15:14: Subject: sscanf %O
Det där torde väl göra fel på till exempel indatat
({ "class", "lambda" })
/ Niels Möller ()
It _is_ the code for the eval tag, with minor modifications.
/ Martin Nilsson (Åskblod)
Previous text:
2003-02-11 15:16: Subject: sscanf %O
Yes, the whole approach reminds me of the Roxen eval tag, which removed the letter "s" from the input code so that it would not be possible to call the system() function... :-)
/ Marcus Comstedt (ACROSS) (Hail Ilpalazzo!)
To prevent that user defined code is executed when the data structure is read. Not that it would be able to do much... I wan't an assurance that sscanf %O (or at least one of its modes) only returns 1=int|float|string|array(@1)|mapping(@1:@1)|multiset(@1)
/ Martin Nilsson (Åskblod)
Previous text:
2003-02-11 15:32: Subject: sscanf %O
Why try to disallow class and lambda for the eval tag?
/ Niels Möller ()
I understand that, what I asked was if and why you also do that in the eval-tag.
/ Niels Möller ()
Previous text:
2003-02-11 15:38: Subject: sscanf %O
To prevent that user defined code is executed when the data structure is read. Not that it would be able to do much... I wan't an assurance that sscanf %O (or at least one of its modes) only returns 1=int|float|string|array(@1)|mapping(@1:@1)|multiset(@1)
/ Martin Nilsson (Åskblod)
The code is used in parsing the expr attribute to if and set. It is only supposed to handle mathematical expressions. Obviously we don't want user defined code to be executed there either.
/ Martin Nilsson (Åskblod)
Previous text:
2003-02-11 15:40: Subject: sscanf %O
I understand that, what I asked was if and why you also do that in the eval-tag.
/ Niels Möller ()
It must also be possible to continue to parse after the constant, see the value " gurka" in my example.
Also, you don't support recursive data, do you? Ie, ({@0}).
/ Mirar
Previous text:
2003-02-11 15:11: Subject: sscanf %O
Like this?
private object compile_handler = class { mapping(string:mixed) get_default_module() { return ([ "this_program":0, "aggregate":aggregate, "aggregate_mapping":aggregate_mapping, "aggregate_multiset":aggregate_multiset ]); }
mixed resolv(string id, void|string fn, void|string ch) { error( "The symbol %O is forbidden.\n", id ); } }();
mixed eval(string what) { what -= "lambda"; what -= "class"; return compile_string( "mixed foo=" + what + ";", 0, compile_handler )()->foo; }
/ Martin Nilsson (Åskblod)
pike-devel@lists.lysator.liu.se