rebol / red parse with [to end] 规则
rebol / red parse with [to end] rule
我正在尝试从头开始理解解析,所以不要告诉我在这种情况下使用拆分。
sentence: "This is a sentence"
parse sentence [
any [
[any space] copy text [to space | to end] skip
(print text)
]
]
为什么我没有得到句子的最后一个字,只有:
This
is
a
[to end]
没用吗?
to end
确实有效,但是你有 skip
并且你已经到了最后,所以 skip
失败了。看到这个:
>> parse sentence [any [[any space] copy text [to space | to end ] (print text) skip]]
This
is
a
sentence
没有 to 和 end 的替代解决方案
sentence: "This is a sentence"
space: charset " "
chars: complement space
parse sentence [
any [
any space
copy text some chars
(print text)
]
]
在 Rebol2 中你必须使用 parse/all,如果你处理字符串,但是 Rebol2 中最简单的拆分解决方案是
>> parse sentence none
== ["This" "is" "a" "sentence"]
我正在尝试从头开始理解解析,所以不要告诉我在这种情况下使用拆分。
sentence: "This is a sentence"
parse sentence [
any [
[any space] copy text [to space | to end] skip
(print text)
]
]
为什么我没有得到句子的最后一个字,只有:
This
is
a
[to end]
没用吗?
to end
确实有效,但是你有 skip
并且你已经到了最后,所以 skip
失败了。看到这个:
>> parse sentence [any [[any space] copy text [to space | to end ] (print text) skip]]
This
is
a
sentence
没有 to 和 end 的替代解决方案
sentence: "This is a sentence"
space: charset " "
chars: complement space
parse sentence [
any [
any space
copy text some chars
(print text)
]
]
在 Rebol2 中你必须使用 parse/all,如果你处理字符串,但是 Rebol2 中最简单的拆分解决方案是
>> parse sentence none
== ["This" "is" "a" "sentence"]