parse method

  1. @override
Future<ParseResult<String>> parse(
  1. CodeUnit<String> codeUnit
)
override

Parses a codeUnit to an ASTRoot and returns a ParseResult.

If some error occurs, returns a ParseResult with an error message.

Implementation

@override
Future<ParseResult<String>> parse(CodeUnit<String> codeUnit) async {
  check(codeUnit);

  var result = _grammarParser.parse(codeUnit.code);

  if (result is! Success) {
    var lineAndColumn = result
        .toPositionString()
        .split(':')
        .map((e) => parseInt(e)!)
        .toList();

    return ParseResult(codeUnit,
        errorMessage: result.message,
        errorPosition: result.position,
        errorLineAndColumn: lineAndColumn);
  }

  var root = result.value;
  return ParseResult(codeUnit, root: root);
}