/// <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; }
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; }
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; }
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; }
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; }
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(); } }
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; }
public string Write(Parser parser) { return Writer.WriteParser(this, parser); }
public void Push(Parser parser) { Parsers.Push(parser); Level += 1; }
public void Add(Parser parser, Parser newParser) { clones.Add(parser, newParser); }
/// <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; }
public UnaryParser(Parser inner) { this.Inner = inner; }
public UnaryParser(string name, Parser inner) { this.Name = name; this.Inner = inner; }
protected UnaryParser(UnaryParser other, ParserCloneArgs args) : base(other, args) { Inner = args.Clone(other.Inner); }
/// <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)); } }
/// <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)); } }
public ParserReplaceArgs(Parser searchParser, Parser replaceParser) { this.SearchParser = searchParser; this.ReplaceParser = replaceParser; }
/// <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) { }
/// <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; }