Пример #1
0
		public UntilParser(Parser inner, int minimum, int maximum = Int32.MaxValue, bool skip = false, bool capture = false)
			: base(null, inner)
		{
			this.Minimum = minimum;
			this.Maximum = maximum;
			this.Capture = capture;
			this.Skip = skip;
		}
Пример #2
0
		public RepeatParser(Parser inner, int minimum, int maximum = Int32.MaxValue, Parser until = null)
			: base(null, inner)
		{
			this.Minimum = minimum;
			this.Maximum = maximum;
			this.Until = until;
			Separator = DefaultSeparator;
		}
Пример #3
0
 public EditorAdapter(LanguageData language) {
   _parser = new Parsing.Parser(language); 
   _scanner = _parser.Scanner;
   _colorizerThread = new Thread(ColorizerLoop);
   _colorizerThread.IsBackground = true;
   _parserThread = new Thread(ParserLoop);
   _parserThread.IsBackground = true;
 }
Пример #4
0
		/// <summary>
		/// Pushes the specified parser onto the chain
		/// </summary>
		/// <param name="parser">Parser to push</param>
		/// <returns>True if the parser was added to the chain, false if it already exists in the chain</returns>
		public bool Push(Parser parser)
		{
			if (!parents.Contains(parser))
			{
				parents.Add(parser);
				return true;
			}
			return false;
		}
Пример #5
0
		protected GroupParser(GroupParser other, ParserCloneArgs chain)
			: base(other, chain)
		{
			this.line = chain.Clone(other.line);
			this.start = chain.Clone(other.start);
			this.end = chain.Clone(other.end);
			SetLine();
			SetBlock();
			SetInner();
		}
Пример #6
0
		void SetInner()
		{
			if (lineSeq != null && blockSeq != null)
				groupParser = blockSeq | lineSeq;
			else if (lineSeq != null)
				groupParser = lineSeq;
			else if (blockSeq != null)
				groupParser = blockSeq;
			else
				groupParser = null;
		}
Пример #7
0
		public Parser Clone(Parser parser)
		{
			if (parser == null)
				return null;
			Parser newParser;
			if (!clones.TryGetValue(parser, out newParser))
			{
				newParser = parser.Clone(this);
				clones[parser] = newParser;
			}
			return newParser;
		}
Пример #8
0
		public override void Initialize(ParserInitializeArgs args)
		{
			base.Initialize(args);
			if (args.Push(this))
			{
				if (Separator != null)
					Separator.Initialize(args);
				if (Until != null)
					Until.Initialize(args);
				separator = Separator ?? args.Grammar.Separator;
				skipUntilMatches = (Until != null && (Until.Name != null || Until.Children().Any(r => r.Name != null)));
				args.Pop();
			}
		}
Пример #9
0
		void CreateSeparator()
		{
			var alt = new AlternativeParser();
			var p = Comment;
			if (p != null)
				alt.Items.Add(p);
			p = Whitespace;
			if (p != null)
				alt.Items.Add(p);
			if (alt.Items.Count == 0)
				separator = null;
			else
				separator = -alt;
		}
Пример #10
0
		public string GenerateName(Parser parser, string name = null)
		{
			string cachedName;
			if (!objectNames.TryGetValue(parser, out cachedName))
			{
				if (name != null)
				{
					cachedName = name;
					var count = 1;
					while (objectNames.Values.Contains(cachedName))
					{
						cachedName = name + count++;
					}
				}
				else
					cachedName = GenerateName(parser.GetType());
				objectNames[parser] = cachedName;
			}
			return cachedName;
		}
Пример #11
0
		public ParserContainsArgs(Parser parser)
		{
			this.Parser = parser;
		}
Пример #12
0
		public UnaryParser(Parser inner)
		{
			this.Inner = inner;
		}
Пример #13
0
		public UnaryParser(string name, Parser inner)
		{
			this.Name = name;
			this.Inner = inner;
		}
Пример #14
0
		protected UnaryParser(UnaryParser other, ParserCloneArgs args)
			: base(other, args)
		{
			Inner = args.Clone(other.Inner);
		}
Пример #15
0
		protected SequenceParser(SequenceParser other, ParserCloneArgs chain)
			: base(other, chain)
		{
			Separator = chain.Clone(other.Separator);
		}
Пример #16
0
		/// <summary>
		/// Pops a succesful named match node, and adds it to the parent match node
		/// </summary>
		/// <param name="parser">Parser with the name to add to the match tree</param>
		/// <param name="index">Index of the start of the match</param>
		/// <param name="length">Length of the match</param>
		public void PopMatch(Parser parser, int index, int length)
		{
			// always successful here, assume at least two or more nodes
			var last = nodes.Pop();

			if (nodes.Count > 0)
			{
				var node = nodes.Last;
				if (node == null)
				{
					node = new MatchCollection();
					nodes.Last = node;
				}
				node.Add(new Match(parser, Scanner, index, length, last));
			}
		}
Пример #17
0
		/// <summary>
		/// Adds an error for the specified parser at the current position
		/// </summary>
		/// <param name="parser">Parser to add the error for</param>
		public void AddError(Parser parser)
		{
			var pos = Scanner.Position;
			if (pos > errorIndex)
			{
				errorIndex = pos;
				errors.Clear();
				errors.Add(parser);
			}
			else if (pos == errorIndex)
			{
				errors.Add(parser);
			}
			if (pos > childErrorIndex)
				childErrorIndex = pos;
		}
Пример #18
0
		public override void Initialize(ParserInitializeArgs args)
		{
			base.Initialize(args);
			separator = Separator ?? args.Grammar.Separator;
			if (Items.Count == 0)
				throw new InvalidOperationException("There are no items in this sequence");
			if (args.Push(this))
			{
				var leftItem = Items[0];
				if (leftItem != null)
				{
					foreach (var parent in args.RecursionFixes)
					{
						if (leftItem.IsLeftRecursive(parent))
						{
							Items[0] = new EmptyParser();
							break;
						}
					}
				}
				foreach (var item in Items.Where(r => r != null))
				{
					item.Initialize(args);
				}

				if (Separator != null)
					Separator.Initialize(args);

				args.Pop();
			}
		}
Пример #19
0
		public ExceptParser(Parser inner, Parser except)
		{
			this.Inner = inner;
			this.Except = except;
		}
Пример #20
0
		public SequenceParser(params Parser[] sequence)
			: base(sequence)
		{
			Separator = DefaultSeparator;
		}
Пример #21
0
		public SequenceParser(IEnumerable<Parser> sequence)
			: base(sequence)
		{
			Separator = DefaultSeparator;
		}
Пример #22
0
		public SequenceParser()
		{
			Separator = DefaultSeparator;
		}
Пример #23
0
		public void Push(Parser parser)
		{
			Parsers.Push(parser);
			Level += 1;
		}
Пример #24
0
		/// <summary>
		/// Adds a match to the current result match node
		/// </summary>
		/// <remarks>
		/// This is used to add a parse match to the result match tree
		/// </remarks>
		/// <param name="parser">Parser for the match</param>
		/// <param name="index">Index of the start of the match</param>
		/// <param name="length">Length of the match</param>
		public void AddMatch(Parser parser, int index, int length)
		{
			if (nodes.Count > 0)
			{
				var node = nodes.Last;
				if (node == null)
				{
					node = new MatchCollection();
					nodes.Last = node;
				}
				node.Add(new Match(parser, Scanner, index, length));
			}
		}
Пример #25
0
		public string Write(Parser parser)
		{
			return Writer.WriteParser(this, parser);
		}
Пример #26
0
		public GroupParser(Parser startEnd)
			: this(startEnd, startEnd, null)
		{
		}
Пример #27
0
		public void Add(Parser parser, Parser newParser)
		{
			clones.Add(parser, newParser);
		}
Пример #28
0
		public GroupParser(Parser start, Parser end, Parser line = null)
		{
			this.start = start;
			this.end = end;
			this.line = line;
			SetLine();
			SetBlock();
			SetInner();
		}
Пример #29
0
		public override IEnumerable<Parser> Children(ParserChildrenArgs args)
		{
			var items = new Parser[] { start, end, line }.Where(r => r != null);
			var childItems = items.SelectMany(r => r.Children(args));
			return items.Concat(childItems);
		}
Пример #30
0
		protected ExceptParser(ExceptParser other, ParserCloneArgs args)
			: base(other, args)
		{
			Except = args.Clone(other.Except);
		}