World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
BrianH 1-Jul-2006 [1240x5] | Graham, yes I did. I know parse well enough to run it in my head. |
expand-macros: func [data [string!] macros [block!] /local whitespace macro-rule macro expansion here there ] compose [ whitespace: (charset " ^/") macro-rule: make block! 2.5 * length? macros foreach [macro expansion] macros [ macro-rule: insert macro-rule compose [here: (macro) there: [whitespace | end] '|] ] macro-rule: head remove back macro-rule parse/all data [some [ macro-rule ( macro: copy/part here there there: change/part here select/skip macros macro 2 there ) :there | skip ]] macro-rule: none data ] | |
Whoops, small fix... | |
expand-macros: func [data [string!] macros [block!] /local whitespace macro-rule macro expansion here there ] compose [ whitespace: (charset " ^/") macro-rule: make block! 2.5 * length? macros foreach [macro expansion] macros [ macro-rule: insert macro-rule compose [here: (macro) there: [whitespace | end] |] ] macro-rule: head remove back macro-rule parse/all data [some [ macro-rule ( macro: copy/part here there there: change/part here select/skip macros macro 2 there ) :there | skip ]] macro-rule: none data ] | |
Wait, there is another error. | |
Tomc 1-Jul-2006 [1245] | I am glad to see someone else using here and there ;) |
BrianH 1-Jul-2006 [1246x2] | expand-macros: func [data [string!] macros [block!] /local whitespace macro-rule macro expansion here there ] compose [ whitespace: (charset " ^/") macro-rule: make block! 2.5 * length? macros foreach [macro expansion] macros [ macro-rule: insert macro-rule compose [here: (macro) there: [whitespace | end] |] ] macro-rule: head remove back macro-rule parse/all data [some [ macro-rule ( macro: copy/part here there there: change/part here select/skip macros macro 2 there ) :there | thru whitespace ] to end] macro-rule: none data ] |
That should do it. | |
Graham 1-Jul-2006 [1248] | I don't feel so bad that my rule wasn't working ! |
BrianH 1-Jul-2006 [1249x2] | ; Now whitespace is dealt with expand-macros: func [data [string!] macros [block!] /local whitespace macro-rule macro expansion here there ] compose [ whitespace: (charset " ^/") macro-rule: make block! 2.5 * length? macros foreach [macro expansion] macros [ macro-rule: insert macro-rule compose [here: (macro) there: [whitespace | end] |] ] macro-rule: head remove back macro-rule parse/all data [some [any whitespace [ macro-rule ( macro: copy/part here there there: change/part here select/skip macros macro 2 there ) :there | to whitespace ]] to end] macro-rule: none data ] |
You might want to add tabs to the whitespace charset. | |
Graham 1-Jul-2006 [1251x2] | why do you need to reset macro-rule to none? |
it's a local so memory will be released anyway .. | |
BrianH 1-Jul-2006 [1253] | You don't need to, but if you don't it will sit in memory until the next time you run the function. |
Graham 1-Jul-2006 [1254] | Oh ... ok. |
BrianH 1-Jul-2006 [1255] | Memory for locals is not released. |
Graham 1-Jul-2006 [1256] | when the function is exited ? |
BrianH 1-Jul-2006 [1257] | Nope. |
Graham 1-Jul-2006 [1258] | Hmm. |
BrianH 1-Jul-2006 [1259] | Only on recursed functions. |
Graham 1-Jul-2006 [1260] | I guess it can't be otherwise we wouldn't need to use 'copy on series |
BrianH 1-Jul-2006 [1261] | It's a speed optimization. This might change with REBOL 3. |
Graham 1-Jul-2006 [1262] | memory use is a large with Rebol. |
BrianH 1-Jul-2006 [1263] | The series copy thing is something different. |
Graham 1-Jul-2006 [1264] | speed or memory .. |
BrianH 1-Jul-2006 [1265x2] | Most of the excessive memory overhead of REBOL is just sloppy (no offense Carl). It's not much of a problem for most, but I have run into memory limits when running on embedded or handheld platforms, or running hundreds of instances on servers. |
You have to design your platform for memory efficiency or it won't be. | |
Graham 1-Jul-2006 [1267] | Little problem :( ** Script Error: Invalid argument: make bitset! #{ 0004000001000000000000000000000000000000000000000000000000000000 } ** Where: expand-macros ** Near: parse/all data [some [any whitespace [ macro-rule ( macro: copy/part here there ... |
Tomc 1-Jul-2006 [1268x3] | whi the parens on whitespace: rule? |
nevermind it is in compose | |
but that can just be a static rule outside of compose | |
BrianH 1-Jul-2006 [1271] | More efficiency. I build my charsets once, rather than on every call. |
Graham 1-Jul-2006 [1272] | should probably build the rule outside the function as well since it only should be rebuilt when the macro list changes |
Tomc 1-Jul-2006 [1273x3] | cant say to whitespace |
wish you could | |
tipicaly get around with | |
Graham 1-Jul-2006 [1276] | that's where my rule got stuck .. on to whitespace |
Tomc 1-Jul-2006 [1277x2] | bs: complement ws |
any bs | |
BrianH 1-Jul-2006 [1279x3] | Yeah, I'm changing my code now. |
expand-macros: func [data [string!] macros [block!] /local ws non-ws macro-rule macro expansion here there ] compose [ ws: (charset " ^/") non-ws: (complement charset " ^/") macro-rule: make block! 2.5 * length? macros foreach [macro expansion] macros [ macro-rule: insert macro-rule compose [here: (macro) there: [ws | end] |] ] macro-rule: head remove back macro-rule parse/all data [some [any ws [ macro-rule ( macro: copy/part here there there: change/part here select/skip macros macro 2 there ) :there | some non-ws ]] to end] macro-rule: none data ] | |
See, I don't have to test. Graham has the data, he can test :) | |
Tomc 1-Jul-2006 [1282] | that is the part I can't allways be bothered with either |
Graham 1-Jul-2006 [1283] | LOL ... |
BrianH 1-Jul-2006 [1284x2] | When it's my data, I test it myself. After the major logc bugs are worked out in my head of course... |
REBOL catches spelling errors (logc -> logic). | |
Graham 1-Jul-2006 [1286x2] | Have you guys made any submissions to RT for parse improvements for R3? |
Any further submissions ie. | |
Tomc 1-Jul-2006 [1288] | RT can just use the pending suggeations from before R3 |
BrianH 1-Jul-2006 [1289] | Gabriele and I have worked extensively on such submissions. |
older newer | first last |