Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sorawee committed Sep 23, 2021
0 parents commit 957f78a
Show file tree
Hide file tree
Showing 18 changed files with 575 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on: [push, pull_request]
name: CI
jobs:
build:
name: "Build on Racket '${{ matrix.racket-version }}' (${{ matrix.racket-variant }})"
runs-on: ubuntu-latest
strategy:
matrix:
racket-version: ["stable", "current"]
racket-variant: ["BC", "CS"]
steps:
- uses: actions/checkout@v2
- uses: Bogdanp/[email protected]
with:
architecture: x64
distribution: full
variant: ${{ matrix.racket-variant }}
version: ${{ matrix.racket-version }}
- name: Installing fmt and its dependencies
run: raco pkg install --no-docs --auto --name fmt
- name: Compiling fmt and building its docs
run: raco setup --check-pkg-deps --unused-pkg-deps fmt
- name: Testing fmt
run: raco test -x -p fmt
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*~
\#*
.\#*
.DS_Store
compiled/
/doc/
13 changes: 13 additions & 0 deletions LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2021 sorawee

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
23 changes: 23 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
fmt

MIT License

Copyright (c) 2021 sorawee

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fmt
===

A code formatter for Racket.

Work in progress.

To run, execute `racket run.rkt <filename.rkt>`.
50 changes: 50 additions & 0 deletions conventions.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#lang racket/base

(provide hook-standard
hook-define)
(require racket/match
racket/list
pprint-compact
"core.rkt")

(define (hook-define xs pretty)
(define xs* (map pretty xs))
(define req-last-newline? (require-newline? (last xs)))

(apply
alt
(append
;; fallback case
(if req-last-newline?
(list (v-append (first xs*)
(h-append space (v-concat (rest xs*)))))
(list (v-append (first xs*)
(h-append space (flush (v-concat (rest xs*)))))))
;; fit in one line case
(match xs
[(list _ _ _)
#:when (not (ormap require-newline? xs))
(list (flat (hs-concat xs*)))]
[_ '()])

;; regular case
(match xs
[(list head _ _ _ ...)
#:when (not (require-newline? head))
(if req-last-newline?
(list (v-append
(h-append (first xs*)
space
(second xs*))
(h-append space (flush (v-concat (rest (rest xs*)))))))
(list (v-append
(h-append (first xs*)
space
(second xs*))
(h-append space (v-concat (rest (rest xs*)))))))]
[_ '()]))))

(define (hook-standard name)
(case name
[("define") hook-define]
[else #f]))
Loading

0 comments on commit 957f78a

Please sign in to comment.