PostScript String production.

Power Java
Parsing With JavaCC
by Steve Kapp
Listing 3. PostScript String production.


01    PSObject stringType(PSEnvironment env): { Token t;
                              String s; PSObject obj; } {
02          t = <PS_STRING> {
03               // Remove the enclosing delimiters "(" and ")"
                                                         from the string.
04               s = t.image.substring(1, t.image.length() - 1));
05               return (new PSString(s, false));
06          }
07        | t = <HEX_STRING> {
08               // Remove the enclosing delimiters "<" and ">"
                                                         from the string.
09               s = t.image.substring(1, t.image.length() - 1));
10               if ((s.length() % 2) == 1) {
11                  s = s + "0";
12               }
13               return (new PSString(s, false));
14          }
15    }

About the Author

Steve Kapp is a client partner at EMRT in Rochester, NY. Steve can be contacted at [email protected].