From 07b179c6a642ec83382e7cb9a9c0be30f80c0218 Mon Sep 17 00:00:00 2001 From: sblundy Date: Sun, 28 Jul 2019 09:36:52 -0700 Subject: [PATCH] use keyword --- .../sblundy/elvish/lang/ElvishLexer.java | 279 +++++++++--------- .../sblundy/elvish/lang/ElvishParser.java | 17 +- .../sblundy/elvish/psi/ElvishChunk.java | 3 + .../sblundy/elvish/psi/ElvishTypes.java | 5 + .../sblundy/elvish/psi/ElvishUseCommand.java | 16 + .../sblundy/elvish/psi/ElvishVisitor.java | 4 + .../elvish/psi/impl/ElvishChunkImpl.java | 6 + .../elvish/psi/impl/ElvishUseCommandImpl.java | 41 +++ src/main/grammars/Elvish.bnf | 6 +- src/main/grammars/Elvish.flex | 2 + .../sblundy/elvish/ElvishSyntaxHighlighter.kt | 1 + .../github/sblundy/elvish/lang/use-nested.elv | 1 + .../github/sblundy/elvish/lang/use-nested.txt | 7 + .../github/sblundy/elvish/lang/use-path.elv | 1 + .../github/sblundy/elvish/lang/use-path.txt | 11 + .../com/github/sblundy/elvish/lang/use.elv | 3 + .../com/github/sblundy/elvish/lang/use.txt | 27 ++ 17 files changed, 292 insertions(+), 138 deletions(-) create mode 100644 src/gen/com/github/sblundy/elvish/psi/ElvishUseCommand.java create mode 100644 src/gen/com/github/sblundy/elvish/psi/impl/ElvishUseCommandImpl.java create mode 100644 src/test/resources/com/github/sblundy/elvish/lang/use-nested.elv create mode 100644 src/test/resources/com/github/sblundy/elvish/lang/use-nested.txt create mode 100644 src/test/resources/com/github/sblundy/elvish/lang/use-path.elv create mode 100644 src/test/resources/com/github/sblundy/elvish/lang/use-path.txt create mode 100644 src/test/resources/com/github/sblundy/elvish/lang/use.elv create mode 100644 src/test/resources/com/github/sblundy/elvish/lang/use.txt diff --git a/src/gen/com/github/sblundy/elvish/lang/ElvishLexer.java b/src/gen/com/github/sblundy/elvish/lang/ElvishLexer.java index cf720f4..d8afdb3 100644 --- a/src/gen/com/github/sblundy/elvish/lang/ElvishLexer.java +++ b/src/gen/com/github/sblundy/elvish/lang/ElvishLexer.java @@ -120,17 +120,17 @@ public static int ZZ_CMAP(int ch) { private static final int [] ZZ_ACTION = zzUnpackAction(); private static final String ZZ_ACTION_PACKED_0 = - "\3\0\1\1\1\2\1\3\1\1\1\4\1\5\1\6"+ + "\3\0\1\1\1\2\1\3\1\1\2\4\1\5\1\6"+ "\6\4\1\7\1\10\1\11\1\12\1\2\1\13\1\14"+ "\1\15\1\16\1\17\1\20\1\21\1\22\1\23\1\24"+ "\1\25\1\26\1\27\1\30\1\31\1\32\1\31\1\0"+ - "\1\33\1\3\2\34\2\4\1\35\1\4\1\36\4\4"+ - "\1\37\6\40\4\4\1\41\1\4\1\42\1\43\4\0"+ - "\1\4\1\44\1\45\2\4\2\0\2\4\1\46\1\0"+ - "\1\47\1\4\1\0\1\50"; + "\1\33\1\3\2\34\3\4\1\35\1\4\1\36\4\4"+ + "\1\37\6\40\1\41\4\4\1\42\1\4\1\43\1\44"+ + "\4\0\1\4\1\45\1\46\2\4\2\0\2\4\1\47"+ + "\1\0\1\50\1\4\1\0\1\51"; private static int [] zzUnpackAction() { - int [] result = new int[86]; + int [] result = new int[89]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; @@ -156,19 +156,20 @@ private static int zzUnpackAction(String packed, int offset, int [] result) { private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\65\0\152\0\237\0\237\0\324\0\u0109\0\u013e"+ - "\0\u0173\0\237\0\u01a8\0\u01dd\0\u0212\0\u0247\0\u027c\0\u02b1"+ - "\0\u02e6\0\237\0\u02e6\0\u0173\0\u031b\0\u0350\0\237\0\237"+ + "\0\u0173\0\u01a8\0\237\0\u01dd\0\u0212\0\u0247\0\u027c\0\u02b1"+ + "\0\u02e6\0\u031b\0\237\0\u031b\0\u01a8\0\u0350\0\u0385\0\237"+ "\0\237\0\237\0\237\0\237\0\237\0\237\0\237\0\237"+ - "\0\u013e\0\237\0\237\0\u0385\0\u03ba\0\u03ef\0\u0424\0\237"+ - "\0\u0459\0\237\0\u048e\0\u04c3\0\u04f8\0\u013e\0\u052d\0\u013e"+ - "\0\u0562\0\u0597\0\u05cc\0\u0601\0\237\0\237\0\u0636\0\u066b"+ - "\0\u06a0\0\u06d5\0\u070a\0\u073f\0\u0774\0\u07a9\0\u07de\0\u013e"+ - "\0\u0813\0\u013e\0\u013e\0\u0848\0\u087d\0\u08b2\0\u08e7\0\u091c"+ - "\0\u013e\0\u013e\0\u0951\0\u0986\0\u09bb\0\u06d5\0\u09f0\0\u0a25"+ - "\0\u013e\0\u0a5a\0\u013e\0\u0a8f\0\u066b\0\u013e"; + "\0\237\0\u013e\0\237\0\237\0\u03ba\0\u03ef\0\u0424\0\u0459"+ + "\0\237\0\u048e\0\237\0\u04c3\0\u04f8\0\u052d\0\u0562\0\u013e"+ + "\0\u0597\0\u013e\0\u05cc\0\u0601\0\u0636\0\u066b\0\237\0\237"+ + "\0\u06a0\0\u06d5\0\u070a\0\u073f\0\u0774\0\u013e\0\u07a9\0\u07de"+ + "\0\u0813\0\u0848\0\u013e\0\u087d\0\u013e\0\u013e\0\u08b2\0\u08e7"+ + "\0\u091c\0\u0951\0\u0986\0\u013e\0\u013e\0\u09bb\0\u09f0\0\u0a25"+ + "\0\u073f\0\u0a5a\0\u0a8f\0\u013e\0\u0ac4\0\u013e\0\u0af9\0\u06d5"+ + "\0\u013e"; private static int [] zzUnpackRowMap() { - int [] result = new int[86]; + int [] result = new int[89]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; @@ -191,79 +192,82 @@ private static int zzUnpackRowMap(String packed, int offset, int [] result) { private static final int [] ZZ_TRANS = zzUnpackTrans(); private static final String ZZ_TRANS_PACKED_0 = - "\1\4\1\5\1\6\1\7\5\10\1\11\1\10\1\12"+ - "\3\10\1\13\2\10\1\14\1\15\1\16\2\10\1\17"+ - "\5\10\1\20\1\21\1\22\1\11\2\10\1\23\1\24"+ - "\1\25\1\26\1\27\1\30\1\31\1\32\1\33\1\34"+ - "\1\35\1\36\1\37\1\40\1\41\1\42\1\43\1\4"+ - "\56\44\1\45\6\44\3\46\1\47\53\46\1\50\5\46"+ - "\65\0\1\6\1\51\63\6\1\0\1\52\43\0\1\53"+ - "\23\0\5\10\1\0\1\10\1\0\22\10\3\0\2\10"+ - "\16\0\1\10\14\0\1\11\26\0\1\11\3\0\1\11"+ - "\24\0\4\10\1\54\1\0\1\10\1\0\4\10\1\55"+ - "\15\10\3\0\2\10\16\0\1\10\7\0\5\10\1\0"+ - "\1\10\1\0\7\10\1\56\12\10\3\0\2\10\16\0"+ - "\1\10\7\0\5\10\1\0\1\10\1\0\6\10\1\57"+ - "\5\10\1\60\2\10\1\61\2\10\3\0\2\10\16\0"+ - "\1\10\7\0\5\10\1\0\1\10\1\0\11\10\1\62"+ - "\10\10\3\0\2\10\16\0\1\10\7\0\5\10\1\0"+ - "\1\10\1\0\20\10\1\63\1\10\3\0\2\10\16\0"+ - "\1\10\7\0\5\10\1\0\1\10\1\0\3\10\1\64"+ - "\16\10\3\0\2\10\16\0\1\10\41\0\1\21\4\0"+ - "\1\21\22\0\1\5\131\0\1\26\16\0\56\44\1\0"+ - "\6\44\56\0\1\65\6\0\3\46\1\0\53\46\1\0"+ - "\5\46\1\66\1\0\1\66\1\65\1\67\1\66\1\70"+ - "\1\71\1\72\2\73\2\66\3\65\3\66\1\65\3\66"+ - "\3\65\2\66\1\65\10\66\1\0\11\66\1\65\4\66"+ - "\2\0\1\51\43\0\1\51\20\0\1\52\67\0\5\10"+ - "\1\0\1\74\1\0\22\10\3\0\2\10\16\0\1\10"+ - "\7\0\5\10\1\0\1\10\1\0\5\10\1\75\1\76"+ - "\13\10\3\0\2\10\16\0\1\10\7\0\5\10\1\0"+ - "\1\10\1\0\14\10\1\77\5\10\3\0\2\10\16\0"+ - "\1\10\7\0\5\10\1\0\1\10\1\0\20\10\1\100"+ - "\1\10\3\0\2\10\16\0\1\10\7\0\5\10\1\0"+ - "\1\10\1\0\6\10\1\101\13\10\3\0\2\10\16\0"+ - "\1\10\7\0\5\10\1\0\1\10\1\0\16\10\1\102"+ - "\3\10\3\0\2\10\16\0\1\10\7\0\5\10\1\0"+ - "\1\10\1\0\4\10\1\103\15\10\3\0\2\10\16\0"+ - "\1\10\10\0\1\104\1\0\1\104\2\0\1\104\1\0"+ - "\1\104\1\0\2\104\3\0\1\104\5\0\1\104\3\0"+ - "\1\104\34\0\1\105\1\0\1\105\2\0\1\105\1\0"+ - "\1\105\1\0\2\105\3\0\1\105\5\0\1\105\3\0"+ - "\1\105\36\0\1\106\62\0\1\107\1\0\1\107\2\0"+ + "\1\4\1\5\1\6\1\7\2\10\1\11\2\10\1\12"+ + "\1\10\1\13\3\10\1\14\2\10\1\15\1\16\1\17"+ + "\2\10\1\20\5\10\1\21\1\22\1\23\1\12\2\10"+ + "\1\24\1\25\1\26\1\27\1\30\1\31\1\32\1\33"+ + "\1\34\1\35\1\36\1\37\1\40\1\41\1\42\1\43"+ + "\1\44\1\4\56\45\1\46\6\45\3\47\1\50\53\47"+ + "\1\51\5\47\65\0\1\6\1\52\63\6\1\0\1\53"+ + "\43\0\1\54\23\0\5\10\1\0\1\10\1\0\22\10"+ + "\3\0\2\10\16\0\1\10\7\0\5\10\1\0\1\10"+ + "\1\0\5\10\1\55\14\10\3\0\2\10\16\0\1\10"+ + "\14\0\1\12\26\0\1\12\3\0\1\12\24\0\4\10"+ + "\1\56\1\0\1\10\1\0\4\10\1\57\15\10\3\0"+ + "\2\10\16\0\1\10\7\0\5\10\1\0\1\10\1\0"+ + "\7\10\1\60\12\10\3\0\2\10\16\0\1\10\7\0"+ + "\5\10\1\0\1\10\1\0\6\10\1\61\5\10\1\62"+ + "\2\10\1\63\2\10\3\0\2\10\16\0\1\10\7\0"+ + "\5\10\1\0\1\10\1\0\11\10\1\64\10\10\3\0"+ + "\2\10\16\0\1\10\7\0\5\10\1\0\1\10\1\0"+ + "\20\10\1\65\1\10\3\0\2\10\16\0\1\10\7\0"+ + "\5\10\1\0\1\10\1\0\3\10\1\66\16\10\3\0"+ + "\2\10\16\0\1\10\41\0\1\22\4\0\1\22\22\0"+ + "\1\5\131\0\1\27\16\0\56\45\1\0\6\45\56\0"+ + "\1\67\6\0\3\47\1\0\53\47\1\0\5\47\1\70"+ + "\1\0\1\70\1\67\1\71\1\70\1\72\1\73\1\74"+ + "\2\75\2\70\3\67\3\70\1\67\3\70\3\67\2\70"+ + "\1\67\10\70\1\0\11\70\1\67\4\70\2\0\1\52"+ + "\43\0\1\52\20\0\1\53\67\0\5\10\1\0\1\10"+ + "\1\0\3\10\1\76\16\10\3\0\2\10\16\0\1\10"+ + "\7\0\5\10\1\0\1\77\1\0\22\10\3\0\2\10"+ + "\16\0\1\10\7\0\5\10\1\0\1\10\1\0\5\10"+ + "\1\100\1\101\13\10\3\0\2\10\16\0\1\10\7\0"+ + "\5\10\1\0\1\10\1\0\14\10\1\102\5\10\3\0"+ + "\2\10\16\0\1\10\7\0\5\10\1\0\1\10\1\0"+ + "\20\10\1\103\1\10\3\0\2\10\16\0\1\10\7\0"+ + "\5\10\1\0\1\10\1\0\6\10\1\104\13\10\3\0"+ + "\2\10\16\0\1\10\7\0\5\10\1\0\1\10\1\0"+ + "\16\10\1\105\3\10\3\0\2\10\16\0\1\10\7\0"+ + "\5\10\1\0\1\10\1\0\4\10\1\106\15\10\3\0"+ + "\2\10\16\0\1\10\10\0\1\107\1\0\1\107\2\0"+ "\1\107\1\0\1\107\1\0\2\107\3\0\1\107\5\0"+ - "\1\107\3\0\1\107\32\0\2\65\4\0\1\65\1\0"+ - "\2\65\25\0\2\65\6\0\1\65\16\0\5\10\1\0"+ - "\1\10\1\0\3\10\1\110\16\10\3\0\2\10\16\0"+ - "\1\10\7\0\5\10\1\0\1\10\1\0\3\10\1\111"+ - "\16\10\3\0\2\10\16\0\1\10\7\0\5\10\1\0"+ - "\1\10\1\0\7\10\1\112\12\10\3\0\2\10\16\0"+ - "\1\10\7\0\5\10\1\0\1\10\1\0\15\10\1\113"+ - "\4\10\3\0\2\10\16\0\1\10\7\0\5\10\1\0"+ - "\1\10\1\0\4\10\1\114\15\10\3\0\2\10\16\0"+ - "\1\10\10\0\1\115\1\0\1\115\2\0\1\115\1\0"+ - "\1\115\1\0\2\115\3\0\1\115\5\0\1\115\3\0"+ - "\1\115\34\0\1\116\1\0\1\116\2\0\1\116\1\0"+ - "\1\116\1\0\2\116\3\0\1\116\5\0\1\116\3\0"+ - "\1\116\36\0\1\65\62\0\1\65\1\0\1\65\2\0"+ - "\1\65\1\0\1\65\1\0\2\65\3\0\1\65\5\0"+ - "\1\65\3\0\1\65\33\0\5\10\1\0\1\10\1\0"+ - "\12\10\1\117\7\10\3\0\2\10\16\0\1\10\7\0"+ - "\5\10\1\0\1\10\1\0\4\10\1\120\15\10\3\0"+ + "\1\107\3\0\1\107\34\0\1\110\1\0\1\110\2\0"+ + "\1\110\1\0\1\110\1\0\2\110\3\0\1\110\5\0"+ + "\1\110\3\0\1\110\36\0\1\111\62\0\1\112\1\0"+ + "\1\112\2\0\1\112\1\0\1\112\1\0\2\112\3\0"+ + "\1\112\5\0\1\112\3\0\1\112\32\0\2\67\4\0"+ + "\1\67\1\0\2\67\25\0\2\67\6\0\1\67\16\0"+ + "\5\10\1\0\1\10\1\0\3\10\1\113\16\10\3\0"+ "\2\10\16\0\1\10\7\0\5\10\1\0\1\10\1\0"+ - "\3\10\1\121\16\10\3\0\2\10\16\0\1\10\10\0"+ - "\1\122\1\0\1\122\2\0\1\122\1\0\1\122\1\0"+ - "\2\122\3\0\1\122\5\0\1\122\3\0\1\122\33\0"+ - "\5\10\1\0\1\10\1\0\13\10\1\123\6\10\3\0"+ + "\3\10\1\114\16\10\3\0\2\10\16\0\1\10\7\0"+ + "\5\10\1\0\1\10\1\0\7\10\1\115\12\10\3\0"+ "\2\10\16\0\1\10\7\0\5\10\1\0\1\10\1\0"+ - "\4\10\1\124\15\10\3\0\2\10\16\0\1\10\10\0"+ - "\1\125\1\0\1\125\2\0\1\125\1\0\1\125\1\0"+ - "\2\125\3\0\1\125\5\0\1\125\3\0\1\125\33\0"+ - "\5\10\1\0\1\10\1\0\16\10\1\126\3\10\3\0"+ - "\2\10\16\0\1\10\3\0"; + "\15\10\1\116\4\10\3\0\2\10\16\0\1\10\7\0"+ + "\5\10\1\0\1\10\1\0\4\10\1\117\15\10\3\0"+ + "\2\10\16\0\1\10\10\0\1\120\1\0\1\120\2\0"+ + "\1\120\1\0\1\120\1\0\2\120\3\0\1\120\5\0"+ + "\1\120\3\0\1\120\34\0\1\121\1\0\1\121\2\0"+ + "\1\121\1\0\1\121\1\0\2\121\3\0\1\121\5\0"+ + "\1\121\3\0\1\121\36\0\1\67\62\0\1\67\1\0"+ + "\1\67\2\0\1\67\1\0\1\67\1\0\2\67\3\0"+ + "\1\67\5\0\1\67\3\0\1\67\33\0\5\10\1\0"+ + "\1\10\1\0\12\10\1\122\7\10\3\0\2\10\16\0"+ + "\1\10\7\0\5\10\1\0\1\10\1\0\4\10\1\123"+ + "\15\10\3\0\2\10\16\0\1\10\7\0\5\10\1\0"+ + "\1\10\1\0\3\10\1\124\16\10\3\0\2\10\16\0"+ + "\1\10\10\0\1\125\1\0\1\125\2\0\1\125\1\0"+ + "\1\125\1\0\2\125\3\0\1\125\5\0\1\125\3\0"+ + "\1\125\33\0\5\10\1\0\1\10\1\0\13\10\1\126"+ + "\6\10\3\0\2\10\16\0\1\10\7\0\5\10\1\0"+ + "\1\10\1\0\4\10\1\127\15\10\3\0\2\10\16\0"+ + "\1\10\10\0\1\130\1\0\1\130\2\0\1\130\1\0"+ + "\1\130\1\0\2\130\3\0\1\130\5\0\1\130\3\0"+ + "\1\130\33\0\5\10\1\0\1\10\1\0\16\10\1\131"+ + "\3\10\3\0\2\10\16\0\1\10\3\0"; private static int [] zzUnpackTrans() { - int [] result = new int[2756]; + int [] result = new int[2862]; int offset = 0; offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); return result; @@ -301,13 +305,13 @@ 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 = - "\3\0\2\11\4\1\1\11\7\1\1\11\4\1\12\11"+ - "\1\1\2\11\3\1\1\0\1\11\1\1\1\11\12\1"+ - "\2\11\15\1\4\0\5\1\2\0\3\1\1\0\2\1"+ + "\3\0\2\11\5\1\1\11\7\1\1\11\4\1\12\11"+ + "\1\1\2\11\3\1\1\0\1\11\1\1\1\11\13\1"+ + "\2\11\16\1\4\0\5\1\2\0\3\1\1\0\2\1"+ "\1\0\1\1"; private static int [] zzUnpackAttribute() { - int [] result = new int[86]; + int [] result = new int[89]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; @@ -626,206 +630,211 @@ else if (zzAtEOF) { { return TokenType.BAD_CHARACTER; } // fall through - case 41: break; + case 42: break; case 2: { return ElvishTypes.EOL; } // fall through - case 42: break; + case 43: break; case 3: { return ElvishTypes.COMMENT; } // fall through - case 43: break; + case 44: break; case 4: { return ElvishTypes.VARIABLE_CHAR; } // fall through - case 44: break; + case 45: break; case 5: { return ElvishTypes.COMMAND_BAREWORD_CHAR; } // fall through - case 45: break; + case 46: break; case 6: { return ElvishTypes.CLOSE_BRACKET; } // fall through - case 46: break; + case 47: break; case 7: { return ElvishTypes.BAREWORD_CHAR; } // fall through - case 47: break; + case 48: break; case 8: { return ElvishTypes.EQUALS; } // fall through - case 48: break; + case 49: break; case 9: { return ElvishTypes.AT_SYMBOL; } // fall through - case 49: break; + case 50: break; case 10: { return ElvishTypes.WILDCARD; } // fall through - case 50: break; + case 51: break; case 11: { return ElvishTypes.INLINE_WHITESPACE; } // fall through - case 51: break; + case 52: break; case 12: { return ElvishTypes.DOLLAR_SIGN; } // fall through - case 52: break; + case 53: break; case 13: { return ElvishTypes.OPEN_BRACE; } // fall through - case 53: break; + case 54: break; case 14: { return ElvishTypes.CLOSE_BRACE; } // fall through - case 54: break; + case 55: break; case 15: { return ElvishTypes.OPEN_BRACKET; } // fall through - case 55: break; + case 56: break; case 16: { return ElvishTypes.QUESTION; } // fall through - case 56: break; + case 57: break; case 17: { return ElvishTypes.OPEN_PARAN; } // fall through - case 57: break; + case 58: break; case 18: { return ElvishTypes.CLOSE_PARAN; } // fall through - case 58: break; + case 59: break; case 19: { yyPushState(IN_SINGLE_QUOTE_STRING); return ElvishTypes.SINGLE_QUOTE; } // fall through - case 59: break; + case 60: break; case 20: { yyPushState(IN_DOUBLE_QUOTE_STRING); return ElvishTypes.DOUBLE_QUOTE; } // fall through - case 60: break; + case 61: break; case 21: { return ElvishTypes.AMPERSAND; } // fall through - case 61: break; + case 62: break; case 22: { return ElvishTypes.TILDE; } // fall through - case 62: break; + case 63: break; case 23: { return ElvishTypes.PIPE; } // fall through - case 63: break; + case 64: break; case 24: { return ElvishTypes.SEMICOLON; } // fall through - case 64: break; + case 65: break; case 25: { return ElvishTypes.TEXT; } // fall through - case 65: break; + case 66: break; case 26: { yyPopState(); return ElvishTypes.SINGLE_QUOTE; } // fall through - case 66: break; + case 67: break; case 27: { yyPopState(); return ElvishTypes.DOUBLE_QUOTE; } // fall through - case 67: break; + case 68: break; case 28: { return ElvishTypes.CONTINUATION; } // fall through - case 68: break; + case 69: break; case 29: { return ElvishTypes.KEYWORD_IF; } // fall through - case 69: break; + case 70: break; case 30: { return ElvishTypes.KEYWORD_FN; } // fall through - case 70: break; + case 71: break; case 31: { return ElvishTypes.ESCAPED_QUOTED_TEXT; } // fall through - case 71: break; + case 72: break; case 32: { return ElvishTypes.INVALID_ESCAPED_QUOTED_TEXT; } // fall through - case 72: break; + case 73: break; case 33: - { return ElvishTypes.KEYWORD_FOR; + { return ElvishTypes.KEYWORD_USE; } // fall through - case 73: break; + case 74: break; case 34: - { return ElvishTypes.KEYWORD_TRY; + { return ElvishTypes.KEYWORD_FOR; } // fall through - case 74: break; + case 75: break; case 35: - { return ElvishTypes.KEYWORD_DEL; + { return ElvishTypes.KEYWORD_TRY; } // fall through - case 75: break; + case 76: break; case 36: - { return ElvishTypes.KEYWORD_ELSE; + { return ElvishTypes.KEYWORD_DEL; } // fall through - case 76: break; + case 77: break; case 37: - { return ElvishTypes.KEYWORD_ELIF; + { return ElvishTypes.KEYWORD_ELSE; } // fall through - case 77: break; + case 78: break; case 38: - { return ElvishTypes.KEYWORD_WHILE; + { return ElvishTypes.KEYWORD_ELIF; } // fall through - case 78: break; + case 79: break; case 39: - { return ElvishTypes.KEYWORD_EXCEPT; + { return ElvishTypes.KEYWORD_WHILE; } // fall through - case 79: break; + case 80: break; case 40: + { return ElvishTypes.KEYWORD_EXCEPT; + } + // fall through + case 81: break; + case 41: { return ElvishTypes.KEYWORD_FINALLY; } // fall through - case 80: break; + case 82: break; default: zzScanError(ZZ_NO_MATCH); } diff --git a/src/gen/com/github/sblundy/elvish/lang/ElvishParser.java b/src/gen/com/github/sblundy/elvish/lang/ElvishParser.java index 39afd4c..34ffba1 100644 --- a/src/gen/com/github/sblundy/elvish/lang/ElvishParser.java +++ b/src/gen/com/github/sblundy/elvish/lang/ElvishParser.java @@ -1530,11 +1530,12 @@ static boolean Space(PsiBuilder builder_, int level_) { } /* ********************************************************** */ - // DeleteCommand | LogicCommand | IfCommand | WhileCommand | ForCommand | TryCommand | FnCommand + // DeleteCommand | UseCommand | LogicCommand | IfCommand | WhileCommand | ForCommand | TryCommand | FnCommand static boolean SpecialCommand(PsiBuilder builder_, int level_) { if (!recursion_guard_(builder_, level_, "SpecialCommand")) return false; boolean result_; result_ = DeleteCommand(builder_, level_ + 1); + if (!result_) result_ = UseCommand(builder_, level_ + 1); if (!result_) result_ = LogicCommand(builder_, level_ + 1); if (!result_) result_ = IfCommand(builder_, level_ + 1); if (!result_) result_ = WhileCommand(builder_, level_ + 1); @@ -1617,6 +1618,20 @@ private static boolean TryCommand_7_0(PsiBuilder builder_, int level_) { return result_; } + /* ********************************************************** */ + // KEYWORD_USE Space Bareword + public static boolean UseCommand(PsiBuilder builder_, int level_) { + if (!recursion_guard_(builder_, level_, "UseCommand")) return false; + if (!nextTokenIs(builder_, KEYWORD_USE)) return false; + boolean result_; + Marker marker_ = enter_section_(builder_); + result_ = consumeToken(builder_, KEYWORD_USE); + result_ = result_ && Space(builder_, level_ + 1); + result_ = result_ && Bareword(builder_, level_ + 1); + exit_section_(builder_, marker_, USE_COMMAND, result_); + return result_; + } + /* ********************************************************** */ // VARIABLE_CHAR+ public static boolean Variable(PsiBuilder builder_, int level_) { diff --git a/src/gen/com/github/sblundy/elvish/psi/ElvishChunk.java b/src/gen/com/github/sblundy/elvish/psi/ElvishChunk.java index c37e238..81cd096 100644 --- a/src/gen/com/github/sblundy/elvish/psi/ElvishChunk.java +++ b/src/gen/com/github/sblundy/elvish/psi/ElvishChunk.java @@ -31,6 +31,9 @@ public interface ElvishChunk extends PsiElement { @NotNull List getTryCommandList(); + @NotNull + List getUseCommandList(); + @NotNull List getWhileCommandList(); diff --git a/src/gen/com/github/sblundy/elvish/psi/ElvishTypes.java b/src/gen/com/github/sblundy/elvish/psi/ElvishTypes.java index af61ff2..f340698 100644 --- a/src/gen/com/github/sblundy/elvish/psi/ElvishTypes.java +++ b/src/gen/com/github/sblundy/elvish/psi/ElvishTypes.java @@ -43,6 +43,7 @@ public interface ElvishTypes { IElementType REDIR = new ElvishElementType("REDIR"); IElementType SINGLE_QUOTED = new ElvishElementType("SINGLE_QUOTED"); IElementType TRY_COMMAND = new ElvishElementType("TRY_COMMAND"); + IElementType USE_COMMAND = new ElvishElementType("USE_COMMAND"); IElementType VARIABLE = new ElvishElementType("VARIABLE"); IElementType VARIABLE_REF = new ElvishElementType("VARIABLE_REF"); IElementType WHILE_COMMAND = new ElvishElementType("WHILE_COMMAND"); @@ -72,6 +73,7 @@ public interface ElvishTypes { IElementType KEYWORD_FOR = new ElvishTokenType("for"); IElementType KEYWORD_IF = new ElvishTokenType("if"); IElementType KEYWORD_TRY = new ElvishTokenType("try"); + IElementType KEYWORD_USE = new ElvishTokenType("use"); IElementType KEYWORD_WHILE = new ElvishTokenType("while"); IElementType OPEN_BRACE = new ElvishTokenType("{"); IElementType OPEN_BRACKET = new ElvishTokenType("["); @@ -193,6 +195,9 @@ else if (type == SINGLE_QUOTED) { else if (type == TRY_COMMAND) { return new ElvishTryCommandImpl(node); } + else if (type == USE_COMMAND) { + return new ElvishUseCommandImpl(node); + } else if (type == VARIABLE) { return new ElvishVariableImpl(node); } diff --git a/src/gen/com/github/sblundy/elvish/psi/ElvishUseCommand.java b/src/gen/com/github/sblundy/elvish/psi/ElvishUseCommand.java new file mode 100644 index 0000000..7e87c0d --- /dev/null +++ b/src/gen/com/github/sblundy/elvish/psi/ElvishUseCommand.java @@ -0,0 +1,16 @@ +// This is a generated file. Not intended for manual editing. +package com.github.sblundy.elvish.psi; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.psi.PsiElement; + +public interface ElvishUseCommand extends PsiElement { + + @NotNull + ElvishBareword getBareword(); + + @NotNull + PsiElement getInlineWhitespace(); + +} diff --git a/src/gen/com/github/sblundy/elvish/psi/ElvishVisitor.java b/src/gen/com/github/sblundy/elvish/psi/ElvishVisitor.java index f2dcb84..212b150 100644 --- a/src/gen/com/github/sblundy/elvish/psi/ElvishVisitor.java +++ b/src/gen/com/github/sblundy/elvish/psi/ElvishVisitor.java @@ -135,6 +135,10 @@ public void visitTryCommand(@NotNull ElvishTryCommand o) { visitPsiElement(o); } + public void visitUseCommand(@NotNull ElvishUseCommand o) { + visitPsiElement(o); + } + public void visitVariable(@NotNull ElvishVariable o) { visitPsiElement(o); } diff --git a/src/gen/com/github/sblundy/elvish/psi/impl/ElvishChunkImpl.java b/src/gen/com/github/sblundy/elvish/psi/impl/ElvishChunkImpl.java index cfca421..9a5a56c 100644 --- a/src/gen/com/github/sblundy/elvish/psi/impl/ElvishChunkImpl.java +++ b/src/gen/com/github/sblundy/elvish/psi/impl/ElvishChunkImpl.java @@ -74,6 +74,12 @@ public List getTryCommandList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, ElvishTryCommand.class); } + @Override + @NotNull + public List getUseCommandList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, ElvishUseCommand.class); + } + @Override @NotNull public List getWhileCommandList() { diff --git a/src/gen/com/github/sblundy/elvish/psi/impl/ElvishUseCommandImpl.java b/src/gen/com/github/sblundy/elvish/psi/impl/ElvishUseCommandImpl.java new file mode 100644 index 0000000..b326388 --- /dev/null +++ b/src/gen/com/github/sblundy/elvish/psi/impl/ElvishUseCommandImpl.java @@ -0,0 +1,41 @@ +// This is a generated file. Not intended for manual editing. +package com.github.sblundy.elvish.psi.impl; + +import java.util.List; +import org.jetbrains.annotations.*; +import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.util.PsiTreeUtil; +import static com.github.sblundy.elvish.psi.ElvishTypes.*; +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.github.sblundy.elvish.psi.*; + +public class ElvishUseCommandImpl extends ASTWrapperPsiElement implements ElvishUseCommand { + + public ElvishUseCommandImpl(@NotNull ASTNode node) { + super(node); + } + + public void accept(@NotNull ElvishVisitor visitor) { + visitor.visitUseCommand(this); + } + + public void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof ElvishVisitor) accept((ElvishVisitor)visitor); + else super.accept(visitor); + } + + @Override + @NotNull + public ElvishBareword getBareword() { + return findNotNullChildByClass(ElvishBareword.class); + } + + @Override + @NotNull + public PsiElement getInlineWhitespace() { + return findNotNullChildByType(INLINE_WHITESPACE); + } + +} diff --git a/src/main/grammars/Elvish.bnf b/src/main/grammars/Elvish.bnf index 805688c..fbd0726 100644 --- a/src/main/grammars/Elvish.bnf +++ b/src/main/grammars/Elvish.bnf @@ -53,6 +53,7 @@ KEYWORD_TRY="try" KEYWORD_DEL="del" KEYWORD_FN="fn" + KEYWORD_USE="use" CONTINUATION="regexp:[\\][\r|\n]" ] } @@ -114,7 +115,7 @@ BracedSep ::= (Space | EOL)* [ ',' ] (Space | EOL)* // Special Commands -private SpecialCommand ::= DeleteCommand | LogicCommand | IfCommand | WhileCommand | ForCommand | TryCommand | FnCommand +private SpecialCommand ::= DeleteCommand | UseCommand | LogicCommand | IfCommand | WhileCommand | ForCommand | TryCommand | FnCommand DeleteCommand ::= KEYWORD_DEL CommandSep* Variable Index* LogicCommand ::= LogicCMD (CommandSep* argument)* CommandSep* @@ -129,4 +130,5 @@ Collection ::= List | Map | VariableRef | ExceptionCapture | OutputCapture TryCommand ::= KEYWORD_TRY Space OPEN_BRACE Chunk CLOSE_BRACE (Space ExceptBlock)? (Space ElseBlock)? (Space FinallyBlock)? ExceptBlock ::= KEYWORD_EXCEPT Space Variable Space OPEN_BRACE Chunk CLOSE_BRACE FinallyBlock ::= KEYWORD_FINALLY Space OPEN_BRACE Chunk CLOSE_BRACE -FnCommand ::= KEYWORD_FN Space Variable Space LambdaArguments? OPEN_BRACE Chunk CLOSE_BRACE \ No newline at end of file +FnCommand ::= KEYWORD_FN Space Variable Space LambdaArguments? OPEN_BRACE Chunk CLOSE_BRACE +UseCommand ::= KEYWORD_USE Space Bareword \ No newline at end of file diff --git a/src/main/grammars/Elvish.flex b/src/main/grammars/Elvish.flex index 1aa6104..8428e2c 100644 --- a/src/main/grammars/Elvish.flex +++ b/src/main/grammars/Elvish.flex @@ -53,6 +53,7 @@ KEYWORD_IF = if KEYWORD_TRY = try KEYWORD_DEL = del KEYWORD_FN = fn +KEYWORD_USE = use STRING_CMP_BUILTINS=(([<>=!]=)|[<>])s NUMERIC_CMP_BUILTINS=(([<>=!]=)|[<>]) VARIABLE_CHAR=[[0-9a-zA-Z\-_:~]||[[\u0080-\uFFFF]&&\p{Print}]] // see parse/parse.go:713 (allowedInVariableName()) @@ -109,6 +110,7 @@ WHITESPACE=({INLINE_WHITESPACE_CHAR}|{EOL})+ {KEYWORD_FN} { return ElvishTypes.KEYWORD_FN; } {KEYWORD_TRY} { return ElvishTypes.KEYWORD_TRY; } {KEYWORD_DEL} { return ElvishTypes.KEYWORD_DEL; } + {KEYWORD_USE} { return ElvishTypes.KEYWORD_USE; } {VARIABLE_CHAR}+ { return ElvishTypes.VARIABLE_CHAR; } {BAREWORD_CHAR}+ { return ElvishTypes.BAREWORD_CHAR; } {COMMAND_BAREWORD_CHAR}+ { return ElvishTypes.COMMAND_BAREWORD_CHAR; } diff --git a/src/main/kotlin/com/github/sblundy/elvish/ElvishSyntaxHighlighter.kt b/src/main/kotlin/com/github/sblundy/elvish/ElvishSyntaxHighlighter.kt index bdeacc7..df18f35 100644 --- a/src/main/kotlin/com/github/sblundy/elvish/ElvishSyntaxHighlighter.kt +++ b/src/main/kotlin/com/github/sblundy/elvish/ElvishSyntaxHighlighter.kt @@ -32,6 +32,7 @@ class ElvishSyntaxHighlighter : SyntaxHighlighterBase() { ElvishTypes.KEYWORD_FOR, ElvishTypes.KEYWORD_IF, ElvishTypes.KEYWORD_TRY, + ElvishTypes.KEYWORD_USE, ElvishTypes.KEYWORD_WHILE -> KEYWORD_KEYS ElvishTypes.OPEN_BRACKET, ElvishTypes.CLOSE_BRACKET -> BRACKETS_KEYS ElvishTypes.OPEN_BRACE, ElvishTypes.CLOSE_BRACE -> BRACES_KEYS diff --git a/src/test/resources/com/github/sblundy/elvish/lang/use-nested.elv b/src/test/resources/com/github/sblundy/elvish/lang/use-nested.elv new file mode 100644 index 0000000..89d6ab0 --- /dev/null +++ b/src/test/resources/com/github/sblundy/elvish/lang/use-nested.elv @@ -0,0 +1 @@ +use x:y:z \ No newline at end of file diff --git a/src/test/resources/com/github/sblundy/elvish/lang/use-nested.txt b/src/test/resources/com/github/sblundy/elvish/lang/use-nested.txt new file mode 100644 index 0000000..e52cda5 --- /dev/null +++ b/src/test/resources/com/github/sblundy/elvish/lang/use-nested.txt @@ -0,0 +1,7 @@ +Elvish File + ElvishChunkImpl(CHUNK) + ElvishUseCommandImpl(USE_COMMAND) + PsiElement(ElvishTokenType.use)('use') + PsiElement(ElvishTokenType.INLINE_WHITESPACE)(' ') + ElvishBarewordImpl(BAREWORD) + PsiElement(ElvishTokenType.VARIABLE_CHAR)('x:y:z') \ No newline at end of file diff --git a/src/test/resources/com/github/sblundy/elvish/lang/use-path.elv b/src/test/resources/com/github/sblundy/elvish/lang/use-path.elv new file mode 100644 index 0000000..dc331bc --- /dev/null +++ b/src/test/resources/com/github/sblundy/elvish/lang/use-path.elv @@ -0,0 +1 @@ +use x/y/z \ No newline at end of file diff --git a/src/test/resources/com/github/sblundy/elvish/lang/use-path.txt b/src/test/resources/com/github/sblundy/elvish/lang/use-path.txt new file mode 100644 index 0000000..a355d20 --- /dev/null +++ b/src/test/resources/com/github/sblundy/elvish/lang/use-path.txt @@ -0,0 +1,11 @@ +Elvish File + ElvishChunkImpl(CHUNK) + ElvishUseCommandImpl(USE_COMMAND) + PsiElement(ElvishTokenType.use)('use') + PsiElement(ElvishTokenType.INLINE_WHITESPACE)(' ') + ElvishBarewordImpl(BAREWORD) + PsiElement(ElvishTokenType.VARIABLE_CHAR)('x') + PsiElement(ElvishTokenType.BAREWORD_CHAR)('/') + PsiElement(ElvishTokenType.VARIABLE_CHAR)('y') + PsiElement(ElvishTokenType.BAREWORD_CHAR)('/') + PsiElement(ElvishTokenType.VARIABLE_CHAR)('z') \ No newline at end of file diff --git a/src/test/resources/com/github/sblundy/elvish/lang/use.elv b/src/test/resources/com/github/sblundy/elvish/lang/use.elv new file mode 100644 index 0000000..00b247c --- /dev/null +++ b/src/test/resources/com/github/sblundy/elvish/lang/use.elv @@ -0,0 +1,3 @@ +use re + +re:find "x" $x \ No newline at end of file diff --git a/src/test/resources/com/github/sblundy/elvish/lang/use.txt b/src/test/resources/com/github/sblundy/elvish/lang/use.txt new file mode 100644 index 0000000..17ba420 --- /dev/null +++ b/src/test/resources/com/github/sblundy/elvish/lang/use.txt @@ -0,0 +1,27 @@ +Elvish File + ElvishChunkImpl(CHUNK) + ElvishUseCommandImpl(USE_COMMAND) + PsiElement(ElvishTokenType.use)('use') + PsiElement(ElvishTokenType.INLINE_WHITESPACE)(' ') + ElvishBarewordImpl(BAREWORD) + PsiElement(ElvishTokenType.VARIABLE_CHAR)('re') + ElvishPipelineSepImpl(PIPELINE_SEP) + PsiElement(ElvishTokenType.EOL)('\n') + ElvishPipelineSepImpl(PIPELINE_SEP) + PsiElement(ElvishTokenType.EOL)('\n') + ElvishHeadImpl(HEAD) + ElvishCommandBarewordImpl(COMMAND_BAREWORD) + PsiElement(ElvishTokenType.VARIABLE_CHAR)('re:find') + PsiElement(ElvishTokenType.INLINE_WHITESPACE)(' ') + ElvishArgumentImpl(ARGUMENT) + ElvishCompoundImpl(COMPOUND) + ElvishDoubleQuotedImpl(DOUBLE_QUOTED) + PsiElement(ElvishTokenType.")('"') + PsiElement(ElvishTokenType.TEXT)('x') + PsiElement(ElvishTokenType.")('"') + PsiElement(ElvishTokenType.INLINE_WHITESPACE)(' ') + ElvishArgumentImpl(ARGUMENT) + ElvishCompoundImpl(COMPOUND) + ElvishVariableRefImpl(VARIABLE_REF) + PsiElement(ElvishTokenType.$)('$') + PsiElement(ElvishTokenType.VARIABLE_CHAR)('x') \ No newline at end of file