Giter Club home page Giter Club logo

smlnj-parser-style's Introduction

SML-NJ Parser & Style-checks

This project is considered experimental

For UNC Comp 524

This repository contains supporting libraries and style-checks for SML programs for UNC Comp 524. They depend on SML/NJ, which helpfully exposes Compiler internals as structures which can be used, e.g., to parse a file and create an AST.

An example of parsing a file follows (sml style-utils/sources.cm):

(* make an AST *)
val parsed = FileParser.parse "...";
#ast parsed;

(* pretty print it *)
val depth = ...; (* 1, 2, …, 999, … *)
FileParser.pp depth parsed;

Creating style-checks for UNC Comp 524 is work-in-progress; an example of making a grader is in 524-f20-a3/a3grader.sml (see also 524-f20-a3.cm). The core idea is to write some checks with a return type result and a stringifier result_to_string, and pass that structure to GraderFn---this gives you a structure ascribing to GRADER, whose runall method takes a string representing a file-path and runs all of your checks. For example, A3Grader.runall on a passing implementation:

$ sml -m 524-f20-a3.cm
- A3Grader.runall "SocialDistance.sml";
no disallowed functions: pass
matching derived safe calls matching safe with matcher: pass
matching given safe calls matching safe with matcher: pass
curryable interpolated safe calls interpolated safe: pass
curried once interpolated safe calls curryable interpolated safe: pass
curried twice interpolated safe calls curried once interpolated safe: pass
curried matching given safe calls curryable matching safe with given safe matcher: pass
curried matching derived safe calls curryable matching safe with derived safe matcher: pass
no magic numbers in functions: pass
val it = () : unit

Utilities, such as an easy-to-use result type and stringifier and regexp-matcher for declarations, are in GraderUtils. Opening it is a quick way to get started building a grader.

Note that pass b is Pass if b is true, while fail b is Fail if b is true (and vice-versa for when b is false). This makes it easy to write checks like

(* fail when f is true *)
val does_not_f = fail o f
(* pass when g is true *)
val does_g = pass o g

All SML/NJ systems contain compiled versions of the libraries we depend on.

To obtain a reference or source copy of the libraries that we depend on, the simplest route is to edit config/targets in your installation to include the line

request src-smlnj

Then run config/install.{sh,bat} with appropriate permissions. Extract compiler.tgz and system.tgz from the installation directory to obtain the full source.

smlnj-parser-style's People

Contributors

benknoble avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.