Skip to content

Commit 92f7b05

Browse files
authored
Merge pull request #203 from SeeSharpSoft/master
Release 2.11.0
2 parents 262f6d8 + c438a1f commit 92f7b05

31 files changed

+763
-154
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: java
22
jdk:
3-
- openjdk8
3+
- openjdk9
44

55
env:
66
- IDEA_VERSION=PC-2019.3.3 GRAMMAR_KIT_VERSION=2019.3

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.11.0
2+
May 8, 2020
3+
4+
NEW: Adding custom separator #177
5+
16
2.10.0
27
Apr 19, 2020
38

README.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ This enables default editor features like syntax validation, highlighting and in
2626
- quick fix inspections
2727
- intentions (Alt+Enter), e.g. Quote/Unquote (all), Shift Column Left/Right
2828
- structure view (header-entry layout)
29-
- support for ',', ';', '|' and '↹' as value separator
29+
- support for ',', ';', ':', '|' and '↹' as pre-defined value separator
30+
- support for freely defined value separators
3031
- highlight of active column values
3132
- tab (↹) separator highlighting
3233

@@ -59,13 +60,16 @@ Please note that if a document is syntactically incorrect, other features like c
5960
CSV files provide a high degree of flexibility and can be used universally for all kind of data.
6061
This led to a variety of CSV derivatives like semicolon or pipe separated values, which share the common format but make use of a different separator.
6162

62-
The plugin supports project specific separator setting.
63-
New separators can be added fairly easy in the parser definition of the source code.
63+
The plugin supports file-specific separator settings.
64+
Predefined separators, like Comma (,), semicolon (;), colon (:), tab (↹) and pipe (|), come with a precompiled lexer providing the best performance for working with CSV.
65+
66+
Since version 2.11.0, this plugin additionally comes with a runtime lexer implementation to support freely chosen separator.
6467

6568
#### TSV/PSV
6669

67-
Comma (,), semicolon (;), tab (↹) and pipe (|) can be explicitly set as a separator for CSV files.
68-
Additionally the file types TSV (Tab-Separated-Values) and PSV (Pipe-Separated-Values) were introduced as a kind of CSV language.
70+
A different separator can be chosen for each CSV file.
71+
72+
Additionally, the file types TSV (Tab-Separated-Values) and PSV (Pipe-Separated-Values) were introduced as a kind of CSV language.
6973
For TSV and PSV files the same formatter and code style settings are applied as for CSV itself, but the separator is considered to be a tab or a pipe respectively.
7074
All functionality that is available for plain CSV files (inspections, intentions, structure view, etc.) can be used for TSV and PSV as well.
7175

@@ -126,7 +130,7 @@ Enable zero-based column numbering. This affects the tooltip info of the text ed
126130

127131
##### Default Value Separator (CSV only)
128132

129-
The following separators are currently supported: **,** (Comma), **;** (Semicolon), **|** (Pipe) and **↹** (Tab)
133+
The following separators are currently supported: **,** (Comma), **;** (Semicolon), **:** (Colon), **|** (Pipe) and **↹** (Tab)
130134

131135
_Default Value Separator_ defines which separator is used as standard for each newly opened CSV file. The separator character can be changed for each file individually in its editors context menu.
132136

@@ -326,9 +330,10 @@ Annasusanna,Amsterdam, 1
326330
![Context menu](./docs/contextmenu.png)
327331

328332
The action to switch the value separator (or escape character) - *which is used for CSV syntax validation of a specific file* - is part of its editors context menu.
333+
Since version 2.11.0, also custom separator setting is available via this action.
329334

330335

331-
This action defines how the parser/validator/highlighter/etc. behaves. It does intentionally not change the file content.
336+
**Please note:** This action defines how the parser/validator/highlighter/etc. behaves. It does intentionally not change the file content.
332337
To be more precise: It **does not replace** previous separator/escape characters by new ones or adjust the escaped texts.
333338

334339
#### Adjust column widths (table editor only)
@@ -395,15 +400,6 @@ Besides source code contributions, feel free to open bug reports or just suggest
395400

396401
- zoom table-editor cells with Ctrl+Mouse Wheel @royqh1979
397402

398-
## FAQ
399-
400-
> Why can't I choose the separator freely?
401-
402-
Having clearly defined symbols enables the syntax parser and language lexer to do its job properly.
403-
The code for those is generated during build time by using the [Grammar-Kit](https://github.com/JetBrains/Grammar-Kit).
404-
Adding a new kind of separator during development is fairly easy (please feel free to request a new commonly used one) in comparison to the implementation effort and usefulness of a freely defined separator.
405-
406-
407403
## Jetbrains Repository
408404

409405
JetBrains Plugin Repository Link: https://plugins.jetbrains.com/plugin/10037-csv-plugin

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jacocoTestReport {
2424
}
2525

2626
group 'net.seesharpsoft.intellij.plugins'
27-
version '2.10.0'
27+
version '2.11.0'
2828

2929
apply plugin: 'java'
3030
sourceCompatibility = javaVersion
@@ -34,6 +34,7 @@ repositories {
3434
mavenCentral()
3535
}
3636
dependencies {
37+
implementation 'net.seesharpsoft.sharping:sharping-commons:0.21.0'
3738
compileOnly 'org.apache.ant:ant:1.7.0'
3839
testCompile 'org.mockito:mockito-core:2.28.2'
3940
}

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# https://www.jetbrains.com/intellij-repository/snapshots
44

55
name='CSV Plugin'
6-
javaVersion=8
7-
javaTargetVersion=8
6+
javaVersion=9
7+
javaTargetVersion=9

src/main/java/net/seesharpsoft/intellij/plugins/csv/Csv.bnf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
tokenTypeClass="net.seesharpsoft.intellij.plugins.csv.psi.CsvTokenType"
1414

1515
tokens=[
16-
TEXT='regexp:[^ ,;|\t\r\n"\\]+'
17-
ESCAPED_TEXT='regexp:[,;|\t\r\n]|""|\\"'
16+
TEXT='regexp:[^ ,:;|\t\r\n"\\]+'
17+
ESCAPED_TEXT='regexp:[,:;|\t\r\n]|""|\\"'
1818
ESCAPE_CHARACTER='regexp:\\'
19-
COMMA='regexp:[,;|\t]'
20-
QUOTE='"'
19+
COMMA='regexp:[,:;|\t]'
20+
QUOTE='regexp:"'
2121
CRLF='regexp:\n'
2222
]
2323
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvHelper.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.seesharpsoft.intellij.plugins.csv;
22

33
import com.intellij.ide.scratch.ScratchFileType;
4+
import com.intellij.ide.scratch.ScratchUtil;
45
import com.intellij.lang.*;
56
import com.intellij.lexer.Lexer;
67
import com.intellij.openapi.fileTypes.FileType;
@@ -22,6 +23,7 @@
2223
import net.seesharpsoft.intellij.plugins.csv.psi.CsvFile;
2324
import net.seesharpsoft.intellij.plugins.csv.psi.CsvRecord;
2425
import net.seesharpsoft.intellij.plugins.csv.psi.CsvTypes;
26+
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
2527
import org.jetbrains.annotations.NotNull;
2628

2729
import java.util.HashMap;
@@ -50,7 +52,7 @@ public static PsiElement createEmptyCsvField(PsiFile psiFile) {
5052
public static boolean isCsvFile(Project project, VirtualFile file) {
5153
final FileType fileType = file.getFileType();
5254
return (fileType instanceof LanguageFileType && ((LanguageFileType) fileType).getLanguage().isKindOf(CsvLanguage.INSTANCE)) ||
53-
(fileType == ScratchFileType.INSTANCE && LanguageUtil.getLanguageForPsi(project, file).isKindOf(CsvLanguage.INSTANCE));
55+
(ScratchUtil.isScratch(file) && LanguageUtil.getLanguageForPsi(project, file).isKindOf(CsvLanguage.INSTANCE));
5456
}
5557

5658
public static IElementType getElementType(PsiElement element) {
@@ -158,32 +160,36 @@ public static Project getProject(PsiFile psiFile) {
158160
return psiFile == null ? null : psiFile.getProject();
159161
}
160162

161-
public static CsvValueSeparator getValueSeparator(CsvFile csvFile) {
163+
public static @NotNull CsvValueSeparator getValueSeparator(CsvFile csvFile) {
162164
return getValueSeparator(csvFile.getContainingFile());
163165
}
164166

165-
public static CsvValueSeparator getValueSeparator(PsiFile psiFile) {
167+
public static @NotNull CsvValueSeparator getValueSeparator(PsiFile psiFile) {
166168
return getValueSeparator(getProject(psiFile), getVirtualFile(psiFile));
167169
}
168170

169-
public static CsvValueSeparator getValueSeparator(Project project, VirtualFile virtualFile) {
170-
return CsvFileAttributes.getInstance(project).getValueSeparator(project, virtualFile);
171+
public static @NotNull CsvValueSeparator getValueSeparator(Project project, VirtualFile virtualFile) {
172+
return project == null ?
173+
CsvEditorSettings.getInstance().getDefaultValueSeparator() :
174+
CsvFileAttributes.getInstance(project).getValueSeparator(project, virtualFile);
171175
}
172176

173177
public static boolean hasValueSeparatorAttribute(@NotNull PsiFile psiFile) {
174178
return CsvFileAttributes.getInstance(getProject(psiFile)).hasValueSeparatorAttribute(getProject(psiFile), getVirtualFile(psiFile));
175179
}
176180

177-
public static CsvEscapeCharacter getEscapeCharacter(CsvFile csvFile) {
181+
public static @NotNull CsvEscapeCharacter getEscapeCharacter(CsvFile csvFile) {
178182
return getEscapeCharacter(csvFile.getContainingFile());
179183
}
180184

181-
public static CsvEscapeCharacter getEscapeCharacter(PsiFile psiFile) {
185+
public static @NotNull CsvEscapeCharacter getEscapeCharacter(PsiFile psiFile) {
182186
return getEscapeCharacter(getProject(psiFile), getVirtualFile(psiFile));
183187
}
184188

185-
public static CsvEscapeCharacter getEscapeCharacter(Project project, VirtualFile virtualFile) {
186-
return CsvFileAttributes.getInstance(project).getEscapeCharacter(project, virtualFile);
189+
public static @NotNull CsvEscapeCharacter getEscapeCharacter(Project project, VirtualFile virtualFile) {
190+
return project == null ?
191+
CsvEditorSettings.getInstance().getDefaultEscapeCharacter() :
192+
CsvFileAttributes.getInstance(project).getEscapeCharacter(project, virtualFile);
187193
}
188194

189195
public static boolean hasEscapeCharacterAttribute(@NotNull PsiFile psiFile) {

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvLexer.flex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ import java.util.regex.Pattern;
3232
%eof{ return;
3333
%eof}
3434

35-
TEXT=[^ ,;|\t\r\n\"\\]+
36-
ESCAPED_TEXT=[,;|\t\r\n]|\"\"|\\\"
35+
TEXT=[^ ,:;|\t\r\n\"\\]+
36+
ESCAPED_TEXT=[,:;|\t\r\n]|\"\"|\\\"
3737
ESCAPE_CHAR=\\
3838
QUOTE=\"
39-
COMMA=[,;|\t]
39+
COMMA=[,:;|\t]
4040
EOL=\n
4141
WHITE_SPACE=[ \f]+
4242

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package net.seesharpsoft.intellij.plugins.csv;
2+
3+
import com.intellij.lexer.Lexer;
4+
import com.intellij.openapi.project.Project;
5+
import com.intellij.openapi.vfs.VirtualFile;
6+
import com.intellij.psi.PsiFile;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
public class CsvLexerFactory {
10+
protected static CsvLexerFactory INSTANCE = new CsvLexerFactory();
11+
12+
public static CsvLexerFactory getInstance() {
13+
return INSTANCE;
14+
}
15+
16+
protected Lexer createLexer(@NotNull CsvValueSeparator separator, @NotNull CsvEscapeCharacter escapeCharacter) {
17+
if (separator.isCustom()) {
18+
return new CsvSharpLexer(new CsvSharpLexer.Configuration(
19+
separator.getCharacter(),
20+
"\n",
21+
escapeCharacter.getCharacter(),
22+
"\""));
23+
}
24+
return new CsvLexerAdapter(separator, escapeCharacter);
25+
}
26+
27+
public Lexer createLexer(Project project, VirtualFile file) {
28+
return createLexer(CsvHelper.getValueSeparator(project, file), CsvHelper.getEscapeCharacter(project, file));
29+
}
30+
31+
public Lexer createLexer(@NotNull PsiFile file) {
32+
return createLexer(CsvHelper.getValueSeparator(file), CsvHelper.getEscapeCharacter(file));
33+
}
34+
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvParserDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public PsiElement createElement(ASTNode node) {
7575

7676
@Override
7777
public Lexer createLexer(@NotNull PsiFile file) {
78-
return new CsvLexerAdapter(CsvHelper.getValueSeparator(file), CsvHelper.getEscapeCharacter(file));
78+
return CsvLexerFactory.getInstance().createLexer(file);
7979
}
8080

8181
@Override

0 commit comments

Comments
 (0)