Skip to content

Commit 9bfd27a

Browse files
author
wallaby.pouch
committed
parser fixes, var resolving fixes
git-svn-id: http://bashsupport.googlecode.com/svn/trunk@111 91dd7c56-102c-11df-9f54-17e475596acb
1 parent 737587c commit 9bfd27a

File tree

19 files changed

+552
-329
lines changed

19 files changed

+552
-329
lines changed

bashsupport/BashSupport.iml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
<SOURCES />
3131
</library>
3232
</orderEntry>
33-
<orderEntry type="library" name="GroupLayout" level="project" />
3433
</component>
3534
</module>
3635

bashsupport/BashSupport.ipr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@
724724
<module fileurl="file://$PROJECT_DIR$/../PluginErrorReporting/PluginErrorReporting.iml" filepath="$PROJECT_DIR$/../PluginErrorReporting/PluginErrorReporting.iml" />
725725
</modules>
726726
</component>
727-
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA IU-95.311" project-jdk-type="IDEA JDK">
727+
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA IU-95.429" project-jdk-type="IDEA JDK">
728728
<output url="file://$PROJECT_DIR$/out" />
729729
</component>
730730
<component name="ResourceManagerContainer">

bashsupport/BashSupport.iws

Lines changed: 432 additions & 240 deletions
Large diffs are not rendered by default.

bashsupport/Changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2010-07-28:
2+
- Fixed parsing of single $ characters, e.g. "$a$"
3+
- Improved parsing of for loops
4+
- Fixed resolving of global variables
5+
16
2010-07-23:
27
- Fixed exception which occured while adding a REPL console
38

bashsupport/TODO.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Bugs (indentation marks fixed bugs):
125125
- Support tilde expansion
126126
- Support for Ctrl+J
127127
- export a[1]=1 is invalid, "declare a[1]=2" is valid though
128-
- no variable auto completion in here docs
128+
- no variable auto completion in here docs
129129
- Bash v4: Inspection in v3 mode to warn about the ambiguous redirect &| if run on v4
130130
- Bash v4: declare keyword changes
131131
- Bash v4: read keyword changes

bashsupport/src/com/ansorgit/plugins/bash/lang/lexer/_BashLexer.java

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

bashsupport/src/com/ansorgit/plugins/bash/lang/parser/ParameterExpansionParsing.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ public boolean isValid(BashPsiBuilder builder) {
4141
return builder.getTokenType() == LEFT_CURLY;
4242
}
4343

44-
private boolean isValid(IElementType token) {
45-
throw new IllegalStateException("Can't check with single element");
46-
}
47-
4844
public boolean parse(BashPsiBuilder builder) {
4945
PsiBuilder.Marker marker = builder.mark();
5046

bashsupport/src/com/ansorgit/plugins/bash/lang/parser/misc/WordParsing.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import com.ansorgit.plugins.bash.lang.parser.Parsing;
2424
import com.ansorgit.plugins.bash.lang.parser.ParsingTool;
2525
import com.ansorgit.plugins.bash.lang.parser.util.ParserUtil;
26+
import com.ansorgit.plugins.bash.lang.psi.util.BashPsiUtils;
2627
import com.intellij.lang.PsiBuilder;
2728
import com.intellij.psi.tree.IElementType;
2829
import com.intellij.psi.tree.TokenSet;
30+
import com.intellij.util.ArrayUtil;
2931

3032
/**
3133
* Parsing of tokens which can be understood as word tokens, e.g. WORD, variables, subshell commands, etc.
@@ -36,6 +38,8 @@
3638
* @author Joachim Ansorg
3739
*/
3840
public class WordParsing implements ParsingTool {
41+
private static final TokenSet singleDollarFollowups = TokenSet.create(STRING_END, WHITESPACE, LINE_FEED);
42+
3943
/**
4044
* Checks whether the next tokens might belong to a word token.
4145
* The upcoming tokens are not remapped.
@@ -49,14 +53,31 @@ public boolean isWordToken(final BashPsiBuilder builder) {
4953

5054
public boolean isWordToken(final BashPsiBuilder builder, final boolean enableRemapping) {
5155
final IElementType tokenType = builder.getTokenType(false, enableRemapping);
52-
return isComposedString(tokenType)
56+
boolean isWord = isComposedString(tokenType)
5357
|| Parsing.braceExpansionParsing.isValid(builder)
5458
|| BashTokenTypes.stringLiterals.contains(tokenType)
5559
|| Parsing.var.isValid(builder)
5660
|| Parsing.shellCommand.backtickParser.isValid(builder)
5761
|| Parsing.shellCommand.conditionalParser.isValid(builder)
5862
|| Parsing.processSubstitutionParsing.isValid(builder)
5963
|| tokenType == LEFT_CURLY;
64+
65+
if (isWord) {
66+
return true;
67+
}
68+
69+
if (tokenType == DOLLAR) {
70+
PsiBuilder.Marker marker = builder.mark();
71+
try {
72+
builder.advanceLexer();
73+
IElementType next = builder.getTokenType();
74+
return singleDollarFollowups.contains(next);
75+
} finally {
76+
marker.rollbackTo();
77+
}
78+
}
79+
80+
return false;
6081
}
6182

6283
public static boolean isComposedString(IElementType tokenType) {
@@ -126,6 +147,9 @@ public boolean parseWord(BashPsiBuilder builder, boolean enableRemapping, TokenS
126147
//parsing token stream which is not a expansion but has curly brackets
127148
builder.advanceLexer();
128149
processedTokens++;
150+
} else if (nextToken == DOLLAR) {
151+
builder.advanceLexer();
152+
processedTokens++;
129153
} else { //either whitespace or unknown token
130154
break;
131155
}

bashsupport/src/com/ansorgit/plugins/bash/lang/parser/shellCommand/BacktickParsingFunction.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ public boolean isValid(BashPsiBuilder builder) {
4343
return !builder.getBackquoteData().isInBackquote() && builder.getTokenType() == BashTokenTypes.BACKQUOTE;
4444
}
4545

46-
private boolean isValid(IElementType token) {
47-
throw new IllegalStateException("isValid(token) not supported");
48-
}
49-
5046
public boolean parse(BashPsiBuilder builder) {
5147
/*
5248
backquote: '`' compound_list '`'

bashsupport/src/com/ansorgit/plugins/bash/lang/parser/shellCommand/ForLoopParsingFunction.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,24 @@ private boolean parseForLoop(BashPsiBuilder builder) {
8181
//mark the word as var
8282
ParserUtil.markTokenAndAdvance(builder, VAR_DEF_ELEMENT);
8383
} else {
84-
ParserUtil.error(forLoop, "parser.shell.for.expectedWord");
84+
forLoop.drop();
85+
ParserUtil.error(builder, "parser.shell.for.expectedWord");
8586
return false;
8687
}
8788

8889
builder.eatOptionalNewlines();
8990

9091
//now either do, a block {} or IN
91-
final IElementType afterLoopValue = ParserUtil.getTokenAndAdvance(builder);
92-
if (afterLoopValue == ShellCommandParsing.DO_KEYWORD || afterLoopValue == ShellCommandParsing.LEFT_CURLY || afterLoopValue == ShellCommandParsing.SEMI) {
93-
if (afterLoopValue == ShellCommandParsing.SEMI) {
94-
builder.eatOptionalNewlines();
95-
}
96-
} else if (afterLoopValue == ShellCommandParsing.IN_KEYWORD) {
92+
final IElementType afterLoopValue = builder.getTokenType();
93+
if (afterLoopValue == SEMI) {
94+
builder.advanceLexer();
95+
builder.eatOptionalNewlines();
96+
}
97+
/*else if (afterLoopValue == ShellCommandParsing.DO_KEYWORD || afterLoopValue == ShellCommandParsing.LEFT_CURLY) {
98+
99+
}*/ else if (afterLoopValue == ShellCommandParsing.IN_KEYWORD) {
100+
builder.advanceLexer();
101+
97102
//already after "in"
98103

99104
//parse the optional word list

0 commit comments

Comments
 (0)