Skip to content

The documentation for directive define is incorrect. #55

@paxcut

Description

@paxcut

In the pattern language docs under the preprocessor we find this sentence in the entry for #define:

In the example above, the label MY_CONSTANT will be replaced with 1337 throughout the entire program without doing any sort of lexical analysis. This means the directive will be replaced even within strings.

I think this was written when the preprocessor did a text find replace and when the lexer was applied after the preprcessor. Currently the lexer is applied first and the preprocessor uses the tokens created to implement all the preprocessor directives In particular, the find replace done by the define directive is done on a token basis using the tokens obtained from the lexer so it does use lexical analysis. Specifically, only identifier tokens are processed during the application of the define directive and strings are not identifier tokens so nothing inside strings, comments or any other type of token is currently changed by the define directive.
You can safely do #define a 1 without worrying that every a character in the file will be changed to a 1. Only variables using a as their identifier will be changed. so a variable called aaa will not be changed to 111 either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions