mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 20:35:38 +02:00
Bug 151329 - Accept '\r' as line delimiter in the lexer
Change-Id: Ie3fb2926270a605db2a8590f6e00c1dc6ab7855a Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/23096 Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
450504e505
commit
2c78dee75f
2 changed files with 27 additions and 2 deletions
|
@ -121,6 +121,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.parser.IToken;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
|
@ -7516,4 +7517,26 @@ public class AST2Tests extends AST2TestBase {
|
|||
public void testOctalFloatingPointLiteral_394048() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
public void testMacOS9LineEnding_151329a() throws Exception {
|
||||
parseAndCheckBindings("int waldo;\r#define bar");
|
||||
}
|
||||
|
||||
public void testMaxOS9LineEnding_151329b() throws Exception {
|
||||
// This tests that if there is an \r\n in a macro continuation,
|
||||
// the \r is not treated as an extra newline. The code
|
||||
// stringifies the macro expansion and arranges for the string
|
||||
// length to show up in a template parameter, whose value is
|
||||
// checked by the test.
|
||||
String code = "#define MACRO foo\\\r\n"
|
||||
+ "bar\r\n"
|
||||
+ "#define STRINGIFY_(x) #x\r\n"
|
||||
+ "#define STRINGIFY(x) STRINGIFY_(x)\r\n"
|
||||
+ "template <int N> void f(const char (&)[N]);\r\n"
|
||||
+ "int main() { f(STRINGIFY(MACRO)); }\r\n";
|
||||
BindingAssertionHelper helper = new BindingAssertionHelper(code, true);
|
||||
ICPPTemplateInstance f = helper.assertNonProblem("f(STRINGIFY", "f");
|
||||
// 7 characters for "foobar" + the null terminator.
|
||||
assertEquals(7, f.getTemplateArguments()[0].getNonTypeValue().numericalValue().longValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1052,14 +1052,16 @@ final public class Lexer implements ITokenSequence {
|
|||
fEndOffset= ++pos;
|
||||
fCharPhase3= c;
|
||||
switch (c) {
|
||||
// windows line-ending
|
||||
case '\r':
|
||||
// windows line-ending
|
||||
if (fInput.get(pos) == '\n') {
|
||||
fEndOffset= pos+1;
|
||||
fCharPhase3= '\n';
|
||||
return '\n';
|
||||
}
|
||||
return c;
|
||||
// mac os 9 line ending
|
||||
fCharPhase3= '\n';
|
||||
return '\n';
|
||||
|
||||
// trigraph sequences
|
||||
case '?':
|
||||
|
|
Loading…
Add table
Reference in a new issue