Giter VIP home page Giter VIP logo

smtfmt's Introduction

smtfmt

This is a fun little program that formats SMT-LIB programs.

Installation

$ git clone https://github.com/symflower/smtfmt && cd smtfmt
$ ln -s $PWD/smtfmt ~/bin

Usage

$ input='(:not (:forall (?x Real) (:forall (?y Real) (impl (< ?x ?y) ( :exists (?z Real) (:and (< ?x ?z) (< ?z ?y)))))))'
$ echo "$input" | smtfmt
(:not
  (:forall
    (?x Real)
    (:forall
      (?y Real)
      (impl (< ?x ?y) (:exists (?z Real) (:and (< ?x ?z) (< ?z ?y)))))))

Small expressions are printed inline. Longer expressions are broken up and aligned.

Tests

Run pytest smtfmt.py.

Style

Format with black --pyi smtfmt.py.

smtfmt's People

Contributors

bohlender avatar johannes-collab avatar krobelus avatar zimmski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

nj00001

smtfmt's Issues

Formatter may coalesce or split SMT-LIB tokens

While implementing a proper scanner for vim-smt2's auto-formatter I stumbled over minor issues with the testcase originally provided by you @krobelus. The issues are SMT-LIB specific, so if you aim for a generic Lisp formatter they might not be problematic for you at all. They caught me by surprise so I wanted to make you aware of them ๐Ÿ˜…

  • The following line should probably not be considered as properly formatted:
    (list (list (fun) (number 0.0.0.0:5900) atom))

    Here, 0.0.0.0:5900 is understood as a single symbol and correspondingly formatted as such. However, according to the SMT-LIB token specification, these are three separate tokens
  pos  len            kind  lexeme
   26    3         decimal: 0.0
   29    4   simple_symbol: .0.0
   33    5         keyword: :5900

so the formatter should probably separate them by whitespace and consider putting them on separate lines.

  • While the above example features three tokens that are treated as a single token, it can also happen that the formatter treats a single one as a bunch of tokens. For example, this happens when we have quoted symbols such as | this is a single symbol |.

There are some more cases that the formatter does not account for so I suggest just skimming the token specification to decide whether the edge cases are worth being "fixed" for smtfmt.

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.