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

发布于 2024-08-05 10:43:45 字数 305 浏览 2 评论 0原文

我真的还没有掌握解析规则:)

我该如何解析这个?

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

这不起作用:

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

I really don't master Parse rule yet :)

How do I parse this ?

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

This doesn't work:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜清冷一曲。 2024-08-12 10:43:45

to-parse 块中的第三个元素不是字符 {。它是一个字符串——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

The third element in your to-parse block is not the char {. It's a string -- REBOL strings can be delineated "..." or {...}

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

To parse the block successfully, you need to be looking for a string:

entity-rule: ['entity word! string! to end]
parse to-parse entity-rule
== true
她如夕阳 2024-08-12 10:43:45
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: [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 ]
    )
]

will collect the names into the block names, and addresses into the block addresses.
This answer doesn't work in Rebol3 though. Not sure why not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文