Get() public méthode

public Get ( ) : void
Résultat void
Exemple #1
0
        public RantAction Compile()
        {
            var parser     = Parser.Get <SequenceParser>();
            var stack      = new Stack <IEnumerator <Parser> >();
            var actionList = new List <RantAction>();

            _nextActionCallback = a => actionList.Add(a);

            stack.Push(parser.Parse(this, _nextContext, _reader, _nextActionCallback));

top:
            while (stack.Any())
            {
                var p = stack.Peek();

                while (p.MoveNext())
                {
                    if (p.Current == null)
                    {
                        continue;
                    }

                    stack.Push(p.Current.Parse(this, _nextContext, _reader, _nextActionCallback));
                    goto top;
                }

                stack.Pop();
            }

            return(new RASequence(actionList, _source));
        }
        static void Main(string[] args)
        {
            Parser parser = new Parser(new string[] {
                "normal1",
                "normal2",
                "-abc",
                "--long1",
                "value1_long1",
                "value2_long1",
                "--long2=value1_long2",
                "normal3",
                "-d",
                "-e",
                "normal4",
                "--flag"
            });

            Assert(parser.Exists(""));
            Assert(parser.Exists(null, 'a'));
            Assert(parser.Exists(null, 'b'));
            Assert(parser.Exists(null, 'c'));
            Assert(parser.Exists(null, 'd'));
            Assert(parser.Exists(null, 'e'));
            Assert(!parser.Exists(null, 'f'));
            Assert(parser.Exists("blah", 'a'));
            Assert(parser.Exists("long1", 'z'));
            Assert(parser.Exists("long1"));
            Assert(parser.Exists("long2"));
            Assert(!parser.Exists("long3"));
            Assert(!parser.Exists("long3", 'z'));
            Assert(parser.Exists(""));
            Assert(parser.SwitchExists('b'));
            Assert(!parser.SwitchExists('z'));
            Assert(parser.OptionExists(""));
            Assert(parser.OptionExists("long1"));
            Assert(!parser.OptionExists("long3"));
            Assert(parser.SwitchExistsOrValueIs('a', "long2", "value1_long1"));
            Assert(!parser.SwitchExistsOrValueIs('z', "long2", "value1_long1"));
            Assert(parser.SwitchExistsOrValueIs('z', "long2", "value1_long2"));
            Assert(!parser.SwitchExistsOrValueIs('z', "long2", "value1_long1"));
            Assert(parser.SwitchExistsOrValueIs('a', "long3", "value1_long1"));
            Assert(!parser.SwitchExistsOrValueIs('z', "long3", "value1_long1"));
            Assert(parser.Get("") == "normal1");
            Assert(parser.GetAll("")[0] == "normal1");
            Assert(parser.GetAll("")[1] == "normal2");
            Assert(parser.GetAll("")[2] == "normal3");
            Assert(parser.GetAll("")[3] == "normal4");
            Assert(parser.GetAll("").Length == 4);
            Assert(parser.GetAll("long1")[0] == "value1_long1");
            Assert(parser.GetAll("long1")[1] == "value2_long1");
            Assert(parser.GetAll("long1").Length == 2);
            Assert(parser.GetAll("long2")[0] == "value1_long2");
            Assert(parser.GetAll("long2").Length == 1);
            Assert(parser.OptionExists("flag"));
        }
Exemple #3
0
        public RST Compile()
        {
            try
            {
                var parser     = Parser.Get <SequenceParser>();
                var stack      = new Stack <IEnumerator <Parser> >();
                var actionList = new List <RST>();
                _contextStack.Push(CompileContext.DefaultSequence);

                _nextActionCallback = a => actionList.Add(a);

                stack.Push(parser.Parse(this, NextContext, _reader, _nextActionCallback));

top:
                while (stack.Count > 0)
                {
                    var p = stack.Peek();

                    while (p.MoveNext())
                    {
                        if (p.Current == null)
                        {
                            continue;
                        }

                        stack.Push(p.Current.Parse(this, NextContext, _reader, _nextActionCallback));
                        goto top;
                    }

                    stack.Pop();
                }

                if (_errors?.Count > 0)
                {
                    throw new RantCompilerException(_sourceName, _errors);
                }

                return(new RstSequence(actionList, _reader.BaseLocation));
            }
            catch (RantCompilerException)
            {
                throw;
            }
#if !DEBUG
            catch (Exception ex)
            {
                throw new RantCompilerException(_sourceName, _errors, ex);
            }
#endif
        }
internal static int ParseContract (Module assem, string text, out Expression expression)
{
  Debug.Assert(assem != null);
  currentAssembly = assem;

  System.IO.MemoryStream ms = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(text), false);
  Errors errors = new Errors();
  Scanner scanner = new Scanner(ms, errors, "");

  Parser parser = new Parser(scanner, errors);
  parser.Get();
  parser.Expr(out expression);

  currentMethodContract = null;
  currentMethod = null;
  currentAssembly = null;

  if (parser.errors.count == 0)
  {
     return 0;
  }
  else
  {
     expression = null;
     return parser.errors.count;
  }
}