Dart DocumentationpetitparserContext

Context class

An immutable parse context.

class Context {

 final dynamic _buffer;
 final int _position;

 const Context(this._buffer, this._position);

 /** The buffer we are working on. */
 dynamic get buffer => _buffer;

 /** The current position in the buffer. */
 int get position => _position;

 /** Returns [true] if this result indicates a parse success. */
 bool get isSuccess => false;

 /** Returns [true] if this result indicates a parse failure. */
 bool get isFailure => false;

 /** Returns a result indicating a parse success. */
 Result success(dynamic result, [int position]) {
   return new Success(_buffer, position == null ? _position : position, result);
 }

 /** Returns a result indicating a parse failure. */
 Result failure(String message, [int position]) {
   return new Failure(_buffer, position == null ? _position : position, message);
 }

 /** Returns a human readable string of the current context */
 String toString() => 'Context[${toPositionString()}]';

 String toPositionString() {
   if (_buffer is String) {
     var lineAndColumn = Token.lineAndColumnOf(buffer, position);
     return '${lineAndColumn[0]}:${lineAndColumn[1]}';
   } else {
     return '${position}';
   }
 }

}

Subclasses

Result

Constructors

const Context(_buffer, int _position) #

const Context(this._buffer, this._position);

Properties

final buffer #

The buffer we are working on.

dynamic get buffer => _buffer;

final bool isFailure #

Returns true if this result indicates a parse failure.

bool get isFailure => false;

final bool isSuccess #

Returns true if this result indicates a parse success.

bool get isSuccess => false;

final int position #

The current position in the buffer.

int get position => _position;

Methods

Result failure(String message, [int position]) #

Returns a result indicating a parse failure.

Result failure(String message, [int position]) {
 return new Failure(_buffer, position == null ? _position : position, message);
}

Result success(result, [int position]) #

Returns a result indicating a parse success.

Result success(dynamic result, [int position]) {
 return new Success(_buffer, position == null ? _position : position, result);
}

String toPositionString() #

String toPositionString() {
 if (_buffer is String) {
   var lineAndColumn = Token.lineAndColumnOf(buffer, position);
   return '${lineAndColumn[0]}:${lineAndColumn[1]}';
 } else {
   return '${position}';
 }
}

String toString() #

Returns a human readable string of the current context

String toString() => 'Context[${toPositionString()}]';