Gallery
Mochaccino Sprint 2
Share
Explore

icon picker
Entry Point

main.dart
library cortado;

import 'dart:io';
part './tokeniser.dart';
part './error_handler.dart';

class Compiler {
final String source;
Compiler(this.source);
void compile({
void Function(List<Token>) callback = print,
}) {
Tokeniser tokeniser = Tokeniser(source);
List<Token> tokens = tokeniser.tokenise();
callback(tokens);
if (ErrorHandler.issues.isNotEmpty) {
ErrorHandler.reportAll();
exit(1);
}
}
}

void main() {
String source = "!*+=";
Compiler cortado = Compiler(source);
print('Compiling:\n$source\n');
cortado.compile(
callback: (List<Token> tokens) {
tokens.forEach(print);
},
);
}

extension StringUtils on String {
bool get isNewline => (this == '\n');
bool get isEOF => (this == 'EOF');
bool get isDigit => (<String>[
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9'
].contains(this));
bool get isAlphaNum => (<String>[
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'_'
].contains(this));
bool get isAlpha => (<String>[
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'_'
].contains(this));
String charAt(int pos) => this[pos];
}

Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.