コード例 #1
0
ファイル: Parser.cs プロジェクト: bartekb96/Regex_proj
    public void pharseSequences()
    {
        string sequence_pattern = @"(?<sequence_type>\S*)\s*::=\s*SEQUENCE\s*{\s*((?<members>.*?)})";
        string member_pattern   = @"(?<type>\S*)\s*(?<class>\S*)(,\s*|(\s\((?<min_range>\d*)..(?<max_range>\d*)\)(,\s*|\s*))|(\s\(SIZE\((?<size>\d*)\)\)(,\s*|\s*))|(\s\(SIZE\((?<min_size>\d*)..(?<max_size>\d*)\)\))(,\s*|\s*)|(\s*}))";

        //---------------NEW SEQUENCE------------------
        DataType sequence;
        string   sequenceType;
        //---------------------------------------------

        //---------------SEQUENCE MEMBER---------------
        DataType sequenceMember;

        string MemberType;
        string MemberClass;
        long   MaxRange;
        long   MinRange;
        int    Size;
        int    MaxSize;
        int    MinSize;

        //---------------------------------------------


        foreach (Match ob in Regex.Matches(content, sequence_pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline))
        {
            sequenceType = Regex.Match(ob.Value, sequence_pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[2].Value;

            sequence = new DataType(sequenceType, "", 0, "", "", 0, 0, 0, 0, 0);

            foreach (Match obj in Regex.Matches(ob.Value, member_pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline))
            {
                //--------------------------------------------------------------------------SETTING MEMBERS PARAMETERS-----------------------------------------------------------
                //---------------------------------------------------------------------------------------------------------------------------------------------------------------
                if (Regex.Match(obj.Value, member_pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[9].Value != "")
                {
                    MemberType  = Regex.Match(obj.Value, member_pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[9].Value;
                    MemberClass = Regex.Match(obj.Value, member_pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[10].Value;
                    Int64.TryParse(Regex.Match(obj.Value, member_pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[12].Value, out MaxRange);
                    Int64.TryParse(Regex.Match(obj.Value, member_pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[11].Value, out MinRange);
                    Int32.TryParse(Regex.Match(obj.Value, member_pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[13].Value, out Size);
                    Int32.TryParse(Regex.Match(obj.Value, member_pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[15].Value, out MaxSize);
                    Int32.TryParse(Regex.Match(obj.Value, member_pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline).Groups[14].Value, out MinSize);

                    sequenceMember = new DataType(MemberType, MemberClass, 0, "", "", Size, MinSize, MaxSize, MinRange, MaxRange);
                    sequence.AddDataTypeToSequence(sequenceMember);
                }
            }

            DataTypesList.Add(sequence);
        }
    }