From 7954ee6e55e9b5a3b89245470b21eca9a489843a Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Tue, 19 Nov 2024 23:53:58 +0100 Subject: [PATCH] Make regexes for scanning include/import statements consistent (#426) 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 bar>` will not match. For objc-scanner, idem as for cpp-scanner. --- src/tools/rc.jam | 9 ++++++--- src/tools/types/cpp.jam | 6 +++--- src/tools/types/objc.jam | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/tools/rc.jam b/src/tools/rc.jam index ef4ef6e859..70fabd4536 100644 --- a/src/tools/rc.jam +++ b/src/tools/rc.jam @@ -93,6 +93,7 @@ class res-scanner : scanner import path ; import regex ; import scanner ; + import sequence ; import toolset ; import virtual-target ; @@ -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 diff --git a/src/tools/types/cpp.jam b/src/tools/types/cpp.jam index c2ab01fdf7..af8bf2b09f 100644 --- a/src/tools/types/cpp.jam +++ b/src/tools/types/cpp.jam @@ -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. diff --git a/src/tools/types/objc.jam b/src/tools/types/objc.jam index 7d6ce0cbf3..81a58abd81 100644 --- a/src/tools/types/objc.jam +++ b/src/tools/types/objc.jam @@ -14,7 +14,7 @@ class objc-scanner : c-scanner rule pattern ( ) { - return "^[ \t]*#[ \t]*include|import[ ]*(<(.+)>|\"(.+)\")" ; + return "^[ \t]*#[ \t]*(include|import)[ \t]*(<[^<]+>|\"[^\"]+\")" ; } }