parse method

List<Tag> parse(
  1. String? source
)

Implementation

List<Tag> parse(String? source) {
  _stack = [];
  _stack.add(RootState(null));

  final context = TagserContext(
    options: _options,
  );

  if (source != null && source.isNotEmpty) {
    final lines = source.split('\n');

    for (var l = 0; l < lines.length; l++) {
      _line = l + 1;
      final line = lines[l];

      for (var i = 0; i < line.length; i++) {
        //print('Current state is: ${_stack.last}');
        _symbol = i + 1;
        final charCode = line.codeUnitAt(i);

        //print('Pocessing char "${String.fromCharCode(charCode)}"; State - ${_stack.last.toString()}');
        //print("char: ${line[i]}");

        context.symbol = _symbol;
        context.line = _line;

        process(ProcessMessage(charCode: charCode), context);
      }
    }

    process(ProcessMessage(charCode: charEos), context);

    final state = _stack.last;

    if (state is RootState) {
      return state.tags;
    }
  }

  return [];
}