Beispiel #1
0
        private static bool TryGetCodePoint(Scanner scanner, out int codePoint)
        {
            codePoint = 0;
            var validCodePoint = false;

            var highSurrogate = scanner.ReadChar();
            if (highSurrogate > 0 && char.IsHighSurrogate((char) highSurrogate))
            {
                var lowSurrogate = scanner.ReadChar();
                if (lowSurrogate > 0 && char.IsLowSurrogate((char) lowSurrogate))
                {
                    codePoint = char.ConvertToUtf32((char) highSurrogate, (char) lowSurrogate);
                    validCodePoint = true;
                }
                else
                {
                    scanner.Position -= 2;
                }
            }
            else
            {
                scanner.Position--;
            }

            return validCodePoint;
        }
Beispiel #2
0
		public GrammarMatch(Grammar grammar, Scanner scanner, int index, int length, MatchCollection matches, int errorIndex, int childErrorIndex, IEnumerable<Parser> errors)
			: base(grammar.Name, grammar, scanner, index, length, matches)
		{
			this.errors = errors;
			this.ErrorIndex = errorIndex;
			this.ChildErrorIndex = childErrorIndex;
		}
Beispiel #3
0
		internal ParseArgs(Grammar grammar, Scanner scanner)
		{
			Grammar = grammar;
			Scanner = scanner;
		}
Beispiel #4
0
		public MatchCollection Matches(Scanner scanner)
		{
			scanner.ThrowIfNull("scanner");
			var matches = new MatchCollection();
			var eof = scanner.IsEof;
			while (!eof)
			{
				var match = Match(scanner);
				if (match.Success)
				{
					matches.AddRange(match.Matches);
					eof = scanner.IsEof;
				}
				else
					eof = scanner.Advance(1) < 0;
			}
			return matches;
		}
Beispiel #5
0
		public GrammarMatch Match(Scanner scanner)
		{
			//scanner.ThrowIfNull("scanner");
			var args = new ParseArgs(this, scanner);

			if (!initialized)
				Initialize();
			Parse(args);
			var root = args.Root;

			if (root.Success && EnableMatchEvents)
			{
				root.TriggerPreMatch();
				root.TriggerMatch();
			}
			return root;
		}