Menu

Question re. COPY-REPLACING

Help
KrisDS
2015-03-04
2015-03-05
  • KrisDS

    KrisDS - 2015-03-04

    I have been working towards resolving issue [#54], but I think I'm missing something...

    The issue shows a replacing clause like:

        REPLACING == :L: == BY == SDH2F ==
    

    That is, it's looking for "== :L: ==". Given that the ":L:" is surrounded with spaces, and based on my reading of the spec, that means it's looking for an ":L:" surrounded with spaces in the copy file. But occurrences of ":L:" there look like:

        05  :L:-COD-PAIS                PIC X(2).
    

    I.e. no spaces surrounding the ":L:".

    Am I missing something in the spec which says that surrounding spaces don't count for some reason ? Because I don't see anything like that, and I'm wondering whether the example is being tolerated by the compiler, rather than adhering to the Cobol spec...

     

    Related

    Issues: #54


    Last edit: Simon Sobisch 2015-03-05
  • Inaki GE

    Inaki GE - 2015-03-05

    Hi again,
    I have checked more in depth what you say and I have found the following link:
    http://publib.boulder.ibm.com/iseries/v5r1/ic2924/books/c0925392609.htm#SPTCPY1PT

    As you can read when appearing a pseudo text (between "==") in the REPLACING clause, "Pseudo-text-1 must contain at least one text word other than a separator comma or separator semicolon. Beginning and ending spaces are not included in the text comparison process, and multiple embedded spaces are considered to be a single space."

    I have checked Koopa's latest version (r214) with COPY REPLACING statement not surrended by spaces and issues with PIC definition do not appear now. However, as I can see, the content of the COPY file is not integrated in the XML generated file. I suppose you will extend this functionality when adapting the grammar for COPY REPLACING stamtent.

    Please, let me know about it.
    Thanks. Best regards.

     
  • KrisDS

    KrisDS - 2015-03-05

    Thanks for that reference. I was looking for a similar clause in the standard spec, but did not find it. Still, I'll update the code to ignore leading and trailing spaces.

    As for the XML: if the copybook is found its contents should end up in the XML output. How are you invoking this ?

     
    • Simon Sobisch

      Simon Sobisch - 2015-03-05

      The standard spec has (see 7.2 Text manipulation):

      COPY literal-1 REPLACING == pseudo-text-1 == BY == pseudo-text-2 ==.
      
      • Pseudo-text-1 shall contain one or more text-words, at least one of which shall be neither a separator comma nor a separator semicolon.
      • Pseudo-text-2 shall contain zero, one, or more text-words.

      with the partially definition for Text-words (formatting in bold just for highlighting, not in the spec):

      A text-word is a character-string, other than a comment or the COBOL word 'COPY', in source text or in library text that constitutes an element processed by text manipulation. A text-word may be one of the following:
      1) a separator, except for: a space; a pseudo-text delimiter; and the opening and closing delimiters for alphanumeric, boolean, and national literals [...];
      2) a [...] literal including the opening and closing delimiters that bound the
      literal;
      3) any other character or sequence of contiguous characters from the compile-time coded character set, bounded by separators. [...]

      Therefore all spaces (outside of a literal) are just delimiting the text-words, they aren't matched against at all.

      BTW: According to the spec the original REPLACING phrase won't work without the LEADING phrase [there are some compilers ignoring this when using the pseudo-text-delimiters] (highlighting again via format in bold, which is not in the spec):

      Pseudo-text-1 [...] match the library text only if the ordered sequence of text-words that forms pseudo-text-1 [...] is equal, character for character, to the ordered sequence of library text-words. When the LEADING phrase is specified, partial-word-1 matches the library text only if the contiguous sequence of characters that forms partial-word-1 is equal, character for character, to an equal number of contiguous characters starting with the leftmost character position of a library text-word. When the TRAILING phrase is specified, partial-word-1 matches the library text only if the contiguous sequence of characters that forms partial-word-1 is equal, character for character, to an equal number of contiguous characters ending with the rightmost character position of a library text-word.

      Simon

       
  • KrisDS

    KrisDS - 2015-03-05

    Aha, I hadn't seen that spaces are not considered words. I still find it confusing to see a lot of explanation in the spec (concerning REPLACING) about what are considered spaces. I guess that's just another way of saying: these things are not matched.

    I'm ignoring LEADING and TRAILING for now. I'll return to those once I get some good examples of them.

    Simon, once again, thanks for sharing your expertise !

     
    • Simon Sobisch

      Simon Sobisch - 2015-03-05

      Here is a link from g**le for you:
      http://documentation.microfocus.com/help/index.jsp?topic=%2FGUID-0E0191D8-C39A-44D1-BA4C-D67107BAF784%2FHRLHLHEXAM07.html

      BTW: To correct myself: The partial word replacement with colons IS fine for ANSI85, with strict ANSI/ISO 2002+ it shouldn't work where you don't need the :word: in the library text but need to use the LEADING phrase in the COPY statement. It's best to support both (==> replace everywhere if :stuff: is replaced, replace only LEADING/TRAILING if given, otherwise replace full text-words only). I'll have to check if GnuCOBOL is doing it that way and change it otherwise :-)

       

Log in to post a comment.