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 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 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; }
/// <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; }
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(); }
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; }
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(); } }
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; }
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 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); }
protected SequenceParser(SequenceParser other, ParserCloneArgs chain) : base(other, chain) { Separator = chain.Clone(other.Separator); }
/// <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 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 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(); } }
public ExceptParser(Parser inner, Parser except) { this.Inner = inner; this.Except = except; }
public SequenceParser(params Parser[] sequence) : base(sequence) { Separator = DefaultSeparator; }
public SequenceParser(IEnumerable<Parser> sequence) : base(sequence) { Separator = DefaultSeparator; }
public SequenceParser() { Separator = DefaultSeparator; }
public void Push(Parser parser) { Parsers.Push(parser); Level += 1; }
/// <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 string Write(Parser parser) { return Writer.WriteParser(this, parser); }
public GroupParser(Parser startEnd) : this(startEnd, startEnd, null) { }
public void Add(Parser parser, Parser newParser) { clones.Add(parser, newParser); }
public GroupParser(Parser start, Parser end, Parser line = null) { this.start = start; this.end = end; this.line = line; SetLine(); SetBlock(); SetInner(); }
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); }
protected ExceptParser(ExceptParser other, ParserCloneArgs args) : base(other, args) { Except = args.Clone(other.Except); }