Information about block 'tests' in the nom language.
The nom language uses tests to match grammar parse tokens that have been popped from the pep machine stack . There are several different types of tests that can be combined together with AND logic (the “.” dot operator) and OR logic (the “,” comma operator as well as with the negation operator.
quoted text before a block {...} is an workspace equals test. This means that the test returns true if the workspace buffer is exactly the same as the quoted text at the time the script code is executed.
read; "a" {
clear; add "The letter 'a' \n";
print; clear;
}
quoted tests can be combined with the negation operator and the 'begins with' B and 'ends with' E operators. They can also be concatenated with the AND '.' and OR ',' operators.
read; "a",B"A",!B"z" {
clear; add "The letter 'a' or 'A' or anything not 'z' \n";
print; clear;
}
The class test checks whether the workspace buffer matches any one of the characters or character classes listing between the square braces. A class test is written.
[character-class] { <commands> }
There are 3 forms of the character class test:
read; ![aeiou] { print; } clear;
All characters in the workspace must match given class, so that a class test is equivalent to the regular expression “^[abcd]+$
” As in the previous example, class tests, like all other type of tests, can be negated with a prefixed “!” character. Double and multiple negation, such as “!!” or “!!!” is a syntax error (since it doesn't have any purpose).
r; [abc-,] { while [abc-,]; print; } clear;
This test returns true if the 'peep' look-ahead register currently contains the <EOF> end of stream marker for the input stream. This test is equivalent to the “END { ... }” block syntax in the AWK script language. The eof test is written as follows
<eof> <EOF> (eof) (EOF)
r; print; (eof) { add " << end of stream!"; } clear;
This test can be combined with other tests either with AND logic or with OR logic
r; (eof).E"horse" { add ' and cart'; print; }
r; (eof),E"horse" { add " <horse OR end-of-file> "; print; }
The <eof> test is important for checking if the script has successfully parsed the input stream when the end of stream is reached. Usually this means checking for the “start token” or tokens of the given grammar.
read;
# ... more code
(eof) {
pop;
"statement*" {
# successful parse
quit;
}
# unsuccessful pase
}
(==) { ...}
This test determines if the current tape cell is equal to the contents of the workspace buffer.
read;
(==) {
put; add ".same.";
}
print; clear;
Determines if the workspace buffer begins with the given text. It is written by preceding some quoted text with the capital letter B .
read; E" ",E"\n",(eof) { B"wh" { print; } clear; }
Tests if the workspace ends with the given text. The 'E' (ends-with modifier) can only be used with quoted text but not with class tests
r; E[abcd] { print; } clear;
r; E"less" { print; } clear;
read; E" ",E"\n" { clip; E"ess" { add " "; print; } clear; }
Conditional tests can be chained together with OR (,) or AND (.)
B"http:",B"ftp:" { print; }
“AND” and “OR” test cannot be combined simply, but a similar thing can be achieved by nesting tests in braces. It may be useful to add logic grouping for tests, eg: (B"a",B"b").E"z" { ... } however this is not currently supported.
B"a".E"z",E"x" { print; } # wrong!
B"a",B"b" { E"z" { ... }}
((workspace BEGINS WITH "a") OR (workspace BEGINS WITH "b"))
AND (workspace ENDS WITH "z")
read; B"http://",B"https://",B"www.",B"ftp:" {
E" ",E"\n",(eof) { add "\n"; print; clear; }
}
E" ",E"\n",(eof) { clear; }
read; [:space:] {clear;} whilenot [:space:];
"dog","cat","lion","puma","bear","emu" { add "\n"; print; }
clear;
It possible to concatenate any type of test or negated test with the the logical AND operator which is the dot “. ” in the ℕ𝕠𝕞 language.
r; B"a".E"z" { print; clear; }
B"http://".!E".txt" { add "<< non-text url"; print; clear; }
B"#".[#0123456789] { add " (timestamp?)\n"; print; }
“AND” logic can also be achieved by nesting brace blocks. In some circumstances this may may have advantages.
B"/" { E".txt" { ... } }
A preceding “!” not operator is used for negating tests.
!B"abc", !E"xyz", ![a-z], !"abc" ...