codewars / runner

Issue tracker for Code Runner
33 stars 8 forks source link

Add library for checking imported/hidden modules for PureScript #46

Open DonaldKellett opened 5 years ago

DonaldKellett commented 5 years ago

From codewars/codewars-runner-cli#691 :

Idk if this is a bit of a stretch but would it be reasonable for me to request something similar to Test.Codewars.BlackList in PureScript? Currently, quite a few Haskell kata aren't suitable for translation into PureScript (e.g. "The Five Fundamental Monads", "foldMap all the things") only because they require certain built-ins to be hidden and AFAIK there is no module/library in PureScript for writing such tests. Or are such Kata (requiring certain built-ins to be hidden) highly discouraged and only kept as legacy content?

kazk commented 5 years ago

Or are such Kata (requiring certain built-ins to be hidden) highly discouraged and only kept as legacy content?

I don't think so. I liked "Fix it". It's just sad that we need to test that users don't use the builtin.

But it depends because I don't think we need hundreds of kata to implement builtin functions from different languages.


Anyways, I'll try to describe how PureScript runner works (it's very simple).

PureScript runner uses pulp to run tests and uses psc-package to manage packages.

Here's what happens when PureScript code is submitted.

Filenames are derived from module declarations.

If we can come up with some module like Test.Codewars.BlackList, we should be able to make that available by placing it in the right place.

Do you know any packages that we can use?

If you want to start experimenting, you should be able to just create a new PureScript project locally for it because we don't really do anything special (we just use spec-discover and specify the reporter; and those should be irrelevant).

The most up to date psc-package.json is:

{
  "name": "codewars-purescript",
  "set": "psc-0.12.2-20190119",
  "source": "https://github.com/purescript/package-sets.git",
  "depends": [
    "prelude",
    "console",
    "effect",
    "bigints",
    "rationals",
    "spec",
    "spec-discovery",
    "spec-quickcheck"
  ]
}

I haven't deployed this one yet, but I'm planning to tonight.

DonaldKellett commented 5 years ago

Do you know any packages that we can use?

IIRC Haskell recently added the parsec parser library? The description for purescript-parsing is "A parser combinator library based on Haskell's Parsec" - perhaps we could use this to implement our Test.Codewars.BlackList for PureScript?

Possible alternatives include:

Of course, two obstacles remain: 1) I haven't checked if purescript-parsing/purescript-string-parsers is in package sets yet (which I'll submit a PR to add now if it's not) and 2) Test.Codewars.BlackList still needs to be implemented ourselves (which ATM I have no clue how to do, even after inspecting the equivalent Haskell code 😛 ). I just checked package sets and they do already have both purescript-parsing and purescript-string-parsers so adding either/both libraries to Codewars should be trivial (if only for implementing Test.Codewars.BlackList in the (near?) future).

kazk commented 5 years ago

@DonaldKellett do you know any package that works with PureScript AST? Something similar to haskell-src-exts.

@Bubbler-4 cleaned up Test.Codewars.BlackList and we now have Test.Hspec.Codewars.

DonaldKellett commented 5 years ago

I did a quick search on Pursuit and none of "purescript-src-exts", "Language.PureScript.Exts", "PureScript.Exts", "Exts", "AST", etc. returned relevant results. The closest(?) I got with "AST" was some AST datatype for something called Kubernetes but is probably totally irrelevant to working with PureScript's AST.

Bubbler-4 commented 5 years ago

I think I found something relevant: parseModule is a Parsec parser that yields a Module, and that Module has a list of Declarations, one constructor of which is ImportDeclaration.

The problem is that everything is written in Haskell so I have no idea what to do with that.

Probably you're better off studying the relevant parser and building an equivalent parser in Purescript. That's somewhat complicated, though I believe the whole import declaration can be summarized into a regex. Probably I can try that if I get lots of spare time.

There's also Vim syntax highlighter for Purescript, in case someone knows how to read it.