vickumar1981 / jupyter-dart-kernel

Dart Kernel for Jupyter Notebooks
MIT License
37 stars 5 forks source link

Failing to Import #3

Closed chibsta closed 2 years ago

chibsta commented 2 years ago

Hi,

I managed to install the kernel and can run basic dart code. However I am struggling with importing standard dart classes e.g.:

import 'dart.math';

produces the following error:

/tmp/tmprdl0ihly/main.dart:3:1: Error: Expected ';' after this. import 'dart:math'; ^^^^^^ /tmp/tmprdl0ihly/main.dart:3:1: Error: Undefined name 'import'. import 'dart:math'; ^^^^^^

I have made sure that dart is installed and have added the path to dartkernel.py to my PYTHONPATH environment variable. Still no joy. I have my jupyter notebook running on Ubuntu 20. Please help.

Regards,

vickumar1981 commented 2 years ago

@chibsta thank you for reporting this error.

Took a stab at fixing the import issue: https://github.com/vickumar1981/jupyter-dart-kernel/commit/e3e5918ca9a10878346bdbdd8e24b1818d6b5e30

I tested and it seemed to work now. Let me know if this works for you.

vickumar1981 commented 2 years ago

basic issue is that i copied this code from the swift kernel, but swift can run as a script, whereas dart expects some kind of main method, like Java and C.

it was just putting all the code inside a main method that dart expects:

void main() {
  [your code here]
}

not sure if this is the best approach, but now it reads the start of each line and splits them as either import statements or code statements. i.e.,

[import statements]
void main {
  [code statements]
}
chibsta commented 2 years ago

Fantastic! Thanks @vickumar1981. Sorted!!

vickumar1981 commented 2 years ago

@chibsta is it okay if i close this issue out as resolved?

chibsta commented 2 years ago

Resolved! Thanks once again!

vickumar1981 commented 2 years ago

Resolved by: https://github.com/vickumar1981/jupyter-dart-kernel/commit/e3e5918ca9a10878346bdbdd8e24b1818d6b5e30