public override ParameterSignature GetReturnParameterSignature(ScriptParserGenerator generator) { switch (_literal.Type) { case GeneratorLexType.Terminal: return(new ParameterSignature(generator.GetTerminalName(this.InnerWord), generator.Settings.InputClass)); case GeneratorLexType.Nonterminal: return(new ParameterSignature(ScriptParserGenerator.ConvertCase(this.InnerWord, generator.Settings.NonterminalCaseConversion), generator.GetReturnClassIdentifier(this.InnerWord))); default: throw new NotSupportedException(); } }
public void WriteParseCode(TextWriter writer, ScriptParserGenerator generator) { writer.Write(ScriptParserGenerator.GetAccessibilityString(generator.Settings.ParseMethodAccessibility)); writer.Write(" "); writer.Write(generator.GetReturnClassIdentifier(this.DefinitionName)); writer.Write(" "); writer.Write(generator.GetParseMethodIdentifier(this.DefinitionName)); writer.WriteLine("() {"); generator.IndentCount = 1; generator.InitializeVariableIndex(1); IDictionary <ElementsElement, MethodSignature> methods = this.GetReturnParameterSignaturesAndElements(generator); if (false) { // 普通のコード if (this.Expression.Selection.Candidates.Count >= 2) { IList <string> firsts = this.Expression.Selection.GetFirstTerminals(generator); string peekVar; writer.WriteLine(generator.GetCodeOfPeekOrThrow(this.DefinitionName, firsts, out peekVar)); Dictionary <string, string> usedFirsts = new Dictionary <string, string>(); foreach (ElementsElement elems in this.Expression.Selection.Candidates) { IList <string> innerFirsts = elems.GetFirstTerminals(generator); foreach (string first in innerFirsts) { string usingPoint; if (usedFirsts.TryGetValue(first, out usingPoint)) { string context = string.Format("'{0}' の定義", this.DefinitionName); string message = string.Format("<{1}> 内の <{0}> は <{2}> によって隠されます", first, elems.ToString(), usingPoint); generator.Warn(context, message); } else { usedFirsts[first] = elems.ToString(); } } writer.WriteLine(generator.GetCodeOfIfLexisIn(peekVar, innerFirsts)); List <string> arguments = new List <string>(); foreach (ElementElement elem in elems.Elements) { string var = elem.WriteParseCode(writer, generator); arguments.Add(var); } writer.WriteLine(generator.GetCodeOfReturnMethod(methods[elems].MethodName, arguments)); writer.Write(generator.GetCodeOfCloseBlock()); writer.Write(generator.GetCodeOfSingleElse()); } writer.WriteLine(generator.GetCodeOfOpenBlock()); writer.WriteLine(generator.GetCodeOfThrowNew("System.NotImplementedException", ScriptParserGenerator.EscapeString(this.DefinitionName))); writer.WriteLine(generator.GetCodeOfCloseBlock()); } else { ElementsElement elems = this.Expression.Selection.Candidates.First(); IList <string> innerFirsts = elems.GetFirstTerminals(generator); List <string> arguments = new List <string>(); foreach (ElementElement elem in elems.Elements) { string var = elem.WriteParseCode(writer, generator); arguments.Add(var); } writer.WriteLine(generator.GetCodeOfReturnMethod(methods[elems].MethodName, arguments)); } } else { // 前半部分が同じSelectionをツリー状に探索するようにするために // SelectionSubCandidateを作る List <SelectionSubCandidate> subCandidates = new List <SelectionSubCandidate>(); foreach (ElementsElement candidate in this.Expression.Selection.Candidates) { subCandidates.Add(new SelectionSubCandidate(candidate)); } SelectionSubCandidate.writeParseCodeAux(writer, generator, subCandidates, (candidateAtEmpty, writer2, generator2) => { writer.WriteLine(generator.GetCodeOfReturnMethod(methods[candidateAtEmpty.OriginalElements].MethodName, candidateAtEmpty.TemporaryVariables)); }); } writer.Write("}"); }