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

World: r3wp

[Parse] Discussion of PARSE dialect

Graham
4-Nov-2005
[683x3]
>> caret: charset [ #"^^" ]
== make bitset! #{
0000000000000000000000400000000000000000000000000000000000000000
}
>> obx: {OBX|1|ST|Hb^ Hb:^L||135|g/L|120 - 155|N|||F^/}
== "OBX|1|ST|Hb Hb:^L||135|g/L|120 - 155|N|||F^/"
>> parse obx [ "OBX" "|" digits "|" "ST" "|" thru caret to end ]
** Script Error: Invalid argument: make bitset! #{
0000000000000000000000400000000000000000000000000000000000000000
}
** Where: halt-view

** Near: parse obx ["OBX" "|" digits "|" "ST" "|" thru caret to end]
>>
BrianH
4-Nov-2005
[686]
Is that with the caret as an escape char, or as a value?
Volker
4-Nov-2005
[687x2]
that is thru with a charset. any caret
no, grrr, lack of smarter thru is annoying.
BrianH
4-Nov-2005
[689]
Because it looks like the carets in your data are registering as 
escape characters. That ^H is registering as a backspace character, 
not the sequence "^H".
Volker
4-Nov-2005
[690]
any non-caret caret  ;?
Graham
4-Nov-2005
[691x2]
It's ^spaceH
ok, parse enhancement proposal .. allow one to change the escape 
character.
BrianH
4-Nov-2005
[693]
If you loading your data like you do when you type it on the interpreter 
command line, carets are treated as escape characters. If you are 
getting it from the read command, they aren't.
Volker
4-Nov-2005
[694]
that you have to escape all the ^ to ^^ in strings is true too, but 
not the error-reason. the rule should fail, not error.
Graham
4-Nov-2005
[695x3]
the data is medical HL7 formatted data.
It's being read in from a file.
so, it shouldn't be escaped in the data itself.
BrianH
4-Nov-2005
[698]
So if you copy your test data to the clipboard, you would assign 
it to a variable like this:
obx: read clipboard://

If you are reading it from a file with the read or open functions, 
there is no escaping.
Volker
4-Nov-2005
[699]
then it should be no problem. only when load sees it in strings. 
if you 'read it, no escaping is needed. and mold auto-escapes.
Graham
4-Nov-2005
[700]
Ok, I am testing on the command line.  May be that is the problem.
BrianH
4-Nov-2005
[701x3]
Try reading from the clipboard directly like I suggested for that.
Note: The form native doesn't escape on output like mold does.
Oh wait, the error in his parse statement isn't because of escaping. 
It's the thru bitset that isn't supported. Try this:
caret: charset "^^"
non-caret: complement caret

parse obx ["OBX" "|" digits "|" "ST" "|" any non-caret caret to end 
]
Graham
4-Nov-2005
[704]
does that return true ?
Volker
4-Nov-2005
[705]
should work like thru.  "any non-caret" is like "to caret", then 
skipping it is like "thru caret". without caret it would go to end, 
and then the final skip fail.
Graham
4-Nov-2005
[706]
>> obx: {OBX|1|ST|Hb^ Hb:^L||135|g/L|120 - 155|N|||F^/}
== "OBX|1|ST|Hb Hb:^L||135|g/L|120 - 155|N|||F^/"
>> caret: charset "^^"
== make bitset! #{
0000000000000000000000400000000000000000000000000000000000000000
}
>> non-caret: complement caret
== make bitset! #{
FFFFFFFFFFFFFFFFFFFFFFBFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
}
>> parse obx [ "OBX" copy test some non-caret caret to end ]
== false
>> test
== "|1|ST|Hb Hb:^L||135|g/L|120 - 155|N|||F^/"
>>
Volker
4-Nov-2005
[707x3]
Yes, so it works
remember the "^" in your string are no "^", else they would be molded 
as "^^"
i would really get the data from outside. put them in a file and 
use obx: read %data.txt, or use clipboard.
Graham
4-Nov-2005
[710]
ok, I'll give that a go later on.
Volker
4-Nov-2005
[711x2]
obx: {OBX|1|ST|Hb^^ Hb:^^L||135|g/L|120 - 155|N|||F^^/}
(or copy from altme ;)
Graham
4-Nov-2005
[713]
obx: {OBX|1|ST|Hb^ Hb:^L||135|g/L|120 - 155|N|||F^/}
Volker
4-Nov-2005
[714]
Hu? Does altme escape too? there should be duble "^^" everywhere.
Graham
4-Nov-2005
[715x2]
>> parse read clipboard:// [ copy test some non-caret caret to end 
]
== true
>> test
== "obx: {OBX|1|ST|Hb"
ok so that works.
BrianH
4-Nov-2005
[717]
Of course since you are looking for one character, you can use to 
or thru like this:
parse read clipboard:// [ copy test thru "^^" to end ]
Volker
4-Nov-2005
[718]
Meoww, thats to simple for me.. good catch :)
Graham
4-Nov-2005
[719x3]
well, if RT want to use Rebol in medical applications, they should 
look at making it easier to work with medical data !
OBX|1|ST|Hb^ Hb:^L||135|g/L|120 - 155|N|||F^/
Just using Altme as a clipboard.
BrianH
4-Nov-2005
[722]
Is there a standard we can read to get the syntax?
Graham
4-Nov-2005
[723]
HL7 - yeah, hundreds of pages of specs.
BrianH
4-Nov-2005
[724]
Aaak.
Graham
4-Nov-2005
[725]
http://www.hl7.org/
BrianH
4-Nov-2005
[726]
For instance, how many fields does that data you posted have? Are 
they seperated by | or is it a length thing?
Graham
4-Nov-2005
[727]
I don't know .. I am just looking at sample data and trying to reverse 
engineer the format as I don't have time to read 100s of pages of 
specs.
BrianH
4-Nov-2005
[728]
What does the ^ mean in context?
Graham
4-Nov-2005
[729x2]
but each OBX record is one blood result
It seems to be a delimiter to divide a record into parts
BrianH
4-Nov-2005
[731]
Really? By the format it looks like they are using | for that.
Graham
4-Nov-2005
[732]
so, | separates fields, and ^ sub divides a field