Example #1
0
 /// <summary>
 /// Reads until EOF is reached or
 /// until predicate does not get satisfied.
 /// </summary>
 public string ReadWhile(CharPredicate predicate)
 {
     m_Buffer.Clear();
     while (!EndOfStream() && predicate(PeekNext()))
     {
         m_Buffer.Add(ReadNext());
     }
     return(new string(m_Buffer.ToArray()));
 }
Example #2
0
            /// <summary>
            /// Skips as long as predicate is dissatisfied or EOF is reached
            /// </summary>
            public int SkipUntil(CharPredicate predicate)
            {
                int n = 0;

                while (!EndOfStream() && !predicate(PeekNext()))
                {
                    SkipNext();
                    n++;
                }

                return(n);
            }
        private void InstallLocalPredicates()
        {
            // Input/Output
            _predicates["write/1"]   = new WritePredicate();
            _predicates["writeln/1"] = new WriteLnPredicate();
            _predicates["nl/0"]      = new NlPredicate();
            _predicates["get0/1"]    = new Get0Predicate();
            _predicates["skip/1"]    = new SkipPredicate();
            _predicates["put/1"]     = new PutPredicate();

            // Comparison, numeric
            _predicates["=\\=/2"] = new NotEqualsPredicate();
            _predicates["=:=/2"]  = new EqualsPredicate();
            _predicates[">=/2"]   = new GreaterThanEqualPredicate();
            _predicates[">/2"]    = new GreaterThanPredicate();
            _predicates["=</2"]   = new LessThanEqualPredicate();
            _predicates["</2"]    = new LessThanPredicate();

            // Control
            _predicates["call/1"] = new CallPredicate();

            // Equality
            _predicates["=/2"]   = new UnifyPredicate();
            _predicates["\\=/2"] = new NotUnifiablePredicate();

            // Meta
            _predicates["is/2"]      = new IsPredicate();
            _predicates["atom/1"]    = new AtomPredicate();
            _predicates["bound/1"]   = new BoundPredicate();
            _predicates["char/1"]    = new CharPredicate();
            _predicates["free/1"]    = new FreePredicate();
            _predicates["integer/1"] = new IntegerPredicate();
            _predicates["nonvar/1"]  = new NonVarPredicate();
            _predicates["var/1"]     = new VarPredicate();

            // Object-Oriented Programming
            _predicates["object/2"]       = new object_2();
            _predicates["invoke/3"]       = new invoke_2();
            _predicates["get_property/3"] = new get_property_3();

            // .NET Reflection
        }
Example #4
0
 internal void checkAndScan( CharPredicate p, string predName ) {
     if (p( chr ))
         scan();
     else
         Error( 103, index - 1, 1, predName );
 }
Example #5
0
 internal static CharTest MkCharTest( CharPredicate cPred, CodePointPredicate cpPred ) {
     return delegate( int ord ) {
         // Use the Char function for the BMP
         if (ord <= (int)Char.MaxValue)
             return cPred( (char)ord );
         else
             return cpPred( Char.ConvertFromUtf32( ord ), 0 );
     };
 }
Example #6
0
 internal IsCharScanner(CharPredicate cp, string expected_name)
 {
     this.expected_name = expected_name;
     this.cp            = cp;
 }
Example #7
0
 /// <summary> succeed and consume the current character if it satisfies the given CharPredicate.</summary>
 /// <param name="cp">the predicate.
 /// </param>
 /// <param name="expected_name">the error message.
 /// </param>
 /// <returns> the scanner.
 /// </returns>
 public static Scanner IsChar(CharPredicate cp, string expected_name)
 {
     return(new IsCharScanner(cp, expected_name).Rename("isChar"));
 }
Example #8
0
 /// <summary> succeed and consume the current character if it satisfies the given CharPredicate.</summary>
 /// <param name="cp">the predicate.
 /// </param>
 /// <returns> the scanner.
 /// </returns>
 public static Scanner IsChar(CharPredicate cp)
 {
     return(IsChar(cp, "satisfiable char"));
 }
Example #9
0
 /// <summary> Scans greedily for 0 or more characters
 /// that satisfies the given CharPredicate.
 /// </summary>
 /// <param name="cp">the predicate object.
 /// </param>
 /// <returns> the Scanner object.
 /// </returns>
 public static Scanner Many(CharPredicate cp)
 {
     return(IsPattern("many chars", Patterns.Many(cp), "many"));
 }
Example #10
0
			/// <summary>
			/// Skips characters in the stream, starting at the current position in the stream,
			/// and stops at the first position, for which the character at that position,
			/// returns <c>false</c> for the given <c>predicate</c>.
			/// Returns the amount of characters that have been skipped.
			/// </summary>
			public int SkipWhile(CharPredicate predicate)
			{
				int skipped = 0;
				while (!EndOfStream() && predicate(m_Buffer[m_Position]))
				{
					++m_Position;
					++skipped;
				}

				return skipped;
			}
Example #11
0
 internal IsCharScanner(CharPredicate cp, string expected_name)
 {
     this.expected_name = expected_name;
     this.cp = cp;
 }
Example #12
0
 /// <summary> succeed and consume the current character if it satisfies the given CharPredicate.</summary>
 /// <param name="cp">the predicate.
 /// </param>
 /// <param name="expected_name">the error message.
 /// </param>
 /// <returns> the scanner.
 /// </returns>
 public static Scanner IsChar(CharPredicate cp, string expected_name)
 {
     return new IsCharScanner(cp, expected_name).Rename("isChar");
 }
Example #13
0
 /// <summary> succeed and consume the current character if it satisfies the given CharPredicate.</summary>
 /// <param name="cp">the predicate.
 /// </param>
 /// <returns> the scanner.
 /// </returns>
 public static Scanner IsChar(CharPredicate cp)
 {
     return IsChar(cp, "satisfiable char");
 }
Example #14
0
 /// <summary> Scans greedily for 0 or more characters
 /// that satisfies the given CharPredicate.
 /// </summary>
 /// <param name="cp">the predicate object.
 /// </param>
 /// <returns> the Scanner object.
 /// </returns>
 public static Scanner Many(CharPredicate cp)
 {
     return IsPattern("many chars", Patterns.Many(cp), "many");
 }