Exemple #1
0
        /// <summary>
        /// Creates a new SequenceItem from an input file token.
        /// </summary>
        /// <param name="token">The token, containing a positionrecord's name and some modifiers.</param>
        /// <returns>A SequenceItem created from this token.</returns>
        public static SequenceItem FromToken(string token)
        {
            // List of modifiers that specify details about how the item can be matched.
            List <char> modifiers = new List <char>();

            // Strip the end of the token from its modifiers, and
            // store those modifiers in the list.
            while (isModifier(token[token.Length - 1]))
            {
                modifiers.Add(token[token.Length - 1]);
                token = token.Substring(0, token.Length - 1);
            }
            // If the name still contains any characters that are not alphanumeric,
            // throw an exception.
            if (!isAlphanumeric(token))
            {
                throw new MalformedException(string.Format("Name must be alphanumeric, and all modifiers should appear at the end of the name. This token is invalid: {0}", token));
            }
            SequenceItem rv = new SequenceItem(token);

            rv.Position = PositionParser.GetByName(token);
            rv.parseModifiers(modifiers);
            return(rv);
        }
Exemple #2
0
 /// <summary>
 /// Creates a new SequenceItem with this name.
 /// </summary>
 /// <param name="name">The new sequenceitem's name.</param>
 private SequenceItem(string name)
 {
     Position   = PositionParser.GetByName(name);
     transition = new HashSet <PositionRecord>();
     leniency   = new HashSet <PositionRecord>();
 }