Rebol problem

simple parsing example:

ab: charset "ab"
parse "aaa" [some ab]  
; == true

If I need a single-liner (define ab in place) how to do this?

parse "aaa" [some [charset "ab"]]
; ** Script Error: Invalid argument: ?function?

parse "aaa" [some (charset "ab")]
; (INTERPRETER HANGS UP)

I am using REBOL 2.7.7.4.2

UPDATE

in rebol 3:

parse "aaa" [some (charset "ab")]
; == false
+3
source share
3 answers

You are looking for 'compose

>> parse "aaa" compose [ some (charset [#"a" #"b"] ) ]
== true
+2
source

In the parser dialog dialect, expressions are calculated in brackets. However, the result of the assessment does not become part of the analysis rule. This is by design, so you can work in this style:

>> count: 0
== 0

>> parse "aab" [while ["a" (print "Match a" ++ count)] "b"]
Match a
Match a
== true

>> count
== 2

- . (, ) COMPOSE, . :

>> count: 0
== 0

>> rule: compose/deep [while ["a" (print "Match a" ++ count)] "b"]
Match a
== [while ["a" 0] "b"]

>> count
== 1

>> parse "aab" rule
== false

AFAIK, Rebol 2 "DO" . , , .

Rebol 3 DO, , -. wiki, , true "abc":

>> result: none
== none

>> parse "abc" [copy result thru do [reverse "cba"]]
== false

>> result
== none

( , - " DO COPY, SET RETURN. , , , ...)

+2

What you were really looking for was probably

>> parse "aaa" [(ab: charset "ab")  some ab]
== true

define the word at the beginning inside the parsing expression and later use that word as part of the rule

0
source

Source: https://habr.com/ru/post/1759554/


All Articles