Skip to content

Commit

Permalink
Merge pull request #59 from 1c-syntax/feature/eofHidden
Browse files Browse the repository at this point in the history
EOF in hidden channel
  • Loading branch information
asosnoviy authored Apr 15, 2020
2 parents 71be3f1 + 96231d3 commit 47f797e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/github/_1c_syntax/bsl/parser/Tokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CodePointCharStream;
import org.antlr.v4.runtime.CommonToken;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ConsoleErrorListener;
import org.antlr.v4.runtime.Lexer;
Expand Down Expand Up @@ -75,8 +76,8 @@ private List<Token> computeTokens() {
List<Token> tokensTemp = new ArrayList<>(getTokenStream().getTokens());

Token lastToken = tokensTemp.get(tokensTemp.size() - 1);
if (lastToken.getType() == EOF) {
tokensTemp.remove(tokensTemp.size() - 1);
if (lastToken.getType() == EOF && lastToken instanceof CommonToken) {
((CommonToken)lastToken).setChannel(Lexer.HIDDEN);
}

return tokensTemp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package com.github._1c_syntax.bsl.parser;

import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.ParseTree;
import org.junit.jupiter.api.Test;
Expand All @@ -40,7 +41,9 @@ void computeTokens() {
final List<Token> tokens = tokenizer.getTokens();

// then
assertThat(tokens).hasSize(9);
assertThat(tokens).hasSize(10);
assertThat(tokens.get(9).getType()).isEqualTo(Lexer.EOF);
assertThat(tokens.get(9).getChannel()).isEqualTo(Lexer.HIDDEN);
}

@Test
Expand Down

0 comments on commit 47f797e

Please sign in to comment.