exercism / bash

Exercism exercises in Bash.
https://exercism.org/tracks/bash
MIT License
100 stars 88 forks source link

Build representer #533

Open ErikSchierboom opened 3 years ago

ErikSchierboom commented 3 years ago

In Exercism v3, we're introducing a new (optional) tool: the representer. The goal of the representer is to take a solution and returning a representation, which is an extraction of a solution to its essence with normalized names, comments, spacing, etc. but still uniquely identifying the approach taken. Two different ways of solving the same exercise must not have the same representation.

Each representer is track-specific. When a new solution is submitted, we run the track's representer, which outputs two JSON files that describe the representation.

Once we have a normalized representation for a solution, a team of vetted mentors will look at the solution and comment on it (if needed). These comments will then automatically be submitted to each new solution with the same representation. A notification will be sent for old solutions with a matching representation.

The representer is an optional tool though, which means that if a track does not have a representer, it will still function normally.

Goal

Build a representer for your track according to the spec. Check this page to help you get started with building a representer.

Note that the simplest representer is one that merely returns the solution's source code.

It can be very useful to check how other tracks have implemented their representer.

If your track already has a working representer, please close this issue and ensure that the .status.representer key in the track config.json file is set to true.

Choosing between representer and analyzer

There is some overlap between the goals of the representer and the analyzer. If you want to build both, we recommend starting by building the representer for the following reasons:

Tracking

https://github.com/exercism/v3-launch/issues/52

glennj commented 3 years ago

What tools to use? Here's a possibility:

The https://oilshell.org project implements a tool called OSH that can create an AST for bash code.

$ brew install oil

$ cd ~/src/exercism/tracks/bash/exercises/practice/hello-world/.meta

$ osh -n example.sh
(C {<echo>} {(DQ <'Hello, World!'>)})

$ osh -n --ast-format text example.sh
(command.Simple
  words: [
    (compound_word parts:[(Token id:Id.Lit_Chars span_id:4 val:echo)])
    (compound_word
      parts: [
        (double_quoted
          left: (Token id:Id.Left_DoubleQuote span_id:6 val:'"')
          parts: [(Token id:Id.Lit_Chars span_id:7 val:'Hello, World!')]
          multiline: F
          spids: [6 8]
        )
      ]
    )
  ]
  do_fork: T
)
glennj commented 3 years ago

Another possibility: https://github.com/vorpaljs/bash-parser