コード例 #1
0
ファイル: Regex.cs プロジェクト: mbarbon/language-p-net
        private void StartCapture(ref RxContext cxt, int group)
        {
            for (int i = cxt.LastOpenCapture + 1; i < group; ++i)
                cxt.Captures[i].Start = cxt.Captures[i].End = -1;

            cxt.Captures[group].Start = cxt.Pos;
            cxt.Captures[group].End = -1;

            if (cxt.LastOpenCapture < group)
                cxt.LastOpenCapture = group;
        }
コード例 #2
0
ファイル: Regex.cs プロジェクト: mbarbon/language-p-net
        private void SaveGroups(ref RxContext cxt, int start, int end,
                                bool clear, out RxSavedGroups groups)
        {
            groups.Start = start;
            groups.LastOpenCapture = cxt.LastOpenCapture;
            groups.LastClosedCapture = cxt.LastClosedCapture;
            groups.Data = new RxCapture[end - start];

            for (int i = start; i < end; ++i)
            {
                if (clear || cxt.Captures.Length <= i)
                    groups.Data[i - start].Start = groups.Data[i - start].End = -1;
                else
                {
                    groups.Data[i - start] = cxt.Captures[i];
                }
            }
        }
コード例 #3
0
ファイル: Regex.cs プロジェクト: mbarbon/language-p-net
        private void EndCapture(ref RxContext cxt, int group)
        {
            cxt.Captures[group].End = cxt.Pos;

            cxt.LastClosedCapture = group;
        }
コード例 #4
0
ファイル: Regex.cs プロジェクト: mbarbon/language-p-net
        private void RestoreGroups(ref RxContext cxt, ref RxSavedGroups groups)
        {
            if (groups.Data == null)
                return;

            for (int i = 0; i < groups.Data.Length; ++i)
                cxt.Captures[i + groups.Start] = groups.Data[i];

            cxt.LastOpenCapture = groups.LastOpenCapture;
            cxt.LastClosedCapture = groups.LastClosedCapture;
        }
コード例 #5
0
ファイル: Regex.cs プロジェクト: mbarbon/language-p-net
        private int Backtrack(ref RxContext cxt)
        {
            if (cxt.States.Count > 0)
            {
                var btState = cxt.States[cxt.States.Count - 1];

                cxt.States.RemoveAt(cxt.States.Count - 1);
                cxt.Pos = btState.Pos;
                int index = btState.Target;

                if (index >= 0)
                {
                    if (btState.Group >= 0)
                        cxt.Groups.RemoveRange(btState.Group, cxt.Groups.Count - btState.Group);

                    RestoreGroups(ref cxt, ref btState.Groups);

                    return index;
                }
            }

            if (cxt.StateBacktrack.Count > 0)
            {
                int btIdx = cxt.StateBacktrack[cxt.StateBacktrack.Count - 1];

                cxt.StateBacktrack.RemoveAt(cxt.StateBacktrack.Count - 1);
                cxt.States.RemoveRange(btIdx, cxt.States.Count - btIdx);
                if (cxt.Groups.Count > 0)
                    cxt.Groups.RemoveAt(cxt.Groups.Count - 1);

                return Backtrack(ref cxt);
            }
            else
            {
                return -1;
            }
        }