How to ignore lines that are commented out while parsing?

I have a PHP array that I process to get email addresses. Sometimes I want to comment on a post, so I can use a different value for testing.

Here is an example array:

array('system.email' => array(
    'to' => array(
        'contactus' => 'contactus@example.com',
        'newregistration' => 'newreg@example.com', 
        'requestaccess' => 'requestaccess@example.com',
//            'workflow' => 'workflow@example.com'
        'workflow' => 'test_workflow@example.com'
    )  
));

Here is my PARSE rule:

parse read %config.php [
    thru "'system.email'" [
        thru "'to'" [thru "'workflow'" [thru "'" copy recipient-email to "'^/"]]
    ] to end
]

When I run this, the value recipient-emailwill be " workflow@example.com ". How can I write my rule in such a way that it ignores the line starting with //?

+4
source share
1 answer

The rule for using the comment line will look something like this:

spacer: charset reduce [tab cr newline #" "]
spaces: [some spacer]
any-spaces: [any spacer]

[any-spaces "//" thru newline]

, . .

text: {array('system.email' => array(                                                      
    'to' => array(                                                                  
        'contactus' => 'contactus@example.com',                                     
        'newregistration' => 'newreg@example.com',                                  
        'requestaccess' => 'requestaccess@example.com',                             
//            'workflow' => 'workflow@example.com'                                  
        'workflow' => 'test_workflow@example.com'                                   
    )                                                                               
));}

list: []

spacer: charset reduce [tab cr newline #" "]
any-spaces: [any spacer]

comment-rule: [any-spaces "//" thru newline]

email-rule: [
    thru "'"
    copy name to "'" skip
    thru "'" 
    copy email to "'"
    thru newline
]

system-emails: [
    thru "'system.email'" [  
        thru "to' => array(" 
        some [
            comment-rule |
            email-rule (append list reduce [name email])
        ]    
    ] to end
]

parse text system-emails
print list

.

, . , :

decomment: func [str [string!] /local new-str com comment-removing-rule] [

    new-str: copy ""

    com: [
        "//"
        thru newline
    ]
    comment-removing-rule: [
        some [
            com |
            copy char skip (append new-str char)
        ]
    ]

    parse str comment-removing-rule
    return new-str
]
+5

All Articles