diff --git a/src/sly/lexer/LexerBuilder.cs b/src/sly/lexer/LexerBuilder.cs index eeb34872..560c1b8c 100644 --- a/src/sly/lexer/LexerBuilder.cs +++ b/src/sly/lexer/LexerBuilder.cs @@ -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)); } diff --git a/src/sly/parser/generator/visitor/EBNFSyntaxTreeVisitor.cs b/src/sly/parser/generator/visitor/EBNFSyntaxTreeVisitor.cs index 1f76b2b3..1f196cf2 100644 --- a/src/sly/parser/generator/visitor/EBNFSyntaxTreeVisitor.cs +++ b/src/sly/parser/generator/visitor/EBNFSyntaxTreeVisitor.cs @@ -150,7 +150,7 @@ private SyntaxVisitorResult Visit(SyntaxNode 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.NewValue(res); diff --git a/src/sly/parser/parser/Parser.cs b/src/sly/parser/parser/Parser.cs index 8dd2bc4f..5af306bd 100644 --- a/src/sly/parser/parser/Parser.cs +++ b/src/sly/parser/parser/Parser.cs @@ -139,7 +139,7 @@ public ParseResult ParseWithContext(IList> tokens, object par foreach (var expecting in byEnding) { var expectingTokens = expecting.SelectMany(x => x.ExpectedTokens ?? new List>()).Distinct(); - var expectedTokens = expectingTokens != null && expectingTokens.Any() ? expectingTokens?.ToArray() : null; + var expectedTokens = expectingTokens.Any() ? expectingTokens?.ToArray() : null; if (expectedTokens != null) { var expected = new UnexpectedTokenSyntaxError(expecting.First().UnexpectedToken, LexemeLabels, I18n, diff --git a/src/sly/parser/parser/llparser/ebnf/EBNFRecursiveDescentSyntaxParser.Expressions.cs b/src/sly/parser/parser/llparser/ebnf/EBNFRecursiveDescentSyntaxParser.Expressions.cs index 7a0d2f99..4dba3b73 100644 --- a/src/sly/parser/parser/llparser/ebnf/EBNFRecursiveDescentSyntaxParser.Expressions.cs +++ b/src/sly/parser/parser/llparser/ebnf/EBNFRecursiveDescentSyntaxParser.Expressions.cs @@ -112,26 +112,22 @@ public virtual SyntaxParseResult ParseInfixExpressionRule(IList> t } var result = new SyntaxParseResult(); - result.IsError = isError; + result.IsError = false; result.Errors = errors; result.EndingPosition = currentPosition; - if (!isError) - { - SyntaxNode node = null; - if (rule.IsSubRule) - node = new GroupSyntaxNode(nonTerminalName, children); - else - node = new SyntaxNode(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 node = null; + if (rule.IsSubRule) + node = new GroupSyntaxNode(nonTerminalName, children); + else + node = new SyntaxNode(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; } diff --git a/src/sly/parser/parser/llparser/ebnf/EBNFRecursiveDescentSyntaxParser.Many.cs b/src/sly/parser/parser/llparser/ebnf/EBNFRecursiveDescentSyntaxParser.Many.cs index 05ad9a74..3843a03a 100644 --- a/src/sly/parser/parser/llparser/ebnf/EBNFRecursiveDescentSyntaxParser.Many.cs +++ b/src/sly/parser/parser/llparser/ebnf/EBNFRecursiveDescentSyntaxParser.Many.cs @@ -50,12 +50,6 @@ public SyntaxParseResult ParseZeroOrMore(IList> tokens, ZeroOrMore manyNode.IsManyValues = true; break; } - case GroupClause _: - manyNode.IsManyGroups = true; - innerResult = ParseNonTerminal(tokens, innerClause as NonTerminalClause, currentPosition, - parsingContext); - hasByPasNodes = hasByPasNodes || innerResult.HasByPassNodes; - break; case ChoiceClause choice: manyNode.IsManyTokens = choice.IsTerminalChoice; manyNode.IsManyValues = choice.IsNonTerminalChoice; @@ -121,12 +115,12 @@ public SyntaxParseResult ParseOneOrMore(IList> tokens, OneOrMoreCl case TerminalClause terminalClause: manyNode.IsManyTokens = true; firstInnerResult = ParseTerminal(tokens, terminalClause, currentPosition, parsingContext); - hasByPasNodes = hasByPasNodes || firstInnerResult.HasByPassNodes; + hasByPasNodes = firstInnerResult.HasByPassNodes; break; case NonTerminalClause nonTerm: { firstInnerResult = ParseNonTerminal(tokens, nonTerm, currentPosition, parsingContext); - hasByPasNodes = hasByPasNodes || firstInnerResult.HasByPassNodes; + hasByPasNodes = firstInnerResult.HasByPassNodes; if (nonTerm.IsGroup) manyNode.IsManyGroups = true; else @@ -137,13 +131,13 @@ public SyntaxParseResult ParseOneOrMore(IList> 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; @@ -166,11 +160,7 @@ public SyntaxParseResult ParseOneOrMore(IList> tokens, OneOrMoreCl } else { - if (firstInnerResult != null) - { - innerErrors.AddRange(firstInnerResult.Errors); - } - + innerErrors.AddRange(firstInnerResult.Errors); isError = true; }