Ejemplo n.º 1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Eto.Parse.Grammar"/> class
		/// </summary>
		/// <param name="name">Name of the grammar</param>
		/// <param name="rule">Top level grammar rule</param>
		public Grammar(string name = null, Parser rule = null)
			: base(name, rule)
		{
			CaseSensitive = true;
			EnableMatchEvents = true;
			Optimizations = GrammarOptimizations.CharacterSetAlternations;
		}
Ejemplo n.º 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;
 }
Ejemplo n.º 3
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;
		}
Ejemplo n.º 4
0
		public Parser Replace(Parser parser)
		{
			if (parser == null)
				return null;
			if (ReferenceEquals(parser, SearchParser))
			{
				Debug.WriteLine("Replacing {0} with {1}", SearchParser, ReplaceParser);
				return ReplaceParser;
			}
			parser.Replace(this);
			return parser;
		}
Ejemplo n.º 5
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;
		}
Ejemplo n.º 6
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();
			}
		}
Ejemplo n.º 7
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;
		}
		public ParserContainsArgs(Parser parser)
		{
			this.Parser = parser;
		}
Ejemplo n.º 9
0
		public string Write(Parser parser)
		{
			return Writer.WriteParser(this, parser);
		}
Ejemplo n.º 10
0
		public void Push(Parser parser)
		{
			Parsers.Push(parser);
			Level += 1;
		}
Ejemplo n.º 11
0
		public void Add(Parser parser, Parser newParser)
		{
			clones.Add(parser, newParser);
		}
Ejemplo n.º 12
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;
		}
Ejemplo n.º 13
0
 public UnaryParser(Parser inner)
 {
     this.Inner = inner;
 }
Ejemplo n.º 14
0
 public UnaryParser(string name, Parser inner)
 {
     this.Name = name;
     this.Inner = inner;
 }
Ejemplo n.º 15
0
		protected UnaryParser(UnaryParser other, ParserCloneArgs args)
			: base(other, args)
		{
			Inner = args.Clone(other.Inner);
		}
Ejemplo n.º 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));
			}
		}
Ejemplo n.º 17
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));
			}
		}
Ejemplo n.º 18
0
		public ParserReplaceArgs(Parser searchParser, Parser replaceParser)
		{
			this.SearchParser = searchParser;
			this.ReplaceParser = replaceParser;
		}
Ejemplo n.º 19
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Eto.Parse.Grammar"/> class
		/// </summary>
		/// <param name="rule">Top level grammar rule</param>
		public Grammar(Parser rule)
			: this(null, rule)
		{
		}
Ejemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Eto.Parse.Grammar"/> class
 /// </summary>
 /// <param name="name">Name of the grammar</param>
 /// <param name="rule">Top level grammar rule</param>
 public Grammar(string name = null, Parser rule = null)
     : base(name, rule)
 {
     CaseSensitive = true;
     EnableMatchEvents = true;
 }