From 707aedfddf6b29e4a86b241a62d971acd9044255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Kr=C3=A1sa?= Date: Thu, 14 Jan 2021 18:28:21 +0100 Subject: [PATCH] grammar fix --- gen/org/plantuml/idea/grammar/PumlLexer.java | 105 ++++++++---------- src/org/plantuml/idea/grammar/_PumlLexer.flex | 4 +- testData/ParsingTestData.puml | 6 +- testData/ParsingTestData.txt | 51 ++++++++- 4 files changed, 104 insertions(+), 62 deletions(-) diff --git a/gen/org/plantuml/idea/grammar/PumlLexer.java b/gen/org/plantuml/idea/grammar/PumlLexer.java index 619967ad..ffb0dc04 100644 --- a/gen/org/plantuml/idea/grammar/PumlLexer.java +++ b/gen/org/plantuml/idea/grammar/PumlLexer.java @@ -29,7 +29,7 @@ public class PumlLexer implements FlexLexer { /** * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l - * at the beginning of a line + * at the beginning of a line * l is of the form l = 2*k, k a non negative integer */ private static final int ZZ_LEXSTATE[] = { @@ -66,11 +66,11 @@ public static int ZZ_CMAP(int ch) { private static final String ZZ_ACTION_PACKED_0 = "\3\0\1\1\1\2\1\1\1\3\5\1\1\4\1\5" + - "\1\6\1\3\1\0\1\7\1\3\1\6\1\3\6\0" + - "\1\5\1\10\1\0\1\7"; + "\1\6\1\3\1\0\1\7\1\3\1\6\1\3\5\0" + + "\1\5\1\0\1\4\1\7"; private static int[] zzUnpackAction() { - int[] result = new int[31]; + int[] result = new int[30]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; @@ -95,13 +95,13 @@ private static int zzUnpackAction(String packed, int offset, int[] result) { private static final int[] ZZ_ROWMAP = zzUnpackRowMap(); private static final String ZZ_ROWMAP_PACKED_0 = - "\0\0\0\23\0\46\0\71\0\46\0\114\0\137\0\162" + - "\0\205\0\230\0\253\0\276\0\321\0\344\0\367\0\u010a" + - "\0\u011d\0\u0130\0\u0143\0\u0156\0\u0169\0\u017c\0\u018f\0\u01a2" + - "\0\u01b5\0\u01c8\0\321\0\u01db\0\46\0\u01ee\0\46"; + "\0\0\0\23\0\46\0\71\0\46\0\46\0\114\0\137" + + "\0\162\0\205\0\230\0\253\0\276\0\321\0\344\0\367" + + "\0\u010a\0\u011d\0\u0130\0\u0143\0\u0156\0\u0169\0\u017c\0\u018f" + + "\0\u01a2\0\276\0\u01b5\0\u01c8\0\46\0\46"; private static int[] zzUnpackRowMap() { - int[] result = new int[31]; + int[] result = new int[30]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; @@ -129,26 +129,25 @@ private static int zzUnpackRowMap(String packed, int offset, int[] result) { "\1\17\1\20\1\4\1\21\1\22\1\23\1\10\1\11" + "\1\4\1\12\2\4\1\13\1\14\1\4\1\15\1\16" + "\1\15\1\23\1\24\1\25\23\0\1\4\5\0\1\4" + - "\1\0\2\4\1\0\2\4\1\0\1\4\4\0\2\26" + - "\2\0\17\26\3\0\1\7\14\0\1\7\1\0\1\7" + - "\2\0\1\27\20\0\3\30\1\0\2\30\1\0\14\30" + - "\3\31\1\0\4\31\2\0\11\31\3\32\1\0\6\32" + - "\1\0\10\32\1\4\5\0\1\4\1\0\2\4\1\0" + - "\2\14\1\15\1\4\1\15\16\0\2\33\1\15\1\0" + - "\1\15\3\0\1\4\5\0\1\4\1\0\2\4\1\0" + - "\2\4\1\0\1\4\1\34\24\0\2\17\3\0\1\7" + - "\14\0\1\7\1\17\1\20\1\0\1\21\1\22\1\21" + - "\14\0\3\21\3\22\1\0\17\22\1\0\1\21\1\22" + - "\1\23\14\0\1\23\1\21\1\23\1\0\1\21\1\22" + - "\1\21\14\0\1\21\2\24\1\0\1\21\1\22\1\23" + - "\14\0\1\23\1\24\1\25\2\26\1\35\1\0\17\26" + - "\2\27\1\36\1\27\1\0\16\27\3\30\1\0\2\30" + - "\1\35\14\30\3\31\1\0\4\31\1\0\1\35\11\31" + - "\3\32\1\0\6\32\1\35\10\32\17\0\1\34\7\0" + - "\1\37\16\0"; + "\1\0\2\4\1\0\2\4\1\0\1\4\7\0\1\7" + + "\14\0\1\7\1\0\1\7\2\0\1\26\20\0\3\27" + + "\1\0\2\27\1\0\14\27\3\30\1\0\4\30\2\0" + + "\11\30\3\31\1\0\6\31\1\0\10\31\1\4\5\0" + + "\1\4\1\0\2\4\1\0\2\14\1\15\1\4\1\15" + + "\16\0\2\32\1\15\1\0\1\15\3\0\1\4\5\0" + + "\1\4\1\0\2\4\1\0\2\4\1\0\1\4\1\33" + + "\24\0\2\17\3\0\1\7\14\0\1\7\1\17\1\20" + + "\1\0\1\21\1\22\1\21\14\0\3\21\3\22\1\0" + + "\17\22\1\0\1\21\1\22\1\23\14\0\1\23\1\21" + + "\1\23\1\0\1\21\1\22\1\21\14\0\1\21\2\24" + + "\1\0\1\21\1\22\1\23\14\0\1\23\1\24\1\25" + + "\2\26\1\34\1\26\1\0\16\26\3\27\1\0\2\27" + + "\1\35\14\27\3\30\1\0\4\30\1\0\1\35\11\30" + + "\3\31\1\0\6\31\1\35\10\31\17\0\1\33\7\0" + + "\1\36\16\0"; private static int[] zzUnpackTrans() { - int[] result = new int[513]; + int[] result = new int[475]; int offset = 0; offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); return result; @@ -186,11 +185,11 @@ private static int zzUnpackTrans(String packed, int offset, int[] result) { private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute(); private static final String ZZ_ATTRIBUTE_PACKED_0 = - "\2\0\1\10\1\1\1\11\13\1\1\0\4\1\6\0" + - "\1\1\1\11\1\0\1\11"; + "\2\0\1\10\1\1\2\11\12\1\1\0\4\1\5\0" + + "\1\1\1\0\2\11"; private static int[] zzUnpackAttribute() { - int[] result = new int[31]; + int[] result = new int[30]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; @@ -260,9 +259,7 @@ private static int zzUnpackAttribute(String packed, int offset, int[] result) { */ private boolean zzAtEOF; - /** - * denotes if the user-EOF-code has already been executed - */ + /** denotes if the user-EOF-code has already been executed */ private boolean zzEOFDone; /* user code: */ @@ -274,15 +271,15 @@ private IElementType itemType() { if (org.plantuml.idea.util.Utils.containsLetters(yytext())) { return PumlTypes.IDENTIFIER; } else { - return PumlTypes.OTHER; - } + return PumlTypes.OTHER; + } } /** * Creates a new scanner * - * @param in the java.io.Reader to read input from. + * @param in the java.io.Reader to read input from. */ public PumlLexer(java.io.Reader in) { this.zzReader = in; @@ -304,7 +301,7 @@ private static char[] zzUnpackCMap(String packed) { int i = 0; /* index in packed string */ int j = 0; /* index in unpacked array */ while (i < packed.length()) { - int count = packed.charAt(i++); + int count = packed.charAt(i++); char value = packed.charAt(i++); do map[j++] = value; while (--count > 0); } @@ -408,7 +405,8 @@ private void zzScanError(int errorCode) { String message; try { message = ZZ_ERROR_MSG[errorCode]; - } catch (ArrayIndexOutOfBoundsException e) { + } + catch (ArrayIndexOutOfBoundsException e) { message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; } @@ -436,8 +434,8 @@ public void yypushback(int number) { * Resumes scanning until the next regular expression is matched, * the end of input is encountered or an I/O-Error occurs. * - * @return the next token - * @throws java.io.IOException if any I/O-Error occurs + * @return the next token + * @exception java.io.IOException if any I/O-Error occurs */ public IElementType advance() throws java.io.IOException { int zzInput; @@ -497,7 +495,7 @@ public IElementType advance() throws java.io.IOException { zzCurrentPosL += Character.charCount(zzInput); } } - int zzNext = zzTransL[zzRowMapL[zzState] + ZZ_CMAP(zzInput)]; + int zzNext = zzTransL[ zzRowMapL[zzState] + ZZ_CMAP(zzInput)]; if (zzNext == -1) break zzForAction; zzState = zzNext; @@ -505,7 +503,7 @@ public IElementType advance() throws java.io.IOException { if ((zzAttributes & 1) == 1) { zzAction = zzState; zzMarkedPosL = zzCurrentPosL; - if ((zzAttributes & 8) == 8) break zzForAction; + if ( (zzAttributes & 8) == 8) break zzForAction; } } @@ -524,55 +522,48 @@ public IElementType advance() throws java.io.IOException { return PumlTypes.OTHER; } // fall through - case 9: + case 8: break; case 2: { return TokenType.BAD_CHARACTER; } // fall through - case 10: + case 9: break; case 3: { yybegin(LINE_START_STATE); return TokenType.WHITE_SPACE; } // fall through - case 11: + case 10: break; case 4: { yybegin(YYINITIAL); return itemType(); } // fall through - case 12: + case 11: break; case 5: { yybegin(YYINITIAL); return PumlTypes.IDENTIFIER; } // fall through - case 13: + case 12: break; case 6: { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; } // fall through - case 14: + case 13: break; case 7: { yybegin(YYINITIAL); return PumlTypes.COMMENT; - } - // fall through - case 15: - break; - case 8: { - yybegin(YYINITIAL); - return itemType(); - } + } // fall through - case 16: break; + case 14: break; default: zzScanError(ZZ_NO_MATCH); } diff --git a/src/org/plantuml/idea/grammar/_PumlLexer.flex b/src/org/plantuml/idea/grammar/_PumlLexer.flex index 9ac7d46c..84a22fea 100644 --- a/src/org/plantuml/idea/grammar/_PumlLexer.flex +++ b/src/org/plantuml/idea/grammar/_PumlLexer.flex @@ -35,7 +35,7 @@ BRACKET_1=\[[^\]\r\n]+\] // [foo bar] BRACKET_2=\([^\)\r\n,]+\) //without ',' -> do not eat multiple items: (ProductOfferingPrice, ProductUsageSpec) QUOTE_1=\"[^\"\r\n]+\" // "foo bar" -QUOTE_2=\'[^\'\r\n]+\' // 'foo bar' +//QUOTE_2=\'[^\'\r\n]+\' // 'foo bar' - perhaps better without it, it breaks brackets - [x]a'[y]b' (gantt sample) COMPLEX_WORD=[A-Za-z0-9_][A-Za-z0-9._-]*[A-Za-z0-9] WORD_CHARACTER=[A-Za-z0-9] @@ -54,7 +54,7 @@ WHITE_SPACE=[\ \t\f] {BRACKET_1} { yybegin(YYINITIAL); return itemType(); } {BRACKET_2} { yybegin(YYINITIAL); return itemType(); } {QUOTE_1} { yybegin(YYINITIAL); return itemType(); } -{QUOTE_2} { yybegin(YYINITIAL); return itemType(); } +//{QUOTE_2} { yybegin(YYINITIAL); return itemType(); } {COMPLEX_WORD} { yybegin(YYINITIAL); return itemType(); } {WORD_CHARACTER}+ { yybegin(YYINITIAL); return itemType(); } {TAG} { yybegin(YYINITIAL); return PumlTypes.IDENTIFIER; } diff --git a/testData/ParsingTestData.puml b/testData/ParsingTestData.puml index 2ff65f5f..21f3ed2e 100644 --- a/testData/ParsingTestData.puml +++ b/testData/ParsingTestData.puml @@ -34,4 +34,8 @@ Max -> Bob : something else @startuml ProductOfferingPrice -- ProductUsageSpec: ForUsage > (ProductOfferingPrice, ProductUsageSpec) .. ProductUsageSpecCharacteristic -@enduml \ No newline at end of file +@enduml + +@startuml + foo -> bar: [Test prototype]'s start and ends at [Test prototype]'s end +@enduml diff --git a/testData/ParsingTestData.txt b/testData/ParsingTestData.txt index 8e639dd4..e00bfe71 100644 --- a/testData/ParsingTestData.txt +++ b/testData/ParsingTestData.txt @@ -1,4 +1,4 @@ -FILE(0,910) +FILE(0,1002) PumlItemImpl(@startuml)(0,9)(0,9) PsiElement(PumlTokenType.IDENTIFIER)('@startuml')(0,9) PsiWhiteSpace('\n')(9,10) @@ -497,4 +497,51 @@ FILE(0,910) PsiElement(PumlTokenType.IDENTIFIER)('ProductUsageSpecCharacteristic')(872,902) PsiWhiteSpace('\n')(902,903) PumlItemImpl(@enduml)(903,910)(903,910) - PsiElement(PumlTokenType.IDENTIFIER)('@enduml')(903,910) \ No newline at end of file + PsiElement(PumlTokenType.IDENTIFIER)('@enduml')(903,910) + PsiWhiteSpace('\n\n')(910,912) + PumlItemImpl(@startuml)(912,921)(912,921) + PsiElement(PumlTokenType.IDENTIFIER)('@startuml')(912,921) + PsiWhiteSpace('\n')(921,922) + PsiWhiteSpace(' ')(922,923) + PumlItemImpl(foo)(923,926)(923,926) + PsiElement(PumlTokenType.IDENTIFIER)('foo')(923,926) + PsiWhiteSpace(' ')(926,927) + PumlItemImpl(->)(927,929)(927,929) + PsiElement(PumlTokenType.OTHER)('->')(927,929) + PsiWhiteSpace(' ')(929,930) + PumlItemImpl(bar)(930,933)(930,933) + PsiElement(PumlTokenType.IDENTIFIER)('bar')(930,933) + PumlItemImpl(:)(933,934)(933,934) + PsiElement(PumlTokenType.OTHER)(':')(933,934) + PsiWhiteSpace(' ')(934,935) + PumlItemImpl([Test prototype])(935,951)(935,951) + PsiElement(PumlTokenType.IDENTIFIER)('[Test prototype]')(935,951) + PumlItemImpl(')(951,952)(951,952) + PsiElement(PumlTokenType.OTHER)(''')(951,952) + PumlItemImpl(s)(952,953)(952,953) + PsiElement(PumlTokenType.IDENTIFIER)('s')(952,953) + PsiWhiteSpace(' ')(953,954) + PumlItemImpl(start)(954,959)(954,959) + PsiElement(PumlTokenType.IDENTIFIER)('start')(954,959) + PsiWhiteSpace(' ')(959,960) + PumlItemImpl(and)(960,963)(960,963) + PsiElement(PumlTokenType.IDENTIFIER)('and')(960,963) + PsiWhiteSpace(' ')(963,964) + PumlItemImpl(ends)(964,968)(964,968) + PsiElement(PumlTokenType.IDENTIFIER)('ends')(964,968) + PsiWhiteSpace(' ')(968,969) + PumlItemImpl(at)(969,971)(969,971) + PsiElement(PumlTokenType.IDENTIFIER)('at')(969,971) + PsiWhiteSpace(' ')(971,972) + PumlItemImpl([Test prototype])(972,988)(972,988) + PsiElement(PumlTokenType.IDENTIFIER)('[Test prototype]')(972,988) + PumlItemImpl(')(988,989)(988,989) + PsiElement(PumlTokenType.OTHER)(''')(988,989) + PumlItemImpl(s)(989,990)(989,990) + PsiElement(PumlTokenType.IDENTIFIER)('s')(989,990) + PsiWhiteSpace(' ')(990,991) + PumlItemImpl(end)(991,994)(991,994) + PsiElement(PumlTokenType.IDENTIFIER)('end')(991,994) + PsiWhiteSpace('\n')(994,995) + PumlItemImpl(@enduml)(995,1002)(995,1002) + PsiElement(PumlTokenType.IDENTIFIER)('@enduml')(995,1002) \ No newline at end of file