Пример #1
0
        public override string WriteParseCode(TextWriter writer, ScriptParserGenerator generator)
        {
            IList <string>   firsts     = _innerExpression.GetFirstTerminals(generator);
            IList <string>   followings = this.GetFollowingTerminals(generator);
            HashSet <string> firstSet   = new HashSet <string>(firsts);

            foreach (string following in followings)
            {
                if (firstSet.Contains(following))
                {
                    string context = string.Format("'{0}' の定義", this.RootDefinition.DefinitionName);
                    string message = string.Format("<{1}> の直後の <{0}> は <{1}> によって隠されます", following, this.ToString());
                    generator.Warn(context, message);
                }
            }
            ParameterSignature returnParam   = this.GetReturnParameterSignature(generator);
            ParameterSignature innerParam    = _innerExpression.GetReturnParameterSignature(generator);
            string             innerType     = innerParam.GetTypeName();
            string             innerListType = string.Format("List<{0}>", innerType);
            string             innerListVar;

            writer.WriteLine(generator.GetCodeOfDeclareNew(innerListType, out innerListVar));
            string peek;

            writer.WriteLine(generator.GetCodeOfForPeekLexisIn(firsts, out peek));
            string innerVar = _innerExpression.WriteParseCode(writer, generator);

            writer.WriteLine(generator.GetCodeOfInvoke(innerListVar, "Add", innerVar));
            writer.WriteLine(generator.GetCodeOfCloseBlock());
            string returnType = returnParam.GetTypeName();
            string returnVar;

            writer.WriteLine(generator.GetCodeOfDeclare(returnType, out returnVar));
            writer.WriteLine(generator.GetCodeOfInvokeSubstitute(returnVar, innerListVar, "ToArray"));
            return(returnVar);
        }