AltME: Parse


Which will always return false, I think.
or just: to end skip
Sorryi I confused I think, how do I write "except this one" like rule.
>> not-four: ["four" to end skip]
== ["four" to end skip]
>> parse/all "one two three" ["one " not-four " three"]
== false
>> parse/all "one two three" ["one " [not-four | to " "] " three"]
== true
Or use block parsing, if that's an option.
argh :)
Doesn't work.
I guess, you need to include all the ok possibilities?
Block parsing could be useful but I'm parsing huge SQL files which are not LOADable (and different formats from each other).
Switching to R3 is easier.
I think I need to play with index positions during the parse.
Thank you for your time Geomol.
I'll go with regular expression, ^((?!four).)*$
gives the lines does not contain "four".

not-four: [[(not-four/2: [])  "four" (not-four/2:  [thru end skip] ) | to " "]  []]
>> parse/all "one two three" ["one " not-four  " three"  ]
== true
>> parse/all "one four three" ["one " not-four  " three"  ]
== false
A variation of sqlab's approach:
>> space: [some #" "]
== [some #" "]
>> parse/all "one two three" [(fail?: none) "one" space ["four" space (fail?: [end skip]) | to #" " space] fail? "three"]                                                == true
>> parse/all "one four three" [(fail?: none) "one" space ["four" space (fail?: [end skip]) | to #" " space] fail? "three"]                                               == false
>> parse/all "one five three" [(fail?: none) "one" space ["four" space (fail?: [end skip]) | to #" " space] fail? "three"]                                               == true
If your case is more specific maybe it can be done in a different way, like checking for the condition after parsing, or filtering out the input you don't want in advance, and so on.
In Topaz you could do something like:
>> parse [one two three] ['one either 'four [(false)] [skip 'three (true)]]
== true
>> parse [one four three] ['one either 'four [(false)] [skip 'three (true)]]  
== false
(no string parsing yet so I used a block to illustrate)

Endo, you can try my parse enhancements at

I have an SQL text with arguments in the form ":argument_1" How do I get a list of the used arguments used in this SQL using parse?

Something like this?
>> digit: charset [#"0" - #"9"]
>> alpha: charset [#"a" - #"z" #"A" - #"Z"]
>> alphanum: union alpha digit
>> validchars: union alphanum charser [#"_"] ;put any other valid chars here
>> sql: {select * from table where a = :param1 and b=:param2     or x=3}
>> parse/all sql [some [thru ":" copy p some avlidchars (print p) | skip]]
You may need to cleanup comments, You can use something like:
remove-sql-comments: has [m n] [
    parse/all read clipboard:// [
        some [
            m: "--" to newline n: (remove/part m n) :m
            m: "/*" thru "*/" n: (remove/part m n) :m

Thank you Endo. This is very useful.
It is not complete, it doesn't care about comments in strings, but you got the idea.

Last message posted 149 weeks ago.