Skip to content

Commit

Permalink
Make regexes for scanning include/import statements consistent (#426)
Browse files Browse the repository at this point in the history
For res-scanner, add `^[ \t]*` before and `[ \t]*` after the `include`
word. This matches what was done in 13b8a68 for c-scanner and
objc-scanner. Also use `sequence.transform path.native` for the `angle`
and `quoted` results, similar to cpp-scanner.

For cpp-scanner, use `[^<]+` to match characters for angled includes,
and `[^\"]+` for quoted includes, similar to what was done in
res-scanner. This ensures strings like `#include <foo> bar>` will not
match.

For objc-scanner, idem as for cpp-scanner.
  • Loading branch information
dimitry-unified-streaming authored Nov 19, 2024
1 parent a463914 commit 7954ee6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/tools/rc.jam
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class res-scanner : scanner
import path ;
import regex ;
import scanner ;
import sequence ;
import toolset ;
import virtual-target ;

Expand All @@ -108,13 +109,15 @@ class res-scanner : scanner

rule pattern ( )
{
return "(([^ ]+[ ]+(BITMAP|CURSOR|FONT|ICON|MESSAGETABLE|RT_MANIFEST)[ ]+([^ \"]+|\"[^\"]+\"))|(#include[ ]*(<[^<]+>|\"[^\"]+\")))" ;
return "(([^ ]+[ ]+(BITMAP|CURSOR|FONT|ICON|MESSAGETABLE|RT_MANIFEST)[ ]+([^ \"]+|\"[^\"]+\"))|(^[ \t]*#[ \t]*include[ \t]*(<[^<]+>|\"[^\"]+\")))" ;
}

rule process ( target : matches * : binding )
{
local angle = [ regex.transform $(matches) : "#include[ ]*<([^<]+)>" ] ;
local quoted = [ regex.transform $(matches) : "#include[ ]*\"([^\"]+)\"" ] ;
local angle = [ regex.transform $(matches) : "#include[ \t]*<([^<]+)>" ] ;
angle = [ sequence.transform path.native : $(angle) ] ;
local quoted = [ regex.transform $(matches) : "#include[ \t]*\"([^\"]+)\"" ] ;
quoted = [ sequence.transform path.native : $(quoted) ] ;
local res = [ regex.transform $(matches) : "[^ ]+[ ]+(BITMAP|CURSOR|FONT|ICON|MESSAGETABLE|RT_MANIFEST)[ ]+(([^ \"]+)|\"([^\"]+)\")" : 3 4 ] ;

# Icons and other includes may be referenced as
Expand Down
6 changes: 3 additions & 3 deletions src/tools/types/cpp.jam
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class c-scanner : scanner

rule pattern ( )
{
return "^[ \t]*#[ \t]*include[ \t]*(<(.+)>|\"(.+)\")" ;
return "^[ \t]*#[ \t]*include[ \t]*(<[^<]+>|\"[^\"]+\")" ;
}

rule process ( target : matches * : binding )
{
local angle = [ regex.transform $(matches) : "<(.*)>" ] ;
local angle = [ regex.transform $(matches) : "<([^<]+)>" ] ;
angle = [ sequence.transform path.native : $(angle) ] ;
local quoted = [ regex.transform $(matches) : "\"(.*)\"" ] ;
local quoted = [ regex.transform $(matches) : "\"([^\"]+)\"" ] ;
quoted = [ sequence.transform path.native : $(quoted) ] ;

# CONSIDER: the new scoping rules seem to defeat "on target" variables.
Expand Down
2 changes: 1 addition & 1 deletion src/tools/types/objc.jam
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class objc-scanner : c-scanner

rule pattern ( )
{
return "^[ \t]*#[ \t]*include|import[ ]*(<(.+)>|\"(.+)\")" ;
return "^[ \t]*#[ \t]*(include|import)[ \t]*(<[^<]+>|\"[^\"]+\")" ;
}
}

Expand Down

0 comments on commit 7954ee6

Please sign in to comment.