StringTableParser

com.phasmidsoftware.tableparser.core.parse.StringTableParser
abstract class StringTableParser[Table] extends AbstractTableParser[Table]

Abstract class to extend AbstractTableParser but with Input = String. This is the normal situation where a file is a sequence of Strings, each representing one line.

Type parameters

Table

the table type.

Attributes

Graph
Supertypes
class AbstractTableParser[Table]
trait TableParser[Table]
trait TableBuilder[Table]
class Object
trait Matchable
class Any
Show all
Known subtypes

Members list

Type members

Types

type Input = String

The input type, typically String or Strings.

The input type, typically String or Strings.

Attributes

Inherited and Abstract types

type Row

The row type.

The row type.

Attributes

Inherited from:
TableBuilder

Value members

Concrete methods

infix def parse(sy: Try[Source]): Try[Table]
Extension method from TableParser

Method to parse a Try[Source] character-by-character. NOTE the underlying source of sy will be closed after parsing has been completed.

Method to parse a Try[Source] character-by-character. NOTE the underlying source of sy will be closed after parsing has been completed.

Value parameters

sy

a Try[Source].

Attributes

Returns

a Try[Table].

override def parse(xs: Iterator[String], n: Int = ...): Try[Table]

Method to parse a table based on a sequence of Inputs. NOTE: this is required so that we can invoke this method with an Iterator[String].

Method to parse a table based on a sequence of Inputs. NOTE: this is required so that we can invoke this method with an Iterator[String].

Value parameters

n

the number of rows to drop (length of the header)--defaults to 1.

xs

the sequence of Inputs, one for each row

Attributes

Returns

a Try[Table].

Definition Classes
def parseRows(ws: Iterator[String], header: Header): Try[Table]

Parses rows from an iterator of input strings (ws) using the provided header and row parsing logic.

Parses rows from an iterator of input strings (ws) using the provided header and row parsing logic.

This method utilizes the doParseRows function to process each row in the input iterator, applying the provided rowParser.parse function to convert input strings into logical rows, while using the header to guide parsing and interpretation of the input.

Value parameters

header

the Header object that describes the expected structure of the table (e.g., column names).

ws

an iterator over the input strings, where each string represents a row in the table.

Attributes

Returns

a Try of the parsed Table object. On success, it contains the resulting table; on failure, it contains the parsing error.

def parseSelected(xs: Iterator[String], selection: RowSelection, n: Int = ...): Try[Table]

Method to parse the input into a Table of the selected rows (see rows). As in parse, if this parser isn't forgiving, a row which can't be parsed makes the result a Failure.

Method to parse the input into a Table of the selected rows (see rows). As in parse, if this parser isn't forgiving, a row which can't be parsed makes the result a Failure.

Value parameters

n

the number of header lines (defaults to headerRowsToRead).

selection

the rows to select (RFC 7111: see CsvFragment).

xs

the lines of the input.

Attributes

Returns

a Try[Table].

def rows(xs: Iterator[String], n: Int = ..., selection: RowSelection = ...): Try[(Header, Iterator[Try[Row]])]

Method to parse the input lazily, as a stream of rows rather than a Table (see, e.g., IOTable.stream). The header is read now (from the first n lines, unless this parser has a fixed header); each row is parsed only when it is pulled from the iterator. As in parse, the predicate selects the rows; and, if this parser is forgiving, a row which can't be parsed is logged and left out. Otherwise, it is a Failure in the iterator.

Method to parse the input lazily, as a stream of rows rather than a Table (see, e.g., IOTable.stream). The header is read now (from the first n lines, unless this parser has a fixed header); each row is parsed only when it is pulled from the iterator. As in parse, the predicate selects the rows; and, if this parser is forgiving, a row which can't be parsed is logged and left out. Otherwise, it is a Failure in the iterator.

The selection (of RFC 7111 rows: see CsvFragment) applies before the predicate, since its row numbers are those of the input.

Value parameters

n

the number of header lines (defaults to headerRowsToRead).

selection

the rows to select (by default, all of them).

xs

the lines of the input.

Attributes

Returns

a Try of the header and an Iterator of the rows (each a Try).

Inherited methods

def doParseRows(ts: Iterator[Input], header: Header, f: ((Input, Int)) => Try[Row])(using ev: Joinable[Input]): Try[Table]

Parses rows of input data into a table representation.

Parses rows of input data into a table representation.

This method utilizes an IndexedInputToRowsAggregator to transform an iterator of inputs into rows using the provided header and transformation function. It processes the input, materializes the resulting rows into a list, and constructs a table representation from the processed rows and header.

Value parameters

ev

an implicit evidence parameter ensuring the input type adheres to the Joinable type class, which defines how input elements can be combined or validated during processing.

f

a transformation function that maps the Header to a function capable of transforming a tuple of input and its index into a Try[Row]. This function encapsulates row processing logic and error handling for each input element.

header

the Header containing column metadata to guide the transformation process.

ts

an iterator of inputs to be parsed into rows.

Attributes

Returns

a Try containing a Table if the parsing is successful, or an error in case of failure.

Inherited from:
AbstractTableParser

Inherited and Abstract methods

protected def builder(rows: Iterator[Row], header: Header): Table

Method to construct a Table based on the given iterator of rows and the given header.

Method to construct a Table based on the given iterator of rows and the given header.

Value parameters

header

a Header object representing the table's column headers.

rows

an iterator of Row objects representing the data rows.

Attributes

Returns

the constructed Table based on the input rows and header.

Inherited from:
TableBuilder

Inherited fields

protected val forgiving: Boolean

If true, individual row failures are logged but do not cause the overall parse to fail.

If true, individual row failures are logged but do not cause the overall parse to fail.

Attributes

Inherited from:
TableBuilder
val headerRowsToRead: Int

This indicates the number of header rows which must be read from the input. The value is usually 1 but some types of CSV file have more than one header line. If maybeHeader exists, then this number is ignored.

This indicates the number of header rows which must be read from the input. The value is usually 1 but some types of CSV file have more than one header line. If maybeHeader exists, then this number is ignored.

CONSIDER if this is really ignored when maybeHeader is defined, then we should eliminate such places where this value has an override of 0.

Attributes

Inherited from:
TableParser
protected val predicate: Try[Row] => Boolean

Predicate to filter rows. Defaults to including all rows.

Predicate to filter rows. Defaults to including all rows.

Attributes

Inherited from:
TableBuilder

Inherited and Abstract fields

Method to define a row parser.

Method to define a row parser.

Attributes

Returns

a RowParser[Row, Input].

Inherited from:
TableParser