-
Notifications
You must be signed in to change notification settings - Fork 43
/
CsvLexerFactory.java
36 lines (30 loc) · 1.42 KB
/
CsvLexerFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package net.seesharpsoft.intellij.plugins.csv;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
import org.jetbrains.annotations.NotNull;
public class CsvLexerFactory {
protected static CsvLexerFactory INSTANCE = new CsvLexerFactory();
public static CsvLexerFactory getInstance() {
return INSTANCE;
}
protected Lexer createLexer(@NotNull CsvValueSeparator separator, @NotNull CsvEscapeCharacter escapeCharacter) {
if (separator.isCustom() || !CsvEditorSettings.getInstance().getCommentIndicator().isEmpty()) {
return new CsvSharpLexer(new CsvSharpLexer.Configuration(
separator.getCharacter(),
"\n",
escapeCharacter.getCharacter(),
"\"",
CsvEditorSettings.getInstance().getCommentIndicator()));
}
return new CsvLexerAdapter(separator, escapeCharacter);
}
public Lexer createLexer(Project project, VirtualFile file) {
return createLexer(CsvHelper.getValueSeparator(project, file), CsvHelper.getEscapeCharacter(project, file));
}
public Lexer createLexer(@NotNull PsiFile file) {
return createLexer(CsvHelper.getValueSeparator(file), CsvHelper.getEscapeCharacter(file));
}
}