logological / gpp

GPP, a generic preprocessor
https://logological.org/gpp
GNU Lesser General Public License v3.0
192 stars 33 forks source link

Do commas need to be escaped? #35

Closed TerraTech closed 5 years ago

TerraTech commented 5 years ago

gpp-2.24

I am using gpp to handle Linux nftables config files and ran into the following issue:

```cpp #define _CORE_ #ifdef _CORE_ #define CORE(x) x #else #define CORE(x) #endif CORE(foo0 { bar0, baz0 }) CORE(foo1 { bar1\, baz1 }) ``` This will output: ```sh $ gpp test.nft foo0 { bar0 foo1 { bar1, baz1 } ``` Is this expected behavior? It caught me by surprise when I started adding direct nftable sets for some rules and ```nft``` would throw a syntax error. Prior to today, I had been using ```define``` sets which worked fine. e.g. ```cpp ... define setFoo = { bar, baz } CORE(foo { $setFoo }) ``` emits: ```sh foo { bar, baz } ``` so it seems the ```comma``` is being handled special. Thank you for taking a look.
logological commented 5 years ago

Recall that in GPP's default mode, the character , is the argument separator. In your first example, you define CORE to take one argument. When you write CORE(foo0 { bar0, baz0 }), you are calling CORE with two arguments, foo0 { bar0 and baz0 }. Since CORE takes only one argument, the second argument is simply gobbled. When you write CORE(foo1 { bar1\, baz1 }), you quote (i.e., escape) the comma so that GPP does not interpret it as an argument separator. CORE therefore sees the single argument foo1 { bar1\, baz1 }.

Does this answer your question?

TerraTech commented 5 years ago

Thank you for the clarification, much appreciated.

logological commented 5 years ago

Glad to help! If you don't want the comma to be the argument separator, you can always use a different mode, or define your own custom mode that uses a different character (or none at all) as the argument separator. Check out the man page for the appropriate command-line arguments.