Skip to content

Commit

Permalink
mike-lischke#136 Remove FollowSet cache dependency on ignoredTokens
Browse files Browse the repository at this point in the history
Signed-off-by: vityaman <vityaman.dev@yandex.ru>
  • Loading branch information
vityaman committed Aug 12, 2024
1 parent 5b8a86c commit 5eaad7b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 0 additions & 2 deletions ports/cpp/ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ if [ $? -ne 0 ]; then
exit 1
fi

exit 0 # https://github.com/mike-lischke/antlr4-c3/issues/136

set -e

TESTS="
Expand Down
5 changes: 3 additions & 2 deletions ports/cpp/source/antlr4-c3/CodeCompletionCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ bool CodeCompletionCore::translateToRuleIndex(
* @returns A list of toke types.
*/
std::vector<size_t> CodeCompletionCore::getFollowingTokens(const antlr4::atn::Transition* transition
) const {
) {
std::vector<size_t> result;
std::vector<antlr4::atn::ATNState*> pipeline = {transition->target};

Expand All @@ -302,7 +302,7 @@ std::vector<size_t> CodeCompletionCore::getFollowingTokens(const antlr4::atn::Tr
if (outgoing->getTransitionType() == antlr4::atn::TransitionType::ATOM) {
if (!outgoing->isEpsilon()) {
const auto list = outgoing->label();
if (list.size() == 1 && !ignoredTokens.contains(list.get(0))) {
if (list.size() == 1) {
result.push_back(list.get(0));
pipeline.push_back(outgoing->target);
}
Expand Down Expand Up @@ -501,6 +501,7 @@ CodeCompletionCore::RuleEndStatus CodeCompletionCore::processRule( // NOLINT
antlr4::atn::RuleStopState* stop = atn->ruleToStopState[startState->ruleIndex];
setsPerState[startState->stateNumber] = determineFollowSets(startState, stop);
}

const FollowSetsHolder& followSets = setsPerState[startState->stateNumber];

// Get the token index where our rule starts from our (possibly filtered)
Expand Down
2 changes: 1 addition & 1 deletion ports/cpp/source/antlr4-c3/CodeCompletionCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class CodeCompletionCore {

bool translateToRuleIndex(size_t index, RuleWithStartTokenList const& ruleWithStartTokenList);

std::vector<size_t> getFollowingTokens(const antlr4::atn::Transition* transition) const;
static std::vector<size_t> getFollowingTokens(const antlr4::atn::Transition* transition);

FollowSetsHolder determineFollowSets(antlr4::atn::ATNState* start, antlr4::atn::ATNState* stop);

Expand Down
5 changes: 2 additions & 3 deletions ports/cpp/test/expr/ExprTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ TEST(SimpleExpressionParser, TypicalSetup) {
auto candidates = completion.collectCandidates(0);
EXPECT_THAT(Keys(candidates.tokens), UnorderedElementsAre(ExprLexer::VAR, ExprLexer::LET));

// NOTE: Behaviour differs from TypeScript version
EXPECT_THAT(candidates.tokens[ExprLexer::VAR], UnorderedElementsAre());
EXPECT_THAT(candidates.tokens[ExprLexer::LET], UnorderedElementsAre());
EXPECT_THAT(candidates.tokens[ExprLexer::VAR], ElementsAre(ExprLexer::ID, ExprLexer::EQUAL));
EXPECT_THAT(candidates.tokens[ExprLexer::LET], ElementsAre(ExprLexer::ID, ExprLexer::EQUAL));
}
{
// 2) On the variable name ('c').
Expand Down

0 comments on commit 5eaad7b

Please sign in to comment.