private void ValidateAll() { //Check rule on all non-terminals StringSet ntList = new StringSet(); foreach (NonTerminal nt in Data.NonTerminals) { if (nt == Data.AugmentedRoot) { continue; //augm root does not count } BnfExpressionData data = nt.Rule.Data; if (data.Count == 1 && data[0].Count == 1 && data[0][0] is NonTerminal) { ntList.Add(nt.Name); } }//foreach if (ntList.Count > 0) { string slist = TextUtils.Cleanup(ntList.ToString(", ")); AddError("Warning: Possible non-terminal duplication. The following non-terminals have rules containing a single non-terminal: \r\n {0}. \r\n" + "Consider merging two non-terminals; you may need to use 'nt1 = nt2;' instead of 'nt1.Rule=nt2'.", slist); } //Check constructors of all nodes referenced in Non-terminals that don't use NodeCreator delegate var ctorArgTypes = new Type[] { typeof(NodeArgs) }; foreach (NonTerminal nt in Data.NonTerminals) { if (nt.NodeCreator == null && nt.NodeType != null) { object ci = nt.NodeType.GetConstructor(ctorArgTypes); if (ci == null) { AddError( @"AST Node class {0} referenced by non-terminal {1} does not have a constructor for automatic node creation. Provide a constructor with a single NodeArgs parameter, or use NodeCreator delegate property in NonTerminal.", nt.NodeType, nt.Name); } } //if } //foreach ntInfo } //method
private void ValidateAll() { //Check rule on all non-terminals StringSet ntList = new StringSet(); foreach (NonTerminal nt in Data.NonTerminals) { if (nt == Data.AugmentedRoot) { continue; //augm root does not count } BnfExpressionData data = nt.Rule.Data; if (data.Count == 1 && data[0].Count == 1 && data[0][0] is NonTerminal) { ntList.Add(nt.Name); } }//foreach if (ntList.Count > 0) { string slist = TextUtils.Cleanup(ntList.ToString(", ")); AddError("Warning: Possible non-terminal duplication. The following non-terminals have rules containing a single non-terminal: \r\n {0}. \r\n" + "Consider merging two non-terminals; you may need to use 'nt1 = nt2;' instead of 'nt1.Rule=nt2'.", slist); } }
public override string ToString() { return(Core.ToString() + " LOOKAHEADS: " + TextUtils.Cleanup(Lookaheads.ToString(" "))); }
private void ReportParserError() { if (_currentToken.Terminal == Grammar.Eof) { ReportError(_currentToken.Location, "Unexpected end of file."); return; } StringList expectedList = GetCurrentExpectedSymbols(); string message = this.Data.Grammar.GetSyntaxErrorMessage(_context, expectedList); if (message == null) { message = "Syntax error" + (expectedList.Count == 0 ? "." : ", expected: " + TextUtils.Cleanup(expectedList.ToString(" "))); } ReportError(_currentToken.Location, message); }
} //Parse #endregion #region Error reporting and recovery private void ReportParseError() { if (_currentToken.Terminal == Grammar.Eof) { _context.ReportError(_currentToken.Location, "Unexpected end of file."); return; } StringSet expectedList = GetCurrentExpectedSymbols(); string message = this.Data.Grammar.GetSyntaxErrorMessage(_context, expectedList); if (message == null) { message = "Syntax error" + (expectedList.Count == 0 ? "." : ", expected: " + TextUtils.Cleanup(expectedList.ToString(" "))); } if (_context.OptionIsSet(CompilerOptions.GrammarDebugging)) { message += " (parser state: " + _currentState.Name + ")"; } _context.Errors.Add(new SyntaxError(_currentToken.Location, message)); }