defineLine function
Parses, analyse and preprocess lines of liin code
Implementation
Future<List<Map<String, dynamic>>?> defineLine(String str) async {
// ignore: omit_local_variable_types
final Map<String, dynamic> result = {};
// Defining indentation level
var indent = 0;
while (str.startsWith(_exps['indent']!)) {
indent++;
str = str.replaceFirst(_exps['indent']!, '');
}
result['indentation'] = indent;
if (_exps['command_line']!.hasMatch(str)) {
// If this line is a command
result['type'] = LineType.Command;
str = str.replaceFirst(_exps['command_line']!, '');
result.addAll(_defineCommand(str));
} else if (_exps['definition_line']!.hasMatch(str)) {
// If this line is a definition
result['type'] = LineType.Definition;
// Capturing, spliting and clearing
DefinitionType def_type;
final m1 = _exps['definition_1type_capture']!.firstMatch(str)!;
str = str.replaceFirst(_exps['definition_line']!, '');
if (m1[1]!.toLowerCase() == '!x') {
def_type = DefinitionType.Undef;
result['name'] = m1[2];
} else if (m1[1] == '!>') {
def_type = DefinitionType.Block;
result['name'] = m1[2];
} else {
// Checking operators
final m = _exps['definition_capture']!.firstMatch(str)!;
final op = m[2];
dynamic other = m[3];
if (op == '=') {
def_type = DefinitionType.Simple;
other = Expression.parse(other);
} else if (op == '<<') {
def_type = DefinitionType.Command;
other = _defineCommand(other);
} else {
def_type = DefinitionType.Complex;
other = Expression.parse(other);
}
result.addAll({
'name': m[1],
'operator': m[2],
'value': other,
});
}
result['def_type'] = def_type;
} else if (_exps['comment_line']!.hasMatch(str) ||
str == _exps['whitespace']!.firstMatch(str)![0]) {
// If this line is a comment
result['type'] = LineType.Comment;
} else if (_exps['setting_line']!.hasMatch(str)) {
// If this line is a setting
final match = _exps['setting_capture']!.firstMatch(str);
if (match != null) {
// Capturing setting params
final name = match[1];
final arg = match[2];
if (name == 'include') {
return includeLines(arg!);
} else {
print(error(
'Error while processing setting in line $_lineNum. Skipping...'));
}
} else {
print(error('Error while checking line $_lineNum. Skipping...'));
}
} else {
result['type'] = LineType.Empty;
print(error('Error while checking line $_lineNum. Skipping...'));
}
return [result];
}