Skip to content

Commit d81ec1d

Browse files
authored
Merge pull request SJrX#53 from SJrX/issue-51
Resolves SJrX#51 - Tab character not permitted to be in value
2 parents ab0d1e9 + 22c68de commit d81ec1d

3 files changed

Lines changed: 64 additions & 9 deletions

File tree

src/main/gen/net/sjrx/intellij/plugins/systemdunitfiles/generated/UnitFileLexer.java

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/resources/net/sjrx/intellij/plugins/systemdunitfiles/lexer/SystemdUnitFile.flex

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ import net.sjrx.intellij.plugins.systemdunitfiles.generated.UnitFileElementTypeH
3535
%eof}
3636
%public
3737

38-
39-
// New Line Character
38+
// New Line Character (See JFlex manual)
4039
CRLF=\R
4140

4241
// White space
@@ -60,7 +59,7 @@ INCOMPLETE_SECTION_HEADER = \[[^\]\n]*
6059
KEY_CHARACTER=[^=\ \n\t\f\\] | "\\ "
6160

6261
// First value doesn't allow spaces
63-
VALUE_CHARACTER=[^\n\t\f\\] | "\\"{CRLF} | "\\".
62+
VALUE_CHARACTER=[^\n\f\\] | "\\"{CRLF} | "\\".
6463

6564
// Comments can start with either ; or a #
6665
COMMENT=("#"|";")[^\n]*
@@ -89,7 +88,7 @@ SEPARATOR=[=]
8988

9089
<WAITING_FOR_SEPARATOR> {SAME_LINE_WHITESPACE}*{SEPARATOR}{SAME_LINE_WHITESPACE}* { yybegin(WAITING_FOR_VALUE); return UnitFileElementTypeHolder.SEPARATOR; }
9190

92-
// Pull a value character or really any character and mark it as it's value, this is really a hack :(
91+
// Pull a value character or really any character and mark it as its value, this is really a hack :(
9392
<WAITING_FOR_VALUE> ({VALUE_CHARACTER}+|[^]) { yybegin(IN_SECTION); return UnitFileElementTypeHolder.VALUE; }
9493

9594
<YYINITIAL, IN_SECTION>({CRLF}|{WHITE_SPACE})+ { return TokenType.WHITE_SPACE; }

src/test/java/net/sjrx/intellij/plugins/systemdunitfiles/parser/UnitFileParserTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,62 @@ public void testLineContinuationSimple() {
157157
assertSameLines(expectedPsiTree, parseTree);
158158
}
159159

160+
public void testLineContinuationWithTabInlineSimple() {
161+
/*
162+
* Fixture Setup
163+
*/
164+
String sourceCode = "[One]\n"
165+
+ "Key=Val\tue \\\n"
166+
+ "Hello";
167+
168+
String expectedPsiTree = "unit configuration file (systemd)(0,24)\n"
169+
+ " UnitFileSectionGroupsImpl(SECTION_GROUPS)(0,24)\n"
170+
+ " PsiElement(UnitFileTokenType{SECTION})('[One]')(0,5)\n"
171+
+ " PsiWhiteSpace('\\n')(5,6)\n"
172+
+ " UnitFilePropertyImpl(PROPERTY)(6,24)\n"
173+
+ " PsiElement(UnitFileTokenType{KEY})('Key')(6,9)\n"
174+
+ " PsiElement(UnitFileTokenType{SEPARATOR})('=')(9,10)\n"
175+
+ " PsiElement(UnitFileTokenType{VALUE})('Val\\tue \\\\nHello')(10,24)";
176+
/*
177+
* Exercise SUT
178+
*/
179+
180+
String parseTree = convertSourceToParseTree(sourceCode);
181+
182+
/*
183+
* Verification
184+
*/
185+
assertSameLines(expectedPsiTree, parseTree);
186+
}
187+
188+
public void testLineContinuationWithWhitespaceStartingNextLine() {
189+
/*
190+
* Fixture Setup
191+
*/
192+
String sourceCode = "[One]\n"
193+
+ "Key=Value \\\n"
194+
+ "\tHello";
195+
196+
String expectedPsiTree = "unit configuration file (systemd)(0,24)\n"
197+
+ " UnitFileSectionGroupsImpl(SECTION_GROUPS)(0,24)\n"
198+
+ " PsiElement(UnitFileTokenType{SECTION})('[One]')(0,5)\n"
199+
+ " PsiWhiteSpace('\\n')(5,6)\n"
200+
+ " UnitFilePropertyImpl(PROPERTY)(6,24)\n"
201+
+ " PsiElement(UnitFileTokenType{KEY})('Key')(6,9)\n"
202+
+ " PsiElement(UnitFileTokenType{SEPARATOR})('=')(9,10)\n"
203+
+ " PsiElement(UnitFileTokenType{VALUE})('Value \\\\n\\tHello')(10,24)";
204+
/*
205+
* Exercise SUT
206+
*/
207+
208+
String parseTree = convertSourceToParseTree(sourceCode);
209+
210+
/*
211+
* Verification
212+
*/
213+
assertSameLines(expectedPsiTree, parseTree);
214+
}
215+
160216

161217
public void testLineContinuationWithKeys() {
162218
/*

0 commit comments

Comments
 (0)