World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
Maxim 3-May-2009 [2003x2] | its creates something of a parralel to a closure. |
it can be usefull when you know exactly what can happend, but otherwise you are better of skipping. | |
mhinson 3-May-2009 [2005] | I was engaging the use of "to" in the belief that it was the only way to include the key I was using to find my data in the output from my copy. |
Maxim 3-May-2009 [2006x4] | I find that there several types of broad parse rule families. -some find and extract values OUT of some arbitrary string. -some are used as advanced controled structures, where you can pretty much simulate lisp functional programming, -some are used to convert data streams -others simply can match a whole data set to make sure it conforms. (+probably others) strangely each type of setup has sort of a different global approach, but its very case specific obviously. |
generally, you should realise that when you build parse rules to need to have some sort of sence of "context" i.e. Where are you in your data. this will help you a lot. | |
where as in at what point in the string AND where in the sense of a what step are you now in the parsing. | |
thinking in those terms makes the rules much easier to place in what I like to call "PARSE SPACE" where everything is a little bit odd ;-)f | |
mhinson 3-May-2009 [2010] | The type I am most interested in at the moment are constructs to extract data from strings read from files. Sometimes changing the subsequent behaviour dependent on what has alredy been found. |
Maxim 3-May-2009 [2011] | ok. I have only about 10 minutes to give you, but I'll make the best of them. |
mhinson 3-May-2009 [2012] | Thank you |
Maxim 3-May-2009 [2013] | lesson one, find text AFTER some identifiable (and unmistakable) token: |
mhinson 3-May-2009 [2014] | That I think I can do |
Maxim 3-May-2009 [2015x2] | given: data: "THIS IS A TEST STRING WITH A <TAG> IN IT " |
if we want to extract what is after that single tag, then you can easily use to or even better thru: but lets do it using skip. starting with a simple example will make the lesson 2 more obvious. | |
mhinson 3-May-2009 [2017] | great |
[unknown: 5] 3-May-2009 [2018] | What would be ideal is to be able to use TO on charsets within the parse rule. |
mhinson 3-May-2009 [2019] | parse/all data [thru "<TAG>" copy result to end] print result |
Maxim 3-May-2009 [2020x3] | parse/all data [ some [ ["<TAG>" here: (print rejoin ["we are passed the <TAG!> : '" here "'"]) ] | skip ] ] |
note, we are using skip, to get familliar with the basics of rollback... | |
does the above make sense to you? | |
mhinson 3-May-2009 [2023] | does "some" make it repeat? |
Maxim 3-May-2009 [2024] | yes, and at least one rule must match or else it fails and rolls back to parent. rule |
mhinson 3-May-2009 [2025] | but skip will always succeed? |
Maxim 3-May-2009 [2026] | so can you explain to me why the ["<TAG" ... ] rule is BEFORE the skip rule? |
mhinson 3-May-2009 [2027] | is it because thay are itterated in order? |
Maxim 3-May-2009 [2028x4] | that is the reason for the lesson... once you grasp that you are about 50% there already :-) |
some will loop over and over until ALL rules fail. if that happens then IT fails too. | |
'SOME will loop .... | |
so why did it only print the string once? simple question... but not so obvious to answer for a newbie :-) | |
[unknown: 5] 3-May-2009 [2032] | Here is a crude way to do what we did earlier that doesn't use parse but matches any part to any first occurence of the letter >> chars: charset "by" == make bitset! #{ 0000000000000000000000000400000200000000000000000000000000000000 } >> copy/part z: find {aabbyyc} chars next find z "c" == "bbyyc" |
mhinson 3-May-2009 [2033] | because the match only occured once? |
Maxim 3-May-2009 [2034x2] | yep... it only was able to match the first rule when got AT that point in the data |
every other time (including after it matched the tag) the second, alternative, rule matched, and we where able to hit the end of the string. | |
mhinson 3-May-2009 [2036] | <TAG> here: here only gets the remaining part of the string assigned to it if the previous key parse returns true |
Maxim 3-May-2009 [2037] | set words within parse rules are set to the point in the series that the parser IS , AT that exact moment. |
mhinson 3-May-2009 [2038] | I read about that & how [index? here] will return that position |
Maxim 3-May-2009 [2039x2] | so if you had put the HERE: like so: [here: "<TAG>" ... then the tag itself would be part of the printed string. |
but note that at that point, it has not matched the "<TAG>" yet ! | |
mhinson 3-May-2009 [2041x2] | so is the first position in the parse expression special in that it is always evaluated? |
I see it is parse {123} [(print "hello")] | |
Maxim 3-May-2009 [2043] | it evaluates until it finds a given character that it cannot match |
mhinson 3-May-2009 [2044] | Maxim, I fear my 10 mins are more than up, please dont let me keep you from your tasks. You have been more than kind. |
[unknown: 5] 3-May-2009 [2045] | the thing to know about parse mhinson is that you want to set forth the righ matching conditions to get to the end of the string that your parsing because if something doesn't match it will abort at that point and return false. |
Maxim 3-May-2009 [2046] | ok, I'll be back later for lesson two :-) but I'll give you a simple lesson 1.5 assignment ;-) edit the above so it matches either "<TAG>" OR "[TAG]" :-) |
mhinson 3-May-2009 [2047] | ok thanks Maxim. |
Maxim 3-May-2009 [2048] | I'm keeping it baby steps, but these are the simple building block which really build up about 90% of all real dialects. |
mhinson 3-May-2009 [2049] | Thanks Paul, I fear I have been ignoring the use of other things like find. I guess with more complex parse expressions find may be a shortcut to extract a substring from a predictable block of text.. |
[unknown: 5] 3-May-2009 [2050] | Yeah, I often resort to find over parse because it makes more mental sense to me. |
Maxim 3-May-2009 [2051] | the "comprehension" of those simple things is essential, simply knowing about them is useless... cause in real life, you will have to "SEE" the whole recursive structure of the parse rules played in your head. if you don't fully grasp what is going on, you can't really create that essential mental map. that is what kept me from understanding parse for 6 yess... SIX years :-( and suddenly over the course of 2 days, I finally "GOT" it and a week later I was building a 700 line parse rule for a real-time server doing signal convertion from one data format to another through two network ports. |
mhinson 3-May-2009 [2052] | I think I partly got the feeling that anything other than parse was non-purist. |
older newer | first last |