/* ----------------------------------------------------------------------------- Copyright 2021 Kevin P. Barry Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------------------------------------------------- */ // Author: Kevin P. Barry [ta0kira@gmail.com] // Helpers to parse a full sequence of Char. concrete ParseChars { // Parses a Float. // // Args: // - DefaultOrder: Decimal-format floating-point. // // Returns: // - ErrorOr: The parsed value, or an error on parse failure. // // Notes: // - At least one digit is required. // - Leading +/- signs may be used. // - A successful parse must consume the entire sequence. // - Scientific notation is allowed, e.g., "10E-5". // - This function does not check for overflow/underflow. // // Example: // // ErrorOr value <- ParseChars.float("123.456E5") // if (value.isError()) { // fail(value.getError()) // } @type float (DefaultOrder) -> (ErrorOr) // Parses an Int. // // Args: // - DefaultOrder: Decimal-format integer. // // Returns: // - ErrorOr: The parsed value, or an error on parse failure. // // Notes: // - At least one digit is required. // - Leading +/- signs may be used. // - A successful parse must consume the entire sequence. // - This function does not check for overflow/underflow. // // Example: // // ErrorOr value <- ParseChars.int("123") // if (value.isError()) { // fail(value.getError()) // } @type int (DefaultOrder) -> (ErrorOr) // Parses a hex-formatted Int. // // Args: // - DefaultOrder: Hex-format integer. // // Returns: // - ErrorOr: The parsed value, or an error on parse failure. // // Notes: // - At least one digit is required. // - Leading +/- signs may be used. // - A successful parse must consume the entire sequence. // - This function does not check for overflow/underflow. // // Example: // // ErrorOr value <- ParseChars.hexInt("123ABC") // if (value.isError()) { // fail(value.getError()) // } @type hexInt (DefaultOrder) -> (ErrorOr) // Parses a octal-formatted Int. // // Args: // - DefaultOrder: Octal-format integer. // // Returns: // - ErrorOr: The parsed value, or an error on parse failure. // // Notes: // - At least one digit is required. // - Leading +/- signs may be used. // - A successful parse must consume the entire sequence. // - This function does not check for overflow/underflow. // // Example: // // ErrorOr value <- ParseChars.octInt("755") // if (value.isError()) { // fail(value.getError()) // } @type octInt (DefaultOrder) -> (ErrorOr) // Parses a binary-formatted Int. // // Args: // - DefaultOrder: Binary-format integer. // // Returns: // - ErrorOr: The parsed value, or an error on parse failure. // // Notes: // - At least one digit is required. // - Leading +/- signs may be used. // - A successful parse must consume the entire sequence. // - This function does not check for overflow/underflow. // // Example: // // ErrorOr value <- ParseChars.binInt("10010") // if (value.isError()) { // fail(value.getError()) // } @type binInt (DefaultOrder) -> (ErrorOr) }