Parse

Description

sealed class Tinman.Core.Parsing.Parse

Helper class for performing simple parsing tasks for strings.

Calling object.ToString will return the remaining text, but will not modify the state of the Parse object.

Public / Constructors

Text


public static method Text → (1)

text in : string

[not-null]
The input string.

returns → Parse

The created Parse object.

Returns a Parse object for the given input string.

Public / Methods

Back


public method Back → ()

Decrements the parse position.

Begin


public method Begin → (1)

text in : string

[not-null]
The input text.

returns → Parse

this

Begins to parse the given input text.

Consume


public method Consume → (1)

opt : int32 = 1

[>=0]
The number of input characters to consume.

Consume the next opt input characters.

Follows


public method Follows → (1)

in : string

[not-null]
The string.

returns → bool

true if the following input matches, false if not.

Does the given string match the input that follows?

The current parse position is not modified by this method.

Integer


[Pure]
public static method Integer → (2)

value in : string

The string to parse.

numberBase opt : FormatFlags = FormatFlags.NumberBaseDecimal

The number base.

returns → int64

The integer number.

Parses the given string as an integer number.

ValidatingException

If there is no integer number at the current parse position.


public method Integer → (1)

numberBase opt : FormatFlags = FormatFlags.NumberBaseDecimal

The number base.

returns → int64

The number value.

Parses an integer number.

Valid input strings are defined by the following rules of ParseGrammar:

ValidatingException

If there is no integer number at the current parse position.

See also

Format.ThisInt

LookAhead


public method LookAhead → (1)

idx opt : int32 = 0

[>=0]
Index of character to peek, relative to current parse position.

returns → int32

The character or -1 if the end of the input data has been reached.

Peeks at the following input character.

Next


public method Next → ()

returns → int32

The next character or -1 if the end of the input data has been reached.

Reads the next character from the current line and increments the parse position.

Number


[Pure]
public static method Number → (1)

value in : string

The string to parse.

returns → float64

The floating-point number.

Parses the given string as a floating-point number.

ValidatingException

If value in is not a floating-point number, as defined by the rule float of ParseGrammar.


public method Number → ()

returns → float64

The number value.

Parses a floating-point number.

Valid input strings are defined by the float rule of ParseGrammar.

ValidatingException

If there is no floating-point number at the current parse position.

See also

Format.ThisNum

NumberLenient


[Pure]
public static method NumberLenient → (2)

value in : string

Some number string.

defaultValue opt : float64 = 0

The default value to return if value in is invalid.

returns → float64

The parsed number.

Parses the given string as a floating-point number.

The method applies the following logic in order parse number strings in a lenient manner:

  1. All whitespace characters are stripped from value in.

  2. All ',' characters are stripped iff they occur twice or more.

  3. All '.' characters are stripped iff they occur twice or more.

  4. If either '.' or ',' is present, use it as decimal separator and parse the number.

  5. Otherwise both '.' and ',' are present; use each as decimal separator, parse the number twice and use the number that has the larger absolute value.

SkipNonWhitespace


public method SkipNonWhitespace → ()

Skips all coming non whitespaces.

SkipWhitespace


public method SkipWhitespace → ()

Skips all coming whitespaces.

Token


public method Token → (2)

token in : string

[not-null]
The text token.

caseSensitive opt : bool = true

Match the text token in a case-sensitive manner?

returns → bool

true if the token has been matched, false if not.

Tries to consume the given text token.

Public / Attributes

Input


public attribute Input → (get)

value : string

[not-null]
The input string.

Returns the input string.

IsEof


public attribute IsEof → (get)

value : bool

true if the end of input has been reached, false if not.

Has the end of input been reached?

Offset


public attribute Offset → (get)

value : int32

[0..]
The current text offset.

Returns the current parse offset into the input string.

See also

Parse.Input

ParseGrammar


public static attribute ParseGrammar → (get)

value : Grammar

[not-null]
The grammar.

The grammar of this class.

!float      := sign? (decimal exponent? | infinity) | notanumber ;
!integer-10 := sign? digit+ ;
!integer-16 := (digit | 'a'..'f' | 'A'..'F')+ ;

decimal     := digit+ ('.' digit*)? | '.' digit+ ;
exponent    := @'E' sign? digit+ ;
infinity    := @'Inf' ;
notanumber  := @'NaN' ;

digit       := '0'..'9' ;
sign        := '-' | '+' ;