Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: why this rule always give "a" ?
Pages: [1] Print
Author Topic: why this rule always give "a" ?  (Read 357 times)
parse
Guest


Email
why this rule always give "a" ?
« on: September 25, 2005, 03:24:59 AM »

>> rules: ["a" (probe "a") | "ab" (probe "ab")]
== ["a" (probe "a") | "ab" (probe "ab")]
>> parse "a" rules
"a"
== true
>> parse "ab" rules
"a"
== false
>>
Logged
parse
Guest


Email
why this rule always give "a" ?
« Reply #1 on: September 25, 2005, 03:57:36 AM »

Sorry I forgot end
>> rules: ["a" end (probe "a") | "ab" end (probe "ab")]
== ["a" end (probe "a") | "ab" end (probe "ab")]
>> parse "ab" rules
"ab"
== true


=================

but the problem is rather when I want to copy text after "a" or "ab" it doesn't give me textab:

>> rules: ["a" copy text to end (probe "a") | "ab" copy text to end (probe "ab")]
== ["a" copy text to end (probe "a") | "ab" copy text to end (probe "ab")]
>> parse "ab" rules
"a"
== true
>> parse "a texta" rules
"a"
== true
>> text
== " texta"
>> parse "ab textab" rules
"a"
== true
>>
Logged
CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
why this rule always give "a" ?
« Reply #2 on: September 25, 2005, 10:55:38 PM »

The problem is it's finding an "a" in the "ab textab", so the first part of the rule is satisfied.  Swap them around and it should work.  ie...
Code:
>> rules: ["ab" copy text to end (print [1 text ]) | "a" copy text to end (print [2 text])]
== ["ab" copy text to end (print [1 text]) | "a" copy text to end (print [2 text])]
>> parse  "axyz" rules
2 xyz
== true
>> parse  "abc" rules
1 c
== true
Hope that helps.
Logged

- Carl Read
parser
Guest


Email
why this rule always give "a" ?
« Reply #3 on: September 27, 2005, 03:47:01 AM »

Thanks, it helps Smiley
Logged
Guest
Guest


Email
why this rule always give "a" ?
« Reply #4 on: September 27, 2005, 08:41:51 AM »

Now this trick doesn't work in a special case when newline is involved : I can't get at the output

command1
command1
command2

but only
command1
command1

--------------------------------------

list-commands: {
command1

command1 <
test1
>

command2 <
test2
>

}

rules: [
[
    copy command to "<" copy param to ">" (probe command)
    |
    copy command to newline (probe command)
]
to end    
]

parse list-commands rules

>> parse list-commands rules
{
command1

command1 }
== true
>>
Logged
parser
Guest


Email
why this rule always give "a" ?
« Reply #5 on: September 27, 2005, 10:18:01 AM »

For the case above I really don't understand why it give "command1 <" instead of
{command1
command1
command2}

rules: [

    any [
            [
                some newline
                copy command to " " "<"
                copy param to ">" ">"
                some newline
                (probe command)
            ]
            |
            [
                some newline
                copy Command to newline
                some newline
                (probe command)
            ]
       
        ]
        some newline
        to end
]

list-commands: {
command1 <
test1
>

command1


command2 <
test2
>

}

parse/all list-commands rules

>> parse/all list-commands rules
"command1 <"
== false
>>
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: why this rule always give "a" ?
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 21, 2008, 05:56:17 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2290 Posts in 593 Topics by 3742 Members
Latest Member: CorHorgeExpex

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc