Skip to content

Commit

Permalink
Preprocess: basic support for #undef (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentlb authored Mar 27, 2023
1 parent 3bea2f3 commit 8a69877
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/preprocessor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type private Impl() =

let parseEndLine = manyCharsTill anyChar (followedBy newline) .>> newline

// TODO: ignore the defines when status is Inactive
// TODO: mark defines as unknown when status is Unknown

let parseDefine = parse {
let! _ = keyword "define"
let! name = parseIdent
Expand All @@ -47,6 +50,13 @@ type private Impl() =
return sprintf "#define %s%s" name line
}

let parseUndef = parse {
let! _ = keyword "undef"
let! name = parseIdent
defines.Remove(name) |> ignore<bool>
return sprintf "#undef %s" name
}

let parseIfdef = parse {
let! word = keyword "ifdef" <|> keyword "ifndef"
let! ident = parseIdent
Expand Down Expand Up @@ -125,6 +135,8 @@ type private Impl() =
parseIf
parseIfdef
parseNope
parseUndef

parseOther
]

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/preprocess.frag
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ int this_is_removed;
void keep_else() {}
#endif

#undef DEF
#ifdef DEF
int removed_undefd() {}
#endif

void end() {}
3 changes: 3 additions & 0 deletions tests/unit/preprocess.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ void keep_outernest()
{}
void keep_else()
{}

#undef DEF

void end()
{}

0 comments on commit 8a69877

Please sign in to comment.