World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
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. |
Graham 1-Jul-2006 [1290x4] | Ok, Brian, this one seems to work :) |
Hmm. Another problem. If the macro expansion contains newline characters ie. "^/", the returned text has "^/" in it | |
ros {ROS: ^/Gen: wt. stable,no fever,chills or night sweats^/CVS: neg cp, sob, pnd, orthopnea or dyspnea on exertion^/GI: neg constipation, bright red blood per rectum, or melena | |
I guess I need to form it before I add them to the macros block. | |
BrianH 1-Jul-2006 [1294] | Trim it. |
Graham 1-Jul-2006 [1295] | the above macro is supposed to expand into a multiline statement. |
BrianH 1-Jul-2006 [1296] | Then it is a good thing that the ^/ is in the expansion. |
Graham 1-Jul-2006 [1297] | No, as it ends up on screen showing ^/ instead of a visual newline. |
BrianH 1-Jul-2006 [1298] | Are they writing ^/ in the expansion text source data to indicate a newline? |
Graham 1-Jul-2006 [1299x2] | Yes. So, somehow I need to force the area field to recognise them as newlines and reformat the screen. |
They're using ^/ as the macros are being read in from a text file using read/lines | |
BrianH 1-Jul-2006 [1301] | When you read the macro data, do this to the expansions: replace/all expansion "^^/" "^/" |
Graham 1-Jul-2006 [1302] | so, read/lines is escaping the ^/ ? |
BrianH 1-Jul-2006 [1303] | No, it isn't. You have to yourself. Can you save the macro data in REBOL data format? |
Graham 1-Jul-2006 [1304x3] | I guess so, but I want to make it easy for the users ... |
but that works now :) | |
Thanks for the help guys | |
Henrik 9-Jul-2006 [1307x3] | how "local" are variables that are set during a parse? I was looking at Geomol's postscript.r and looked at: coords: [err: (pos: none) [set pos pair! | set x number! set y number!] ( either pos [ append output compose [(pos/x) " " (pos/y) " lineto^/"] ][ append output compose [(x) " " (y) " lineto^/"] ] ) ] |
but I can't get 'pos set in my own code in the () block after the parse block where 'pos is set. | |
that means it does get set inside the parse block, but it's set to none after the parse block again. | |
Anton 9-Jul-2006 [1310] | Is your code in the second parens actually ever executing ? |
Henrik 9-Jul-2006 [1311] | yes, I try to print the variable and it just returns none. |
Anton 9-Jul-2006 [1312] | Mmm let me make a few tests. |
Henrik 9-Jul-2006 [1313] | actually, there is a difference between my code and this, which may be causing it: I need to loop the block with 'any. I suspect the contents is lost after the first run. |
Oldes 9-Jul-2006 [1314] | because you set it to none in the first parens |
Anton 9-Jul-2006 [1315] | Yes the rule can only fail after the first parens. |
Henrik 9-Jul-2006 [1316] | oldes: it makes no difference whether the first parens is left out or not |
Anton 9-Jul-2006 [1317] | And to answer your question, the variables are just regular rebol words, so they are as local as you make them. |
Oldes 9-Jul-2006 [1318x2] | and how looks the code you parse? |
if the parse is inside function and you set pos in the function as a local - it will be local | |
Henrik 9-Jul-2006 [1320x2] | I'm parsing: [image "String" image-word [action block]] |
where 'image is always first and the remaining items may come in random order | |
Oldes 9-Jul-2006 [1322] | there is no pair and no numbers - the pos must be none |
Henrik 9-Jul-2006 [1323] | oldes, my code is different from his. I used his as it's structurally similar to mine |
Oldes 9-Jul-2006 [1324] | and what exactly do you want? |
Henrik 9-Jul-2006 [1325] | I want to assign a variable to each element so I can process them later |
older newer | first last |