-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0eaeaaa
commit 876b99d
Showing
6 changed files
with
393 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
sonar-objective-c-plugin/src/main/java/org/sonar/objectivec/lexer/BackslashChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* SonarQube Objective-C (Community) Plugin | ||
* Copyright (C) 2012-2016 OCTO Technology, Backelite, and contributors | ||
* mailto:[email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.objectivec.lexer; | ||
|
||
import com.sonar.sslr.impl.Lexer; | ||
import org.sonar.sslr.channel.Channel; | ||
import org.sonar.sslr.channel.CodeReader; | ||
|
||
/** | ||
* @author Sonar C++ Plugin (Community) authors | ||
*/ | ||
public class BackslashChannel extends Channel<Lexer> { | ||
@Override | ||
public boolean consume(CodeReader code, Lexer output) { | ||
char ch = (char) code.peek(); | ||
|
||
if ((ch == '\\') && isNewLine(code.charAt(1))) { | ||
// just throw away the backslash | ||
code.pop(); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static boolean isNewLine(char ch) { | ||
return (ch == '\n') || (ch == '\r'); | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
...objective-c-plugin/src/main/java/org/sonar/objectivec/lexer/CharacterLiteralsChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* SonarQube Objective-C (Community) Plugin | ||
* Copyright (C) 2012-2016 OCTO Technology, Backelite, and contributors | ||
* mailto:[email protected] | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.objectivec.lexer; | ||
|
||
import com.sonar.sslr.api.Token; | ||
import com.sonar.sslr.impl.Lexer; | ||
import org.sonar.objectivec.api.ObjectiveCTokenType; | ||
import org.sonar.sslr.channel.Channel; | ||
import org.sonar.sslr.channel.CodeReader; | ||
|
||
/** | ||
* @author Sonar C++ Plugin (Community) authors | ||
*/ | ||
public class CharacterLiteralsChannel extends Channel<Lexer> { | ||
private static final char EOF = (char) -1; | ||
|
||
private final StringBuilder sb = new StringBuilder(); | ||
|
||
private int index; | ||
private char ch; | ||
|
||
@Override | ||
public boolean consume(CodeReader code, Lexer output) { | ||
int line = code.getLinePosition(); | ||
int column = code.getColumnPosition(); | ||
index = 0; | ||
readPrefix(code); | ||
if ((ch != '\'')) { | ||
return false; | ||
} | ||
if (!read(code)) { | ||
return false; | ||
} | ||
readUdSuffix(code); | ||
for (int i = 0; i < index; i++) { | ||
sb.append((char) code.pop()); | ||
} | ||
output.addToken(Token.builder() | ||
.setLine(line) | ||
.setColumn(column) | ||
.setURI(output.getURI()) | ||
.setValueAndOriginalValue(sb.toString()) | ||
.setType(ObjectiveCTokenType.CHARACTER_LITERAL) | ||
.build()); | ||
sb.setLength(0); | ||
return true; | ||
} | ||
|
||
private boolean read(CodeReader code) { | ||
index++; | ||
while (code.charAt(index) != ch) { | ||
if (code.charAt(index) == EOF) { | ||
return false; | ||
} | ||
if (code.charAt(index) == '\\') { | ||
// escape | ||
index++; | ||
} | ||
index++; | ||
} | ||
index++; | ||
return true; | ||
} | ||
|
||
private void readPrefix(CodeReader code) { | ||
ch = code.charAt(index); | ||
if ((ch == 'u') || (ch == 'U') || ch == 'L') { | ||
index++; | ||
ch = code.charAt(index); | ||
} | ||
} | ||
|
||
private void readUdSuffix(CodeReader code) { | ||
for (int start_index = index, len = 0; ; index++) { | ||
char c = code.charAt(index); | ||
if (c == EOF) { | ||
return; | ||
} | ||
if ((c >= 'a' && c <= 'z') | ||
|| (c >= 'A' && c <= 'Z') | ||
|| (c == '_')) { | ||
len++; | ||
} else { | ||
if (c >= '0' && c <= '9') { | ||
if (len > 0) { | ||
len++; | ||
} else { | ||
index = start_index; | ||
return; | ||
} | ||
} else { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.