More features and examples
The parse dialect has a lot more useful features and functionalities. In this section, we discuss some more examples, so that you get a feeling for what is possible.
Using end
Remember our vowels example from The bitset! datatype section?
;-- see Chapter08/more-features.red: vowel: charset"aeiou" str: "dog" find str vowel ;== "og"
Using parse we can write this as follows:
parse str [ to vowel toend] ;== true
parse"xyz" [ to vowel toend] ;== false
The end
word, which exists only in the parse dialect, returns true
when the current position pointer is at the end of the input.
Building special languages
Email addresses are of the form host@domain
, where domain
is a "."
followed by a three-letter domain name, and host
can contain letters, digits, and one or more "-"
, such as [email protected]
. We can build a pattern from the ground up to describe the components of an email pattern, like this:
digit: charset"0123456789" letter: charset [#"a" - #"z" #"A" - #"Z"] dash...