Skip to content

Commit

Permalink
First milestone, though not at all a proper package!
Browse files Browse the repository at this point in the history
  • Loading branch information
apg committed Aug 18, 2017
0 parents commit 0e8ae3c
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 0 deletions.
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/
60 changes: 60 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
language: c

# Based from: https://github.com/greghendershott/travis-racket

# Optional: Remove to use Travis CI's older infrastructure.
sudo: false

env:
global:
# Supply a global RACKET_DIR environment variable. This is where
# Racket will be installed. A good idea is to use ~/racket because
# that doesn't require sudo to install and is therefore compatible
# with Travis CI's newer container infrastructure.
- RACKET_DIR=~/racket
matrix:
# Supply at least one RACKET_VERSION environment variable. This is
# used by the install-racket.sh script (run at before_install,
# below) to select the version of Racket to download and install.
#
# Supply more than one RACKET_VERSION (as in the example below) to
# create a Travis-CI build matrix to test against multiple Racket
# versions.
- RACKET_VERSION=6.0
- RACKET_VERSION=6.1
- RACKET_VERSION=6.1.1
- RACKET_VERSION=6.2
- RACKET_VERSION=6.3
- RACKET_VERSION=6.4
- RACKET_VERSION=6.5
- RACKET_VERSION=6.6
- RACKET_VERSION=6.7
- RACKET_VERSION=6.8
- RACKET_VERSION=6.9
- RACKET_VERSION=HEAD

matrix:
allow_failures:
# - env: RACKET_VERSION=HEAD
fast_finish: true

before_install:
- git clone https://github.com/greghendershott/travis-racket.git ~/travis-racket
- cat ~/travis-racket/install-racket.sh | bash # pipe to bash not sh!
- export PATH="${RACKET_DIR}/bin:${PATH}" #install-racket.sh can't set for us

install:
- raco pkg install --deps search-auto

before_script:

# Here supply steps such as raco make, raco test, etc. You can run
# `raco pkg install --deps search-auto` to install any required
# packages without it getting stuck on a confirmation prompt.
script:
- raco test -x -p simple-slideshow

after_success:
- raco setup --check-pkg-deps --pkgs simple-slideshow
- raco pkg install --deps search-auto cover cover-coveralls
- raco cover -b -f coveralls -d $TRAVIS_BUILD_DIR/coverage .
11 changes: 11 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
simple-slideshow
Copyright (c) 2017 apg

This package is distributed under the GNU Lesser General Public
License (LGPL). This means that you can link simple-slideshow into proprietary
applications, provided you follow the rules stated in the LGPL. You
can also modify this package; if you distribute a modified version,
you must distribute it under the terms of the LGPL, which in
particular means that you must release the source code for the
modified software. See http://www.gnu.org/copyleft/lesser.html
for more information.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
slideshow-simple
================
README text here.
9 changes: 9 additions & 0 deletions info.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#lang info
(define collection 'multi)
(define deps '("slideshow-lib"
"rackunit-lib"))
(define build-deps '("scribble-lib" "racket-doc"))
(define scribblings '(("scribblings/simple-slideshow.scrbl" ())))
(define pkg-desc "A very simple lang for making basic slideshows")
(define version "0.0")
(define pkg-authors '(apg))
10 changes: 10 additions & 0 deletions scribblings/simple-slideshow.scrbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#lang scribble/manual
@require[@for-label[simple-slideshow
racket/base]]

@title{simple-slideshow}
@author{apg}

@defmodule[simple-slideshow]

Package Description Here
Binary file added slideshow/simple/lang/image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions slideshow/simple/lang/nodes.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#lang racket/base

(require racket/math
racket/struct
racket/contract/base)

(provide (contract-out
[struct location ((line natural?) (column natural?))]
[struct image-slide ((path path-string?) (location location?))]
[struct paragraph-slide ((lines (listof string?)) (location location?))]
[make-paragraph-slide (-> string? location? paragraph-slide?)]
[add-to-paragraph (-> paragraph-slide? string? paragraph-slide?)])

empty-slide
empty-slide?)


(struct location (line column) #:transparent)

(struct image-slide (path location) #:transparent)

(struct paragraph-slide (lines location)
#:constructor-name -paragraph-slide
#:transparent)

(define (make-paragraph-slide line location)
(-paragraph-slide (list line) location))

(define(add-to-paragraph p line)
(define lines (paragraph-slide-lines p))
(struct-copy paragraph-slide p
[lines (append lines (list line))]))

(define empty-slide (make-paragraph-slide "" (location 0 0)))

(define (empty-slide? s)
(eq? empty-slide s))
28 changes: 28 additions & 0 deletions slideshow/simple/lang/reader-test.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#lang racket/base

(require rackunit
"./reader.rkt"
"./nodes.rkt")

(define (expect-read? input result desc)
(check-equal? (parse "<input-string>" (open-input-string input))
result
(symbol->string desc)))

(expect-read? "#a comment"
(list empty-slide)
'just-a-comment)
(expect-read? "@foo.png" (list (image-slide "foo.png" (location 1 0))) 'just-an-image)
(expect-read? "paragraph" (list (make-paragraph-slide "paragraph" (location 1 0))) 'just-a-paragraph)
(expect-read? "\\paragraph" (list (make-paragraph-slide "paragraph" (location 1 0))) 'just-a-paragraph-from-literal)
(expect-read? "\\@paragraph" (list (make-paragraph-slide "@paragraph" (location 1 0))) 'just-a-paragraph-from-literal-image)

;; multiple slides now
(expect-read? "@foo.png\n\nparagraph"
(list (make-paragraph-slide "paragraph" (location 3 0))
(image-slide "foo.png" (location 1 0)))
'multiple-image-blank-paragraph)
(expect-read? "@foo.png\n#comment\n\nparagraph"
(list (make-paragraph-slide "paragraph" (location 4 0))
(image-slide "foo.png" (location 1 0)))
'multiple-image-comment-blank-paragraph)
92 changes: 92 additions & 0 deletions slideshow/simple/lang/reader.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#lang racket/base

(require syntax/readerr
racket/string
racket/stream
racket/contract
"./nodes.rkt")

(provide (rename-out [simple-read-syntax read-syntax])
parse)

;; when eof, return the current nodes
;; when the line starts with a `@` we make an image node.
;; when the line starts with a `\` we make a literal node with whatever after the next line.
;; when the line starts with a `#` we ignore the line as a comment.
;; when the line is blank, we commit the current node to the list of nodes.
;; when there is a current paragraph node, and there is an image, it is a syntax error.
;; when there is a current paragraph node, and there is a comment, the comment is ignored and the node is committed.

(define/contract (in-positioned-port port mode)
(-> input-port? (or/c 'linefeed 'return 'linefeed-return 'any 'any-one) stream?)
(port-count-lines! port)
(define (loop port)
(define-values (lineno col pos) (port-next-location port))
(define line (read-line port mode))
(if (eof-object? line)
empty-stream
(stream-cons (list line lineno col pos) (loop port))))
(loop port))

(define (comment-line? line)
(string-prefix? line "#"))

(define (image-line? line)
(string-prefix? line "@"))

(define (literal-line? line)
(string-prefix? line "\\"))

(define (parse path port)
(for/fold ([slides (list empty-slide)])
([line-no-col (in-positioned-port port 'any)])
(define-values (line no col pos) (apply values line-no-col))
(define loc (location no col))
(cond
[(comment-line? line) slides]
[(empty-slide? (car slides))
(cond
[(image-line? line) (cons (image-slide (substring line 1) loc)
(cdr slides))]
[(literal-line? line) (cons (make-paragraph-slide (substring line 1) loc)
(cdr slides))]
[(non-empty-string? (string-trim line)) (cons (make-paragraph-slide line loc)
(cdr slides))]
[else slides])]
[(image-slide? (car slides))
(if (non-empty-string? (string-trim line))
(raise-read-error "can't add to an image slide" path no col pos 1)
(cons empty-slide slides))]
[(paragraph-slide? (car slides))
(cond
[(literal-line? line) (cons (add-to-paragraph (car slides) (substring line 1))
(cdr slides))]
[(non-empty-string? (string-trim line)) (cons (add-to-paragraph (car slides) (string-trim line))
(cdr slides))]
[else
(if (non-empty-string? (string-trim line))
(raise-read-error "can't add unknown to a paragraph slide" path no col pos 1)
(cons empty-slide slides))])]
[else
(raise-read-error "unable to parse line" path no col pos 1)])))

(define (nodes->slides nodes)
(for/list ([node (reverse nodes)]
#:unless (empty-slide? node))
(cond
[(image-slide? node) `(slide #:title ""
(bitmap ,(image-slide-path node)))]
[(paragraph-slide? node) `(slide #:title ""
,@(map (lambda (x)
`(t ,x))
(paragraph-slide-lines node)))]
[else (error 'unknown-node)])))

(define (simple-read-syntax path port)
(define nodes (parse path port))
(define slides (nodes->slides nodes))
(datum->syntax
#f
`(module my-slides slideshow
(require pict)
,@slides)))
17 changes: 17 additions & 0 deletions slideshow/simple/lang/test-slideshow.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#lang reader "./reader.rkt"

slideshow/simple

@image.jpg

depends on
- Racket
- Slideshow

slideshow FILENAME
\#lang reader slideshow/simple


\@IMAGE.png

thanks / questions?

0 comments on commit 0e8ae3c

Please sign in to comment.