rumil_tokens 0.1.0 copy "rumil_tokens: ^0.1.0" to clipboard
rumil_tokens: ^0.1.0 copied to clipboard

Lossless source code tokenizer built on Rumil parser combinators. Classified token spans for syntax highlighting. Built-in grammars for Dart, Scala, YAML, JSON, and shell.

example/example.dart

import 'package:rumil_tokens/rumil_tokens.dart';

void main() {
  const source = '''
void main() {
  final x = 42;
  // greeting
  print("hello \$x");
}
''';

  final tokens = tokenize(source, dart);

  for (final token in tokens) {
    final kind = switch (token) {
      Keyword() => 'keyword',
      TypeName() => 'type',
      StringLit() => 'string',
      NumberLit() => 'number',
      Comment() => 'comment',
      Annotation() => 'annotation',
      Punctuation() => 'punct',
      Operator() => 'op',
      Variable() => 'var',
      Identifier() => 'ident',
      Whitespace() => 'ws',
      Plain() => 'plain',
    };
    if (token is! Whitespace) {
      print('$kind: ${token.text}');
    }
  }
}
0
likes
160
points
376
downloads

Documentation

API reference

Publisher

verified publisherardaproject.org

Weekly Downloads

Lossless source code tokenizer built on Rumil parser combinators. Classified token spans for syntax highlighting. Built-in grammars for Dart, Scala, YAML, JSON, and shell.

Repository (GitHub)
View/report issues

Topics

#parser #tokenizer #syntax-highlighting #lexer

License

MIT (license)

Dependencies

rumil

More

Packages that depend on rumil_tokens