Skip to content

Latest commit

 

History

History
73 lines (51 loc) · 1.98 KB

Readme.md

File metadata and controls

73 lines (51 loc) · 1.98 KB

SmaCC Dart

This is a dart parser made in Pharo.

Installation

To install it, first create a BLMoose image.

Then, in a playground perform:

Metacello new
  githubUser: 'Evref-BL' project: 'SmaccDart' commitish: 'main' path: 'src';
  baseline: 'SmaccDart';
  onConflict: [ :ex | ex useIncoming ];
  onUpgrade: [ :ex | ex useIncoming ];
  onDowngrade: [ :ex | ex useLoaded ];
  load
  

Usage

To parse a string:

DartParser parse:  'class A {
  final int myInt;
  final String myString;
}'

From a file

DartParser parseFile:  'path/to/the/file.dart'

Example of parsing dependencies of Dart file

With the project dart-dep-resolver, we use the parser to look for dependencies between dart file (using import declaration) and create a Mermaid diagram of these dependencies. The following is an example created from the template of the helloWorld app in Flutter.

flowchart
    widget_test.dart --> main.dart
    main.dart --> material.dart
    widget_test.dart --> material.dart
    widget_test.dart --> flutter_test.dart
Loading

Developer

You will find the grammar used for the parser in the file grammar/dart.g. To reimport it, use:

definition := ('path\to\grammar\dart.g' asFileReference contents).
grammarCompiler := SmaCCGrammarCompiler new.
grammarCompiler codeGenerator defaultCategory: 'SmaCC_Dart'.
grammarCompiler
	buildDefinition: definition;
	compileInto: 'DartScanner' andParser: 'DartParser'.

You can modify the dart.g file to improve the parser.

Each time you modify the .g file, remember to regenerate before commiting

SmaCC documentation

Please refer to the official book of SmaCC (or its archived version).