1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 463723 - GCC output parser cannot parse macro with a combination of

quotes and escapes

Change-Id: I7b07d3e2cc706f5e7839189bd2968f69c5cad28c
This commit is contained in:
Marc-Andre Laperle 2015-04-01 15:35:17 -04:00
parent 0ee5ad92f1
commit e6a4fe47b3
3 changed files with 17 additions and 1 deletions

View file

@ -682,6 +682,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
+ " -D'MACRO5=\"quoted value\"'"
+ " -DMACRO6=\\\"escape-quoted value\\\""
+ " -DMACRO7=\"'single-quoted value'\""
+ " -DMACRO8=\"\\\"escape-quoted value\\\"\""
+ " file.cpp");
parser.shutdown();
@ -702,6 +703,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase {
assertEquals(new CMacroEntry("MACRO5", "\"quoted value\"", 0), entries.get(5));
assertEquals(new CMacroEntry("MACRO6", "\"escape-quoted value\"", 0), entries.get(6));
assertEquals(new CMacroEntry("MACRO7", "'single-quoted value'", 0), entries.get(7));
assertEquals(new CMacroEntry("MACRO8", "\"escape-quoted value\"", 0), entries.get(8));
}
/**

View file

@ -49,7 +49,20 @@ public abstract class AbstractBuildCommandParser extends AbstractLanguageSetting
private static final String LEADING_PATH_PATTERN = "\\S+[/\\\\]"; //$NON-NLS-1$
private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"']*(\\s*((\".*?\")|('.*?')|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$
/**
* "foo"
* Using look-ahead and look-behind to resolve ambiguity with "\" {@link #QUOTE_BSLASH_QUOTE}
*/
private static final String QUOTE = "(\"(?!\\\\).*?(?<!\\\\)\")"; //$NON-NLS-1$
/** \"foo\" */
private static final String BSLASH_QUOTE = "(\\\\\".*?\\\\\")"; //$NON-NLS-1$
/** 'foo' */
private static final String SINGLE_QUOTE = "('.*?')"; //$NON-NLS-1$
/** "\"foo\"" */
private static final String QUOTE_BSLASH_QUOTE = "(\"\\\\\".*?\\\\\"\")"; //$NON-NLS-1$
private static final Pattern OPTIONS_PATTERN = Pattern.compile("-[^\\s\"'\\\\]*(\\s*(" + QUOTE +"|" + QUOTE_BSLASH_QUOTE + "|" + BSLASH_QUOTE + "|" + SINGLE_QUOTE + "|([^-\\s][^\\s]+)))?"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$<
private static final int OPTION_GROUP = 0;
public enum ResourceScope {

View file

@ -40,6 +40,7 @@ public class GCCBuildCommandParser extends AbstractBuildCommandParser implements
new IncludeFileOptionParser("-include\\s*([\"'])(.*)\\1", "$2"),
new IncludeFileOptionParser("-include\\s*([^\\s\"']*)", "$1"),
new MacroOptionParser("-D\\s*([\"'])([^=]*)(=(.*))?\\1", "$2", "$4"),
new MacroOptionParser("-D\\s*([^\\s=\"']*)=(\"\\\\(\")(.*?)\\\\\"\")", "$1", "$3$4$3"),
new MacroOptionParser("-D\\s*([^\\s=\"']*)=(\\\\([\"']))(.*?)\\2", "$1", "$3$4$3"),
new MacroOptionParser("-D\\s*([^\\s=\"']*)=([\"'])(.*?)\\2", "$1", "$3"),
new MacroOptionParser("-D\\s*([^\\s=\"']*)(=([^\\s\"']*))?", "$1", "$3"),