Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #1874
| Newsgroups | comp.lang.postscript |
|---|---|
| Date | 2014-05-04 00:07 -0700 |
| References | <9390d2cf-673b-4a95-95a0-353d1c490804@googlegroups.com> <1wbu30s3mcawh.141eoar302iap$.dlg@40tude.net> <8b1f74a2-fb5b-42c8-9f13-eb18d58d9585@googlegroups.com> |
| Message-ID | <4b6f39ff-1fae-4c2c-8a7f-e55fb7c437bc@googlegroups.com> (permalink) |
| Subject | Re: Regexp expression that selects PostScript strings |
| From | luser- -droog <mijoryx@yahoo.com> |
On Saturday, May 3, 2014 11:42:33 PM UTC-5, luser- -droog wrote:
> On Saturday, May 3, 2014 7:52:38 PM UTC-5, tlvp wrote:
>
> > On Sat, 3 May 2014 13:50:42 -0700 (PDT), jdaw1 wrote:
>
> >
> > > Does anybody have to hand a regexp expression that selects PostScript strings?
> > >
> > > As a simple non-example, \([^\)]*\) fails to cope with the likes of
> > >
> > > (and (as an aside) this should be mentioned)
> > >
> > > and also with strings containing \( or \).
> >
> > Why would you have expected it to cope with the likes of that?
> > What it seems designed to cope with is the likes of this:
> >
> > : (and )as an aside) this should be mentioned)
> >
>
> Not sure about the example, but I think in general
> regular expressions cannot handle postscript strings
> because of the possibility of nested un-escaped parens.
My own code for validating a postscript "statement"
containing complete but arbitrarily nested parens,
braces, and angle-brackets, is a push-down automaton,
the next class up from the finite-automata that can
process regular expressions.
http://code.google.com/p/xpost/source/browse/src/lib/xpost_file.c#198
/* pinch-off a tmpfile containing one "statement" from file. */
/*@null@*/
static
int statementedit(FILE *in, FILE **out)
{
FILE *fp;
int c;
char nest[MAXNEST] = {0}; /* any of {(< waiting for matching >)} */
int defer = -1; /* defer is a flag (-1 == false)
and an index into nest[] */
c = fgetc(in);
if (c == EOF)
{
return undefinedfilename;
}
#ifdef DEBUG_FILE
printf("tmpfile (fdopen)\n");
#endif
fp = f_tmpfile();
if (fp == NULL) {
XPOST_LOG_ERR("tmpfile() returned NULL");
return ioerror;
}
do {
if (defer > -1) {
if (defer > MAXNEST)
{
return syntaxerror;
}
switch(nest[defer]) { /* what's the innermost nest? */
case '{': /* within a proc, can end proc or begin proc, string, hex */
switch (c) {
case '}': --defer; break;
case '{':
case '(':
case '<': nest[++defer] = c; break;
} break;
case '(': /* within a string, can begin or end nested paren */
switch (c) {
case ')': --defer; break;
case '(': nest[++defer] = c; break;
case '\\': fputc(c, fp);
c = fgetc(in);
if (c == EOF) goto done;
goto next;
} break;
case '<': /* hexstrings don't nest, can only end it */
if (c == '>') --defer; break;
}
} else switch (c) { /* undefined, can begin any structure */
case '{':
case '(':
case '<': nest[++defer] = c; break;
case '\\': fputc(c, fp);
c = fgetc(in); break;
}
if (c == '\n') {
if (defer == -1) goto done;
{ /* sub-prompt */
int i;
for (i=0; i <= defer; i++)
putchar(nest[i]);
fputs(".:", stdout);
fflush(NULL);
}
}
next:
fputc(c, fp);
c = fgetc(in);
} while(c != EOF);
done:
fseek(fp, 0, SEEK_SET);
//return fp;
*out = fp;
return 0;
}
Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Regexp expression that selects PostScript strings jdaw1 <jdawiseman@gmail.com> - 2014-05-03 13:50 -0700
Re: Regexp expression that selects PostScript strings tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2014-05-03 20:52 -0400
Re: Regexp expression that selects PostScript strings luser- -droog <mijoryx@yahoo.com> - 2014-05-03 21:42 -0700
Re: Regexp expression that selects PostScript strings luser- -droog <mijoryx@yahoo.com> - 2014-05-04 00:07 -0700
Re: Regexp expression that selects PostScript strings jdaw1 <jdawiseman@gmail.com> - 2014-05-04 07:48 -0700
Re: Regexp expression that selects PostScript strings jdaw1 <jdawiseman@gmail.com> - 2014-05-05 08:48 -0700
Re: Regexp expression that selects PostScript strings jdaw1 <jdawiseman@gmail.com> - 2014-05-05 08:58 -0700
Re: Regexp expression that selects PostScript strings luser- -droog <mijoryx@yahoo.com> - 2014-05-06 09:58 -0700
csiph-web