Rebol / red parsing. Save ASCII codes from parsing a string to a variable?

I came across the RED language the other day and spent (more or less literally) the last 24 hours of “learning” this. I have exhausted my Google skills, trying to find a solution to a simple problem that just dodges my skills and logic, so I hope someone here can lead me to the path to righteousness.

As the name implies, I tried to parse a simple line (any line of random text, really), get an individual char (acter) s, and then tried to save them in a variable. (Another line / array / any type)

The best I could do was use the code:

alpha: charset [#"a" - #"z"] testString: "this is just random rambling to test parsing!" 

as prerequisites and something like this when (trying) to parse:

 probe parse teststring [copy text to alpha (append text2 to-integer(to-char text)) to end] 

Saves ascii code (first letter) ascii for text2 and runs the script several times in a row, correctly adds (the same first character) ASCII code several times in a row:

CONSOLE OUTPUT

 >> probe parse teststring [copy text to alpha (append text2 to-integer(to-char text)) to end] true == true >> probe text2 "34" == "34" >> probe parse teststring [copy text to alpha (append text2 to-integer(to-char text)) to end] true == true >> probe text2 "3434" == "3434" 

Obviously, my parsing does not actually “loop” the individual characters of the string or save them correctly when doing this. Maybe my parsing really takes the whole line from TO to END, and I'm trying to convert this to ASCII code then, or is something else going on here?

ANY help would be greatly appreciated since I cannot advance with my RED training before solving this dilemma and understanding how parsing really works in RED.

+5
source share
1 answer

I'm not sure if I understand your question and what you want to achieve, but if you are looking for all ascii representations of characters, you can get this with

 asciis: [] parse teststring [some [set a alpha (append asciis to-integer a )| skip]] == true >> asciis == [116 104 105 115 105 115 106 117 115 116 114 97 110 100 111 109 114 97 109 98 108 105 110 103 116 111 116 101 115 116 112 97 114 115 105 110 103] 

some is one of the available words for the loop

There are some problems during the testing process. This will lead to some errors before any conversion. text2 is probably announced earlier. in alpha will give an empty string "" when trying to copy to the first alpha character. Remember that up is appropriate and does not include the goal. You cannot convert an empty string to a character. If we assume that no error has occurred so far, you are still in front of your line, and you go straight to the end of your line.

Some documentation on red analysis . see looping iteration

You can debug your parsing with parse-trace or simply put a simple (probe text) after the part of your rule that you want to examine:

+3
source

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


All Articles