55 lines
1.1 KiB
C#
55 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
namespace lexer.match
|
|
{
|
|
public class Sequence : Matchable
|
|
{
|
|
public List<Matchable> matchables = new List<Matchable>();
|
|
|
|
public Sequence()
|
|
{
|
|
}
|
|
public Sequence(String name)
|
|
:base(name){}
|
|
|
|
public void addMatchable(Matchable matchable){
|
|
this.matchables.Add(matchable);
|
|
}
|
|
public Matchable[] Matchables { get { return this.matchables.ToArray(); } }
|
|
|
|
public override MatchedPart[] Match(buffer.CharacterBuffer chbuffer)
|
|
{
|
|
List<MatchedPart> matchedParts = new List<MatchedPart>();
|
|
chbuffer.Push();
|
|
|
|
foreach (Matchable m in matchables){
|
|
MatchedPart[] mparts = m.MatchNoticeable(chbuffer);
|
|
if (mparts == null){
|
|
chbuffer.Pop();
|
|
return null;
|
|
}
|
|
matchedParts.AddRange(mparts);
|
|
chbuffer.Position += mparts.MatchedLength();
|
|
}
|
|
|
|
chbuffer.Pop();
|
|
return matchedParts.ToArray();
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.Append("( ");
|
|
foreach (Matchable m in this.matchables){
|
|
sb.Append(m.ToString(true));
|
|
sb.Append(' ');
|
|
}
|
|
sb.Append(")");
|
|
return sb.ToString();
|
|
}
|
|
|
|
}
|
|
}
|