notationIsDefinitions function

bool notationIsDefinitions(
  1. String text
)

Whether text is definitions: its first line that is not blank or a // comment starts with define or primitive .

Implementation

bool notationIsDefinitions(String text) {
  final first = const LineSplitter().convert(text).map((l) => l.trim()).where((l) => l.isNotEmpty && !l.startsWith('//')).firstOrNull;
  return first != null && RegExp(r'^(define|primitive)\s+[A-Za-z_]').hasMatch(first);
}