This is a script called m5.awk that I randomly found after reading a paper about it on the ACM website. The paper’s worth reading too but the script is just a piece of work. Commented to the brim, clean, and most importantly, useful as hell. it could be a replacement for m4. It allows you to embed AWK in text files, and besides that, it allows you to use several preprocessng features that it offers via macros. Give it a try.

  • key@lemmy.keychat.org
    link
    fedilink
    English
    arrow-up
    14
    ·
    7 months ago

    This is a strong example for the distinction between abundant comments and good documentation. Comments should describe why and how, not what. Comments on every single line stating what the line is doing is rarely a good sign. Despite all the comments, it’s not super clear what it actually does from a user perspective and why someone would want to use it. I assume it’s meant to be a templating system for text documents.

    • ChubakPDP11+TakeWithGrainOfSalt@programming.devOP
      link
      fedilink
      arrow-up
      3
      arrow-down
      6
      ·
      7 months ago

      I forgot to mention, tools like Bison and Autoconf use m4. Andrew Appel calls languages that need preprocessing ‘weak’. The specs for D also call C ‘weak’ for needing to be preprocessed. Preprocessing is almost an abandoned practice, at least in the world of programming, because Scheme-like ‘hygenic macros’ have taken their place. Some languages like Rust and Zig are attempting to reinvent the wheel by re-inventing macros, but Scheme had it right in the 70s. Truly, C and Pascal’s preprocessor were out the door in the 70s, let alone, now.

      Here’s another preprocessor that is 'neat: GPP.

      I have made my own preprocessor, it’s very nasty and has a lot of bugs because I was an idiot when I made it: https://github.com/Chubek/Ekipp

      I have half a mind to remake Ekipp. I don’t know what purpose would it serve. But it’s just neat, I think preprocessors are neat, as useless as they are.

    • ChubakPDP11+TakeWithGrainOfSalt@programming.devOP
      link
      fedilink
      arrow-up
      1
      arrow-down
      6
      ·
      7 months ago

      It does not really need to explain what it ‘is’ because

      1- a paper has been released on ACM explaining it, you can download it for free from here: https://dl.acm.org/doi/pdf/10.1145/353474.353484

      2- It’s name is m5, most people in the UNIX world know what m4 is. If you have Linux, bring up info m4.

      Imagine this, when you use C, there is a preprocessor that does all the #include and #defines, m4 is like that and m5 is like that too. Preprocessing used to be big, but now it’s not. If you wanna see an example of preprocessing, look at this preprocessor I made for C: https://gist.github.com/Chubek/b2846855e5bb71a67c7e3effc6beefd6