Hi Don,
I tried running your program.
To get it to do anything I had to change line 2, separate the local
declaration and the assignment.
to clarify, repat is a (new) variable that I intend to hold a pattern
procedure main(args)
local f, line, re
re := pop(args)
write(re)
repat := re
every f := open(!args, "r") do {
while ( line := read(f) ) do {
if line ?? repat then write(line)
}
}
end
I created qqq.txt with the lines
QQQ
qqq
cqcqcq
and ran testpat QQQ qqq.txt after compiling testpat.icn
Output was
QQQ
then the contents of qqq.txt
as if repat always matches. (it has the null value??)
I tried forcing repat to be a pattern (utr18 says that patterns are
composed of strings concatenated or alternated) so I tried
repat := re .| fail()
repat := re .| re
but the pattern building process gave me node errors at compile time.
dopat2.icn:6: # "re": syntax error (237;349)
File dopat2.icn; Line 16 # traverse: undefined node type
line 16 is the line after end in main, i.e. program source end.
I tried using the -f s option at the compile step, so as to use
unevaluated expressions in patterns
like
repat := < `re` >
# that syntax ought to force a pattern!
node traversal errors again. And the backquotes were not recognised.
Perhaps I put the -f s option in the wrong place?
I also tried
repat := < Q > || < Q > || < Q >
dopat2.icn:6: # "repat": invalid argument in augmented assignment
File dopat2.icn; Line 16 # traverse: undefined node type
so it is not considering || to be pattern concatenation
repat := < Q || Q || Q >
gave the same error!
So although UTR18 seems to give options for converting strings to
patterns I have not had any luck so far.
Jay
On 29/11/2016 14:33, Don Ward wrote:
Here is a very simple (and simple minded) grep program. The idea being
to apply a Unicon regexp pattern to a series of files, just like grep
procedure main(args)
local f, line, re := pop(args)
every f := open(!args, "r") do {
every line := !f do {
if line ?? re then write(line)
}
}
end
Of course, it doesn’t work because in line 6 I have a string instead
of a pattern.
Is there any way to convert the contents of re from a string to a pattern?
After reading UTR18 again (and again), I’ve come to the conclusion
that there isn’t any way to do it.
The pertinent extract from UTR18 is in section 4.5.3 "Limitations due
to lack of eval()”.
But before I give up on the idea entirely, I thought I’d check to see
if my understanding is correct.
Don
------------------------------------------------------------------------------
_______________________________________________
Unicon-group mailing list
Unicon-group@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/unicon-group
------------------------------------------------------------------------------
_______________________________________________
Unicon-group mailing list
Unicon-group@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/unicon-group