Skip to content
Hyomoto edited this page Jun 24, 2021 · 19 revisions
Jump To Go Back Arguments Methods Variables

Parser( _divider )

Implements: Struct

The parser is used to break apart strings based on character runs. By default, it will uses spaces and tabs to break apart strings, but this can be changed by using the divider method.

var _parser = new Parser().parse( "Hello.World!" )

_parser.divider(".");

_parser.next();
Output: "Hello"

Arguments

Name Type Purpose
_divider undef No description

Methods

Jump To top parse clear restart has_next next remaining peek load save to_array size toString

parse( string )

Returns: self

Throws: InvalidArgumentType

Name Type Purpose
string string The string to parse

Sets string as the target for parsing.


clear( )

Returns: self

Name Type Purpose
None

Clears the contents of the parser.


restart( )

Returns: self;

Name Type Purpose
None

Sets the parse position back to the start of the string.


has_next( )

Returns: bool

Name Type Purpose
None

Returns true if there is unparsed string remaining.


next( )

Returns: string or EOS

Name Type Purpose
None

Returns the next chunk in the string based on the divider. If the end of the string has been reached, EOS is returned instead.


remaining( )

Returns: string or EOS

Name Type Purpose
None

Returns the remaining unparsed string, or EOS if the end of the string has been reached.


peek( )

Returns: string or EOS

Name Type Purpose
None

Reads and returns the next word in the parser without advancing it. If the end of the param string has been reached, EOS is returned.


load( data )

Returns: self

Throws: InvalidArgumentType

Name Type Purpose
data struct The saved state to return to.

Returns the parser to a saved state. If the struct provided is not a valid state, InvalidArgumentType will be thrown.


save( )

Returns: struct

Name Type Purpose
None

Returns a struct with the state of the parser preserved.


to_array( )

Returns: array

Name Type Purpose
None

Breaks up the string into an array and returns it.


size( )

Returns: int

Name Type Purpose
None

Returns the length of the internal string.


toString( remaining? )

Returns: string

Name Type Purpose
remaining? bool optional: Whether to only return the remainder

Returns the string being parsed. If remaining? is true, only the part of the string which has yet to be parsed will be returned.


Variables

Jump To top
Name Type Initial Purpose
EOS struct constant A marker that is returned when the end of the string has been reached.
__Content string "" The string being parsed.
__Divider string " \t" (whitespace) The character string used to find the next breakpoint.
__Last int 0 The last position read from.
Clone this wiki locally