From b81c2eee91e09959ee10c08ca34978e13eeb2060 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 28 Mar 2017 20:40:48 -0700 Subject: [PATCH] action --- pitfall/README.md | 31 +++++++++++++++++- pitfall/info.rkt | 6 ++++ pitfall/null.rkt | 3 ++ pitfall/pitfall/.gitignore | 6 ++++ pitfall/pitfall/.travis.yml | 40 +++++++++++++++++++++++ pitfall/pitfall/info.rkt | 3 ++ pitfall/pitfall/main.rkt | 3 ++ pitfall/pitfall/parse.rkt | 27 +++++++++++++++ pitfall/pitfall/parser.rkt | 4 +++ pitfall/pitfall/scribblings/pitfall.scrbl | 10 ++++++ pitfall/pitfall/test.rkt | 5 +++ pitfall/pitfall/tokenizer.rkt | 30 +++++++++++++++++ 12 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 pitfall/info.rkt create mode 100644 pitfall/null.rkt create mode 100644 pitfall/pitfall/.gitignore create mode 100644 pitfall/pitfall/.travis.yml create mode 100644 pitfall/pitfall/info.rkt create mode 100644 pitfall/pitfall/main.rkt create mode 100644 pitfall/pitfall/parse.rkt create mode 100644 pitfall/pitfall/parser.rkt create mode 100644 pitfall/pitfall/scribblings/pitfall.scrbl create mode 100644 pitfall/pitfall/test.rkt create mode 100644 pitfall/pitfall/tokenizer.rkt diff --git a/pitfall/README.md b/pitfall/README.md index 732eafda..0d3a9e3c 100644 --- a/pitfall/README.md +++ b/pitfall/README.md @@ -1,2 +1,31 @@ -# pitfall +pitfall [![Build Status](https://travis-ci.org/mbutterick/pitfall.svg?branch=master)](https://travis-ci.org/mbutterick/pitfall) +- Racket DSL for parsing & generating PDF files + + +Installation +- + +`raco pkg install pitfall` + + +Update +- + +`raco pkg update pitfall` + +Documentation +- +http://docs.racket-lang.org/pitfall + +License +- + +MIT License +Copyright (c) 2017 Matthew Butterick + +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. diff --git a/pitfall/info.rkt b/pitfall/info.rkt new file mode 100644 index 00000000..b6dc412b --- /dev/null +++ b/pitfall/info.rkt @@ -0,0 +1,6 @@ +#lang info +(define collection 'multi) +(define deps '("base" "rackunit-lib")) +(define build-deps '("scribble-lib" "racket-doc")) +(define version "0.0") +(define pkg-authors '(mb)) diff --git a/pitfall/null.rkt b/pitfall/null.rkt new file mode 100644 index 00000000..1e8dcdf3 --- /dev/null +++ b/pitfall/null.rkt @@ -0,0 +1,3 @@ +#lang racket/base + +(require pitfall/parse) \ No newline at end of file diff --git a/pitfall/pitfall/.gitignore b/pitfall/pitfall/.gitignore new file mode 100644 index 00000000..1a593486 --- /dev/null +++ b/pitfall/pitfall/.gitignore @@ -0,0 +1,6 @@ +*~ +\#* +.\#* +.DS_Store +compiled/ +/doc/ diff --git a/pitfall/pitfall/.travis.yml b/pitfall/pitfall/.travis.yml new file mode 100644 index 00000000..fa436736 --- /dev/null +++ b/pitfall/pitfall/.travis.yml @@ -0,0 +1,40 @@ +# adapted from +# https://github.com/greghendershott/travis-racket/blob/master/.travis.yml +# Thanks Greg! + +language: c +sudo: false + +env: + global: + - RACKET_DIR=~/racket + matrix: +# - RACKET_VERSION=6.0 +# - RACKET_VERSION=6.1 +# - RACKET_VERSION=6.2 + - RACKET_VERSION=6.3 + - RACKET_VERSION=6.4 + - RACKET_VERSION=6.5 + - RACKET_VERSION=6.6 + - RACKET_VERSION=HEAD + +# You may want to test against certain versions of Racket, without +# having them count against the overall success/failure. +matrix: + allow_failures: + #- env: RACKET_VERSION=HEAD + # Fast finish: Overall build result is determined as soon as any of + # its rows have failed, or, all of its rows that aren't allowed to + # fail have succeeded. + fast_finish: true + +before_install: + - git clone https://github.com/mbutterick/travis-racket.git + - 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 + +script: + - cd .. # Travis did a cd into the dir. Back up, for the next: + # don't rely on package server + - travis_retry raco pkg install --deps search-auto https://github.com/mbutterick/pitfall.git + - raco test -p pitfall diff --git a/pitfall/pitfall/info.rkt b/pitfall/pitfall/info.rkt new file mode 100644 index 00000000..14943fb0 --- /dev/null +++ b/pitfall/pitfall/info.rkt @@ -0,0 +1,3 @@ +#lang info +(define scribblings '(("scribblings/pitfall.scrbl" ()))) + diff --git a/pitfall/pitfall/main.rkt b/pitfall/pitfall/main.rkt new file mode 100644 index 00000000..80fa45f9 --- /dev/null +++ b/pitfall/pitfall/main.rkt @@ -0,0 +1,3 @@ +#lang racket/base + + diff --git a/pitfall/pitfall/parse.rkt b/pitfall/pitfall/parse.rkt new file mode 100644 index 00000000..64abf804 --- /dev/null +++ b/pitfall/pitfall/parse.rkt @@ -0,0 +1,27 @@ +#lang br/quicklang +(require "parser.rkt" "tokenizer.rkt") +(provide (matching-identifiers-out #rx"pf-" (all-defined-out))) + +(module+ reader (provide read-syntax)) + +(define (read-syntax src port) + (define parse-tree (parse (make-tokenizer src port))) + (strip-bindings + #`(module pitfall-parse-mod pitfall/parse + #,parse-tree))) + +(define-macro (my-mb PARSE-TREE) + #'(#%module-begin PARSE-TREE)) +(provide (rename-out [my-mb #%module-begin])) + +(provide null) + +(define-macro (pf-program ARG ...) + #'(list ARG ...)) + +(define (pf-name str) + (let* ([str (string-trim str "/" #:right? #f)] + [str (regexp-replace* #px"#(\\d\\d)" str (λ (m sub) (string (integer->char (string->number sub 16)))))]) + (string->symbol str))) + +(pf-name "B#45#20L") \ No newline at end of file diff --git a/pitfall/pitfall/parser.rkt b/pitfall/pitfall/parser.rkt new file mode 100644 index 00000000..eaa7d56f --- /dev/null +++ b/pitfall/pitfall/parser.rkt @@ -0,0 +1,4 @@ +#lang brag + +pf-program : (NULL | CHAR | BOOLEAN | INT | REAL | pf-name)* +pf-name : NAME \ No newline at end of file diff --git a/pitfall/pitfall/scribblings/pitfall.scrbl b/pitfall/pitfall/scribblings/pitfall.scrbl new file mode 100644 index 00000000..e97776f2 --- /dev/null +++ b/pitfall/pitfall/scribblings/pitfall.scrbl @@ -0,0 +1,10 @@ +#lang scribble/manual +@require[@for-label[pitfall + racket/base]] + +@title{pitfall} +@author{mb} + +@defmodule[pitfall] + +Package Description Here diff --git a/pitfall/pitfall/test.rkt b/pitfall/pitfall/test.rkt new file mode 100644 index 00000000..9aeeb1ff --- /dev/null +++ b/pitfall/pitfall/test.rkt @@ -0,0 +1,5 @@ +#lang pitfall/parse + +null +true +false \ No newline at end of file diff --git a/pitfall/pitfall/tokenizer.rkt b/pitfall/pitfall/tokenizer.rkt new file mode 100644 index 00000000..ed2fccd6 --- /dev/null +++ b/pitfall/pitfall/tokenizer.rkt @@ -0,0 +1,30 @@ +#lang br +(require brag/support) +(provide make-tokenizer) + +(define-lex-abbrev digit (char-set "0123456789")) +(define-lex-abbrev hex-digit (:or digit (char-set "ABCDEF"))) +(define-lex-abbrev digits (:+ digit)) +(define-lex-abbrev sign (:? (:or "+" "-"))) +(define-lex-abbrev blackspace (:~ whitespace)) + +(define-lex-abbrev nonreg-char (:seq "#" hex-digit hex-digit)) + +(define (make-tokenizer src port) + (port-count-lines! port) + (lexer-file-path src) + (define lex-once + (lexer-srcloc + [(eof) eof] + [whitespace + (token 'WHITESPACE lexeme #:skip? #t)] + [(:or "true" "false") (token 'BOOLEAN (equal? lexeme "true"))] + [(:seq sign digits) (token 'INT (string->number lexeme))] + [(:seq sign (:or (:seq digits "." (:? digits)) + (:seq "." digits))) + (token 'REAL (string->number lexeme))] + [(:seq "/" (:+ (:or nonreg-char blackspace))) + (token 'NAME lexeme)] + ["null" (token 'NULL 'null)] + [any-char (token 'CHAR lexeme)])) +(λ () (lex-once port))) \ No newline at end of file