Esempio n. 1
0
        /// <summary>
        /// Creates an Expression from a user-hostile representation of the expression. In that representation,
        /// we have guids and we have rote strings.
        /// </summary>
        /// <param name="uh">The user-hostile representation of the expression.</param>
        /// <param name="directory">The directory from which the Expression Elements that are referenced here by guid, come.</param>
        /// <param name="owner">The owner of the expression - usually, the Transition to which it is attached.</param>
        /// <returns>The newly-created expression.</returns>
        public static Expression FromUh(string uh, ParticipantDirectory directory, object owner)
        {
            Expression expression = new Expression(owner);

            expression.m_participantDirectory = directory;

            int cursor = 0;

            foreach (Match match in _guidFinder.Matches(uh))
            {
                if (match.Index != cursor)
                {
                    expression.m_elements.Add(new RoteString(uh.Substring(cursor, (match.Index - cursor))));
                    cursor = match.Index;
                }

                Guid guid = new Guid(match.Value);
                cursor += match.Value.Length;

                if (directory.Contains(guid))
                {
                    expression.m_elements.Add(directory[guid]);
                }
                else
                {
                    expression.m_elements.Add(new UnknownReferenceElement(guid));
                    expression.m_hasUnknowns = true;
                }
            }

            if (cursor != uh.Length)
            {
                expression.m_elements.Add(new RoteString(uh.Substring(cursor)));
            }

            return(expression);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an Expression from a user-friendly representation of the expression. In that representation,
        /// a macro is expressed with a leading &quot;'μ&quot;, as in 'μPreviousComplete' ...
        /// </summary>
        /// <param name="uf">Thr user-friendly representation of the expression from which it will be created.</param>
        /// <param name="directory">The directory into which the Expression Elements that are created from this
        /// representation will be stored.</param>
        /// <param name="owner">The owner of the expression - usually, the Transition to which it is attached.</param>
        /// <returns>The newly-created expression.</returns>
        public static Expression FromUf(string uf, ParticipantDirectory directory, object owner)
        {
            Expression expression = new Expression(owner);

            expression.m_participantDirectory = directory;

            int cursor = 0;

            foreach (Match match in _singQuotes.Matches(uf))
            {
                if (match.Value.StartsWith(Macro.MACRO_START))
                {
                    Macro macro = (Macro)directory[match.Value.Trim('\'')];
                    expression.m_elements.Add(macro);
                    cursor = match.Index + match.Value.Length;
                }
                else
                {
                    expression.m_elements.Add(new RoteString(uf.Substring(cursor, (match.Index - cursor + 1))));
                    string token = match.Value.Substring(1, match.Value.Length - 2);
                    if (token.Contains("/"))
                    {
                        int slashNdx = token.IndexOf('/');
                        expression.m_elements.Add(directory.RegisterMapping(token.Substring(0, slashNdx)));
                        expression.m_elements.Add(new RoteString(token.Substring(slashNdx)));
                        cursor = match.Index + match.Value.Length - 1;
                    }
                    else
                    {
                        expression.m_elements.Add(directory.RegisterMapping(token));
                        expression.m_elements.Add(new RoteString(match.Value.Substring(match.Value.Length - 1, 1)));
                        cursor = match.Index + match.Value.Length;
                    }
                }
            }

            if (cursor != uf.Length)
            {
                expression.m_elements.Add(new RoteString(uf.Substring(cursor)));
            }

            List <ExpressionElement> tmp = new List <ExpressionElement>(expression.m_elements);

            expression.m_elements.Clear();

            #region Consolidate sequential RoteString elements.

            StringBuilder sb = new StringBuilder();
            foreach (ExpressionElement ee in tmp)
            {
                if (!ee.GetType().Equals(typeof(RoteString)))
                {
                    if (sb.Length > 0)
                    {
                        expression.m_elements.Add(new RoteString(sb.ToString()));
                        sb = new StringBuilder();
                    }

                    expression.m_elements.Add(ee);
                }
                else
                {
                    sb.Append(ee);
                }
            }

            if (sb.Length > 0)
            {
                expression.m_elements.Add(new RoteString(sb.ToString()));
            }

            #endregion

            return(expression);
        }