r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Parse] Discussion of PARSE dialect

Graham
1-Jul-2006
[1203x2]
there is no whitespace inside a macroname
LOINC, another controlled vocab, contains over 30,000 items.
Tomc
1-Jul-2006
[1205]
so there is a seperate extendable file with the macro=expansion
Graham
1-Jul-2006
[1206x2]
tom, yes.
actually  the file will be saved in a database and loaded when the 
program starts
BrianH
1-Jul-2006
[1208]
Make sure to trim the names before you use them. I am rewriting your 
function.
Graham
1-Jul-2006
[1209]
Tom, what exactly are you involved in ?
Tomc
1-Jul-2006
[1210x2]
zebrafish
as a model orginism
Graham
1-Jul-2006
[1212]
fish!
Tomc
1-Jul-2006
[1213]
http://zfin.org
Graham
1-Jul-2006
[1214x5]
Ok, I understand the need for an ontology here.
but medicine is full of uncontrolled words which are in common use.
and the ontologically controlled programs are very expensive due 
to licensing fees
The AMA charge to use their codes, the American College of Pathologists 
charge to use their SMOMED-CT codes .. and so it goes on.
LOINC, from the Univ. of Indiana has open sourced their codes.
Tomc
1-Jul-2006
[1219x4]
ahh  my mind is corrupted by giving everything away I forget that 
that is not what everyone does
so back to your problem  I
seems it will take n passes
where n is the # of macros.
BrianH
1-Jul-2006
[1223x3]
expand-macros: func [data [string!] macros [block!]
	/local whitespace macro-rule macro here there
] compose [
	whitespace: (charset " ^/")
    macro-rule: make block! length? macros
	foreach [macro expansion] macros [
        macro-rule: insert insert macro-rule macro '|
    ]
    macro-rule: head remove back macro-rule
    parse/all data [some [
        here: copy macro macro-rule there: [whitespace | end] (

            there: change/part here select/skip macros macro 2 there
        ) :there |
        skip
    ]]
    macro-rule: none
    data
]
Sorry, need to change the settings in my editor.
expand-macros: func [data [string!] macros [block!]
    /local whitespace macro-rule macro here there
] compose [
    whitespace: (charset " ^/")
    macro-rule: make block! length? macros
    foreach [macro expansion] macros [
        macro-rule: insert insert macro-rule macro '|
    ]
    macro-rule: head remove back macro-rule
    parse/all data [some [
        here: copy macro macro-rule there: [whitespace | end] (

            there: change/part here select/skip macros macro 2 there
        ) :there |
        skip
    ]]
    macro-rule: none
    data
]
Graham
1-Jul-2006
[1226]
my first effort makes n passes ...
Tomc
1-Jul-2006
[1227]
that the macro-expansoion fioe needs to self check for incidental 
occurances of  a "macro" in an "expansion" and protect against
BrianH
1-Jul-2006
[1228x2]
This will make one pass.
And it won't have the problem you mention Tomc.
Tomc
1-Jul-2006
[1230]
in one pass you can jump over the expansion
BrianH
1-Jul-2006
[1231]
My code does that.
Graham
1-Jul-2006
[1232x2]
Pretty neat ...
Parse is somewhat beyond my skills!
Tomc
1-Jul-2006
[1234]
I wouls still sort the macros by longest to shortest so cant glob 
on to part of  a macro  ..
Graham
1-Jul-2006
[1235]
so, basically you created a single parse rule from the macro list 
and then parsed the text in one go.
Tomc
1-Jul-2006
[1236]
but if you include the trailing white space that should be avoided
BrianH
1-Jul-2006
[1237]
Tomc, that is a good point - I'll fix it. Graham, that's right.
Graham
1-Jul-2006
[1238x2]
Did you compose that without any testing? :)
We need a masterclass in parse ....
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 ..