rebol:如何创建规则来解析大括号?

时间:2009-09-20 19:48:17

标签: rebol

我还没掌握Parse规则:)

我如何解析这个?

to-parse: [entity Person {
    String name
    String lastName
    Address home
    Address business
}]

这不起作用:

entity-rule: ['entity word! #"{" to end]
>> parse to-parse entity-rule
== false
>>

2 个答案:

答案 0 :(得分:5)

to-parse 块中的第三个元素不是char {。这是一个字符串 - REBOL字符串可以描述为“......” {...}

type? to-parse/3
== string!
to-parse/3
{
   String name
   String lastName
   Address home
   Address business
}

要成功解析块,您需要查找字符串:

entity-rule: ['entity word! string! to end]
parse to-parse entity-rule
== true

答案 1 :(得分:5)

to-parse: [entity Person {
    String name
    String lastName
    Address home
    Address business
}]

person-rule: [  
    thru "String " copy name to newline (append names name) thru newline |
    thru "Address " copy address to newline (append addresses address) thru newline |
    skip end
]

parse to-parse [ 
    'entity 'person 
    set details string! (
        names: copy [] addresses: copy []
        parse details [ some person-rule ]
    )
]

会将名称收集到块名称中,并将地址收集到块地址中。 但这个答案在Rebol3中不起作用。不知道为什么不。