Exemplo n.º 1
0
 public void SaveToFile(ParsingGrammar grammar, string fileName)
 {
     using (var stream = File.OpenWrite(fileName))
     {
         _xs.Serialize(stream, new GrammarType(grammar));
     }
 }
        public IndentedWriter Generate(ParsingGrammar g)
        {
            var mb    = new ModelBuilder(g);
            var model = mb.Complete();

            model.Namespace = string.IsNullOrWhiteSpace(this.Namespace) ? g.Name : this.Namespace;
            model.Public    = this.Public;

            var gen = new ModelSourceCodeGenerator(model);

            return(gen.Generate());
        }
        public ParsingGrammar ToGrammar()
        {
            var g = new ParsingGrammar()
            {
                StartRuleName = this.StartRule,
                SkipRuleName  = this.SkipRule
            };

            foreach (var rule in this.Items)
            {
                g.Add(rule.Name, rule.Item.Apply(XmlExprTypeToParsingExpressionConverter.Instance));
            }

            return(g);
        }
Exemplo n.º 4
0
        private static ParsingGrammar Translate(grammar grammar)
        {
            var g = new ParsingGrammar();

            if (grammar.header.nsName != null)
            {
                g.Name = string.Join(".", grammar.header.nsName.identifiers.Select(s => s.@string));
            }

            g.StartRuleName = grammar.header.identifiers.First().@string;

            if (grammar.header.identifiers.Length > 1)
            {
                g.SkipRuleName = grammar.header.identifiers.Last().@string;
            }

            foreach (var r in grammar.rules)
            {
                g.Add(r.identifier.@string, TranslateSeq(r.exprsSeq));
            }

            return(g);
        }
 public LtlAutomatonTextParser()
 {
     _grammar = DefenitionsGrammar.TryParse(LtlParserResources.SourceGrammarText);
 }
Exemplo n.º 6
0
 public ModelBuilder(ParsingGrammar g)
 {
     _g = g;
 }
 public GrammarType(ParsingGrammar g)
 {
     this.SkipRule  = g.SkipRuleName;
     this.StartRule = g.StartRuleName;
     this.Items     = g.Select(r => new RuleType(r)).ToArray();
 }
Exemplo n.º 8
0
        static DefenitionsGrammar()
        {
            var loader = new Xml.GrammarXmlSerializer();

            _grammar = loader.LoadFromXml(PegResources.defXml);
        }