예제 #1
0
        public PatternRoot Deserialize(CodeFile data)
        {
            if (string.IsNullOrEmpty(data.Code))
            {
                throw new ParsingException(data, message: "Pattern value can not be empty.");
            }

            var parser = new DslAntlrParser()
            {
                Logger = Logger
            };
            var converter = new DslUstConverter
            {
                Logger = Logger,
                PatternExpressionInsideStatement = PatternExpressionInsideStatement,
                Data = data
            };

            DslParser.PatternContext patternContext = parser.Parse(data.Code);

            PatternRoot patternNode = converter.Convert(patternContext);

            patternNode.CodeFile = data;

            var preprocessor = new PatternNormalizer()
            {
                Logger = Logger
            };

            patternNode = preprocessor.Normalize(patternNode);

            return(patternNode);
        }
예제 #2
0
        public void Process_Dsl_EqualsToHardcoded(string fileName)
        {
            string data      = File.ReadAllText(Path.Combine(TestUtility.TestsDataPath, fileName));
            var    logger    = new TestLogger();
            var    processor = new DslProcessor {
                Logger = logger, PatternExpressionInsideStatement = false
            };
            PatternRoot result = processor.Deserialize(new TextFile(data)
            {
                PatternKey = fileName
            });

            if (fileName == "DebugInfo.pattern")
            {
                new HashSet <Language> {
                    Language.Php
                };
            }
            Assert.AreEqual(0, logger.ErrorCount, logger.ErrorsString);

            string      patternName    = Path.GetFileNameWithoutExtension(fileName);
            PatternRoot defaultPattern = patterns.FirstOrDefault(p => p.DebugInfo.StartsWith(patternName));

            if (defaultPattern == null)
            {
                Assert.Inconclusive($"Pattern {patternName} does not exists in DefaultPatternRepository");
            }

            var patternNormalizer = new PatternNormalizer();

            defaultPattern = patternNormalizer.Normalize(defaultPattern);

            Assert.AreEqual(defaultPattern.Node, result.Node);
        }