Ejemplo n.º 1
0
        /// <summary>
        /// Every directive can have a single TakeRest directive.
        ///
        /// This takes the remainder of the input string, and places it into the field
        /// or property specified by <paramref name="member"/>.
        ///
        /// Nothing can follow a TakeRest directive except an Else.
        /// </summary>
        public static FSTemplate <T> TakeRest <T>(this FSTemplate <T> template, MemberInfo member, string format = null) where T : class
        {
            ValidateMember <T>(member, format);

            return(template.Append(new FTakeRest <T> {
                Into = member, Format = format
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Backtracks until <paramref name="until"/> is encountered in the string.
        ///
        /// The current index will be placed after the found string.
        ///
        /// If <paramref name="until"/> is not found, the directive fails.
        /// </summary>
        public static FSTemplate <T> Back <T>(this FSTemplate <T> template, string until) where T : class
        {
            ValidateNeedle(until, "until");

            return(template.Append(new FMoveBackUntil <T> {
                Until = until
            }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Backtracks a certain number of characters in the string.
        ///
        /// If the current index into the string is moved out of bounds,
        /// the directive fails.
        /// </summary>
        public static FSTemplate <T> Back <T>(this FSTemplate <T> template, int n) where T : class
        {
            if (n <= 0)
            {
                throw new ArgumentException("Back expects a positive, non-zero, value; found [" + n + "]");
            }

            return(template.Append(new FMoveN <T> {
                N = -1 * n
            }));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Concatenate one series of directives with another.
 ///
 /// Will error if multiple TakeRest or Else directives
 /// are defined by the union of the two series.
 /// </summary>
 public static FSTemplate <T> Append <T>(this FSTemplate <T> left, FSTemplate <T> right) where T : class
 {
     return(left.Append(right));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Take a specific number of characters from the input string, parse them, and put
 /// them into the given property on T.
 ///
 /// Expects a positive, non-zero n.
 /// </summary>
 public static FSTemplate <T> Take <T>(this FSTemplate <T> template, int n, MemberInfo into, string format = null) where T : class
 {
     return(template.Append(Take <T>(n, into, format)));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Advances a certain number of characters in the string.
 ///
 /// If the current index into the string is moved out of bounds,
 /// the directive fails.
 /// </summary>
 public static FSTemplate <T> Skip <T>(this FSTemplate <T> template, int n) where T : class
 {
     return(template.Append(Skip <T>(n)));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Every set of directives can have a single Else directive.
 ///
 /// If any directive fails (expected string not found, moves before the start of the input string, or past
 /// the end) the Else directive will be invoked.
 ///
 /// The Else directive must be the last one to appear.
 /// </summary>
 public static FSTemplate <T> Else <T>(this FSTemplate <T> template, Action <string, T> call) where T : class
 {
     return(template.Append(new FElse <T> {
         Call = call
     }));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Takes characters from the input string, and puts them in the property
 /// or field referenced by <paramref name="member"/> until <paramref name="needle"/> is encountered.
 ///
 /// <paramref name="needle"/> is not placed in <paramref name="member"/>.
 ///
 /// Subsequent directives begin after <paramref name="needle"/>
 ///
 /// If <paramref name="needle"/> is not found, any Else directive is run.
 /// </summary>
 public static FSTemplate <T> Take <T>(this FSTemplate <T> template, string until, MemberInfo member, string format = null) where T : class
 {
     return(template.Append(Take <T>(until, member, format)));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Advance in the string until <paramref name="needle"/> is encountered.
 ///
 /// Subsequent directives begin after <paramref name="needle"/>.
 ///
 /// If <paramref name="needle"/> is not found, any Else directive is run.
 /// </summary>
 public static FSTemplate <T> Until <T>(this FSTemplate <T> template, string needle) where T : class
 {
     return(template.Append(Until <T>(needle)));
 }