Example #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;
		}
Example #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;
		}
Example #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;
 }
Example #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;
		}
Example #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();
		}
Example #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;
		}
Example #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;
		}
Example #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();
			}
		}
Example #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;
		}
Example #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;
		}
Example #11
0
		public ParserContainsArgs(Parser parser)
		{
			this.Parser = parser;
		}
Example #12
0
		public UnaryParser(Parser inner)
		{
			this.Inner = inner;
		}
Example #13
0
		public UnaryParser(string name, Parser inner)
		{
			this.Name = name;
			this.Inner = inner;
		}
Example #14
0
		protected UnaryParser(UnaryParser other, ParserCloneArgs args)
			: base(other, args)
		{
			Inner = args.Clone(other.Inner);
		}
Example #15
0
		protected SequenceParser(SequenceParser other, ParserCloneArgs chain)
			: base(other, chain)
		{
			Separator = chain.Clone(other.Separator);
		}
Example #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));
			}
		}
Example #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;
		}
Example #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();
			}
		}
Example #19
0
		public ExceptParser(Parser inner, Parser except)
		{
			this.Inner = inner;
			this.Except = except;
		}
Example #20
0
		public SequenceParser(params Parser[] sequence)
			: base(sequence)
		{
			Separator = DefaultSeparator;
		}
Example #21
0
		public SequenceParser(IEnumerable<Parser> sequence)
			: base(sequence)
		{
			Separator = DefaultSeparator;
		}
Example #22
0
		public SequenceParser()
		{
			Separator = DefaultSeparator;
		}
Example #23
0
		public void Push(Parser parser)
		{
			Parsers.Push(parser);
			Level += 1;
		}
Example #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));
			}
		}
Example #25
0
		public string Write(Parser parser)
		{
			return Writer.WriteParser(this, parser);
		}
Example #26
0
		public GroupParser(Parser startEnd)
			: this(startEnd, startEnd, null)
		{
		}
Example #27
0
		public void Add(Parser parser, Parser newParser)
		{
			clones.Add(parser, newParser);
		}
Example #28
0
		public GroupParser(Parser start, Parser end, Parser line = null)
		{
			this.start = start;
			this.end = end;
			this.line = line;
			SetLine();
			SetBlock();
			SetInner();
		}
Example #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);
		}
Example #30
0
		protected ExceptParser(ExceptParser other, ParserCloneArgs args)
			: base(other, args)
		{
			Except = args.Clone(other.Except);
		}