我真的还没有掌握 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
>>
我真的还没有掌握 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
>>
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 中不起作用。不知道为什么不。
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