World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Steeve 8-Nov-2008 [3051] | i just have a doubt, in my scripts i like using parse to change a serie. Some of this rules are recursives so that they can apply several modifications on modifications. In such a case i would break your rule to not return in the same point. |
BrianH 8-Nov-2008 [3052x2] | That is why it would be optional. |
By recursives you meant iteratives. Recursives don't use loops. | |
Steeve 8-Nov-2008 [3054x2] | I have a set of rules in an any block wich apply modifications, the same block of rules is applied until there is no more modifications. I don't know h |
how to call that | |
BrianH 8-Nov-2008 [3056] | That is iterative changes. Each round of changes is an iteration. |
Steeve 8-Nov-2008 [3057] | ok |
BrianH 8-Nov-2008 [3058] | That kind of thing can be very powerful. As long as you have a fixpoint (a reachable condition to break you of the loop) you'll be fine. |
Steeve 8-Nov-2008 [3059] | yeah i know it's difficult to create, but when it works it's incredibly compact and powerfull, i like compactness |
BrianH 8-Nov-2008 [3060] | Rewrite rules usually work this way. |
Steeve 8-Nov-2008 [3061] | about your proposal i just will say that is not an high request but if it's free i take it |
BrianH 8-Nov-2008 [3062] | I think it will be better to include this in the tracing infrastructure. |
Steeve 8-Nov-2008 [3063x3] | ok another proposal |
currently when we parsing a serie we can't mix constant string! and constant binaries together | |
we have to choose depending of the type of the serie | |
BrianH 8-Nov-2008 [3066x3] | That will be moreso in R3 because string! and binary! aren't compatible any more. |
Unicode changes. A binary is a series of bytes, a string is a series of codepoints. | |
AS-STRING and AS_BINARY are gone. | |
Steeve 8-Nov-2008 [3069] | but at certain point a string can be converted to a binary an vice versa |
BrianH 8-Nov-2008 [3070x2] | Yes, but that is a real conversion, with encoding and decoding. |
Just like converting from a .jpg to an image! and back. | |
Steeve 8-Nov-2008 [3072] | when u say 'real' u mean a large time consuming conversion ? |
BrianH 8-Nov-2008 [3073x2] | Hopefully not time-consuming but definitely large, depending on the size of the string. |
The Unicode changes were pretty significant and deep. | |
Steeve 8-Nov-2008 [3075x3] | not the subject, but speaking of consuming operations, what about the old idea to have subset of serie (range) without the need to copy/part series ? |
Carl spoken of that in the past | |
*abouty | |
BrianH 8-Nov-2008 [3078] | It was rejected as a base type because it was deemed unnecessary, but could be added as a UDT. |
Steeve 8-Nov-2008 [3079x3] | UDT ? |
about proposals, currently we have only one atom operation to control advance in the serie: [skip]. We could had some other atom operations, like DROP,SWAP,ROT,DUP. (any reference to FORTH language are intentional) | |
don't ask me an usage, it's only because i'm currently working on a FORTH engine | |
BrianH 8-Nov-2008 [3082x3] | UDT = user-defined datatype!, a planned feature of R3. Yes, this includes user-defined function types in theory. |
DROP, SWAP, ROT and DUP are stack modification operations, not parse advancement operations like SKIP. Don't forget REVERSE and matching operations - they advance too. | |
My bad: REVERSE doesn't advance. | |
Steeve 8-Nov-2008 [3085x6] | i know what they are (trust me) it was a sort of transposition to parse |
image just that parsing a serie is like working with a stack, the analogy is not as bad as you think | |
*imagine | |
in an other way, SWAP, ROT, DUP or DROP are not just advance operations , they modify the serie too. | |
... I really don't what could be their usage, forget that... | |
*don't know | |
Anton 8-Nov-2008 [3091] | Just some ideas for possible usage. [[item1 item2 | item2 item1 SWAP] ] ; Put previous two matched items in order. ==> [item1 item2] ; Always sorted. [ROT [a b c d e]] ; Rotate items matched by next subrule, if it matches. ==> [b c d e a] ; [start: a [b c] DUP start] ; Duplicate items from start to current parse index. ==> [a b c a b c] [a DROP [b c]] ; If next subrule matches, then remove items matched, and set parse index back to the beginning of the remove. ==> [a] (DROP is just like REMOVE, so not really needed, I think. Just doing the exercise to see.) The above can be categorized by how they fetch their arguments: - Take two previously matched items/subrules (like SWAP). - Match the next subrule (like ROT, DROP). - Use a variable to take the parse index (like DUP). |
Steeve 8-Nov-2008 [3092] | well done Anton. To have a more genralized form, all these operations could work on an Index, like your DUP |
Anton 8-Nov-2008 [3093x2] | We can implement DUP today using our own function (not a parse command). The equivalent to above DUP example would be: [start: a [b c] finish: (DUP start finish length: finish - start) skip length] or maybe [start: a [b c] finish: (DUP start 'finish) :finish] ; (where DUP modifies 'finish) |
So that's what the DUP command would save us. | |
Pekr 9-Nov-2008 [3095] | BrianH: as for parse catching infinite loops - don't you think that ppl would always want to be protected by such a feature? So why not make it standard? How usefull is parse, if it loops infinitely? Your app hangs, or crashes anyway ... |
Oldes 9-Nov-2008 [3096] | not always. if you need maximal speed. and you trust the data and rules. |
Henrik 9-Nov-2008 [3097] | Hanging parsers to me is usually a problem when developing them. |
Anton 9-Nov-2008 [3098x3] | Steve said in r3-alpha world: Sometimes some of my parse rules can take overnight to resolve on some complex random files...and I would like to be able to set a time limit in parse so that if it is recursively grinding on time, that I can halt it |
So Steve needs to leave his parse rule unattended for long periods. | |
And when he returns, if it timed out, he wants to see where it got up to. | |
older newer | first last |