예제 #1
0
        //--- Methods ---
        public IParser Preprocess(string source)
        {
            var inputStream  = YamlParser.Parse(source);
            var outputStream = new YamlStream {
                Start     = inputStream.Start,
                Documents = inputStream.Documents
                            .Select(inputDocument => Preprocess(inputDocument))
                            .ToList(),
                End = inputStream.End
            };
            var parsingEvents = new List <ParsingEvent>();

            outputStream.AppendTo(parsingEvents);
            return(new YamlParsingEventsParser(parsingEvents));
        }
        //--- Methods ---
        public ModuleNode Convert(string source, string selector)
        {
            // parse text into a pre-processed YAML token stream
            IParser yamlParser;

            try {
                _selector = ":" + (selector ?? "Default");
                var inputStream  = YamlParser.Parse(source);
                var outputStream = new YamlStream {
                    Start     = inputStream.Start,
                    Documents = inputStream.Documents
                                .Select(inputDocument => Preprocess(inputDocument))
                                .ToList(),
                    End = inputStream.End
                };
                var parsingEvents = new List <ParsingEvent>();
                outputStream.AppendTo(parsingEvents);
                yamlParser = new YamlParsingEventsParser(parsingEvents);
            } catch (Exception e) {
                LogError(e);
                return(null);
            }

            // parse YAML token stream into module AST
            try {
                return(new DeserializerBuilder()
                       .WithNamingConvention(new PascalCaseNamingConvention())
                       .WithNodeDeserializer(new CloudFormationFunctionNodeDeserializer())
                       .WithCloudFormationFunctions()
                       .Build()
                       .Deserialize <ModuleNode>(yamlParser));
            } catch (YamlDotNet.Core.YamlException e) {
                LogError($"parsing error near {e.Message}");
            } catch (Exception e) {
                LogError(e);
            }
            return(null);
        }