Skip to content

Commit

Permalink
sonar linting
Browse files Browse the repository at this point in the history
  • Loading branch information
b3b00 committed Jul 31, 2024
1 parent 658684f commit 754f7e2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/sly/lexer/LexerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static class LexerBuilder
if (enumAttributes.Length == 0 && singleCommentAttributes.Length == 0 &&
multiCommentAttributes.Length == 0 && commentAttributes.Length == 0)
{
result?.AddError(new LexerInitializationError(ErrorLevel.WARN,
result.AddError(new LexerInitializationError(ErrorLevel.WARN,
$"token {tokenID} in lexer definition {typeof(IN).FullName} does not have Lexeme",
ErrorCodes.NOT_AN_ERROR));
}
Expand Down
2 changes: 1 addition & 1 deletion src/sly/parser/generator/visitor/EBNFSyntaxTreeVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private SyntaxVisitorResult<IN, OUT> Visit(SyntaxNode<IN> node, object context =
args.Add(context);
}

if (method == null) method = node.Visitor;
method = node.Visitor;
var t = method.Invoke(ParserVsisitorInstance, args.ToArray());
var res = (OUT) t;
result = SyntaxVisitorResult<IN, OUT>.NewValue(res);
Expand Down
2 changes: 1 addition & 1 deletion src/sly/parser/parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public ParseResult<IN, OUT> ParseWithContext(IList<Token<IN>> tokens, object par
foreach (var expecting in byEnding)
{
var expectingTokens = expecting.SelectMany(x => x.ExpectedTokens ?? new List<LeadingToken<IN>>()).Distinct();
var expectedTokens = expectingTokens != null && expectingTokens.Any() ? expectingTokens?.ToArray() : null;
var expectedTokens = expectingTokens.Any() ? expectingTokens?.ToArray() : null;
if (expectedTokens != null)
{
var expected = new UnexpectedTokenSyntaxError<IN>(expecting.First().UnexpectedToken, LexemeLabels, I18n,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,22 @@ public virtual SyntaxParseResult<IN> ParseInfixExpressionRule(IList<Token<IN>> t
}

var result = new SyntaxParseResult<IN>();
result.IsError = isError;
result.IsError = false;
result.Errors = errors;
result.EndingPosition = currentPosition;
if (!isError)
{
SyntaxNode<IN> node = null;
if (rule.IsSubRule)
node = new GroupSyntaxNode<IN>(nonTerminalName, children);
else
node = new SyntaxNode<IN>(nonTerminalName, children);
node = ManageExpressionRules(rule, node);
if (node.IsByPassNode) // inutile de créer un niveau supplémentaire
result.Root = children[0];
result.Root = node;
result.IsEnded = result.EndingPosition >= tokens.Count - 1
|| result.EndingPosition == tokens.Count - 2 &&
tokens[tokens.Count - 1].IsEOS;
}


SyntaxNode<IN> node = null;
if (rule.IsSubRule)
node = new GroupSyntaxNode<IN>(nonTerminalName, children);
else
node = new SyntaxNode<IN>(nonTerminalName, children);
node = ManageExpressionRules(rule, node);
if (node.IsByPassNode) // inutile de créer un niveau supplémentaire
result.Root = children[0];
result.Root = node;
result.IsEnded = result.EndingPosition >= tokens.Count - 1
|| result.EndingPosition == tokens.Count - 2 &&
tokens[tokens.Count - 1].IsEOS;
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ public SyntaxParseResult<IN> ParseZeroOrMore(IList<Token<IN>> tokens, ZeroOrMore
manyNode.IsManyValues = true;
break;
}
case GroupClause<IN> _:
manyNode.IsManyGroups = true;
innerResult = ParseNonTerminal(tokens, innerClause as NonTerminalClause<IN>, currentPosition,
parsingContext);
hasByPasNodes = hasByPasNodes || innerResult.HasByPassNodes;
break;
case ChoiceClause<IN> choice:
manyNode.IsManyTokens = choice.IsTerminalChoice;
manyNode.IsManyValues = choice.IsNonTerminalChoice;
Expand Down Expand Up @@ -121,12 +115,12 @@ public SyntaxParseResult<IN> ParseOneOrMore(IList<Token<IN>> tokens, OneOrMoreCl
case TerminalClause<IN> terminalClause:
manyNode.IsManyTokens = true;
firstInnerResult = ParseTerminal(tokens, terminalClause, currentPosition, parsingContext);
hasByPasNodes = hasByPasNodes || firstInnerResult.HasByPassNodes;
hasByPasNodes = firstInnerResult.HasByPassNodes;
break;
case NonTerminalClause<IN> nonTerm:
{
firstInnerResult = ParseNonTerminal(tokens, nonTerm, currentPosition, parsingContext);
hasByPasNodes = hasByPasNodes || firstInnerResult.HasByPassNodes;
hasByPasNodes = firstInnerResult.HasByPassNodes;
if (nonTerm.IsGroup)
manyNode.IsManyGroups = true;
else
Expand All @@ -137,13 +131,13 @@ public SyntaxParseResult<IN> ParseOneOrMore(IList<Token<IN>> tokens, OneOrMoreCl
manyNode.IsManyTokens = choice.IsTerminalChoice;
manyNode.IsManyValues = choice.IsNonTerminalChoice;
firstInnerResult = ParseChoice(tokens, choice, currentPosition, parsingContext);
hasByPasNodes = hasByPasNodes || firstInnerResult.HasByPassNodes;
hasByPasNodes = firstInnerResult.HasByPassNodes;
break;
default:
throw new InvalidOperationException("unable to apply repeater to " + innerClause.GetType().Name);
}

if (firstInnerResult != null && !firstInnerResult.IsError)
if (!firstInnerResult.IsError)
{
manyNode.Add(firstInnerResult.Root);
lastInnerResult = firstInnerResult;
Expand All @@ -166,11 +160,7 @@ public SyntaxParseResult<IN> ParseOneOrMore(IList<Token<IN>> tokens, OneOrMoreCl
}
else
{
if (firstInnerResult != null)
{
innerErrors.AddRange(firstInnerResult.Errors);
}

innerErrors.AddRange(firstInnerResult.Errors);
isError = true;
}

Expand Down

0 comments on commit 754f7e2

Please sign in to comment.