Compare commits

...

322 Commits

Author SHA1 Message Date
Matthew Butterick 7d41a489c6 ensure prev-indent is an exact-nonnegative-integer 1 year ago
Matthew Butterick b0d133f4ba suppress testing of indenter due to CI issue 3 years ago
Matthew Butterick 07ef0ea181
badge harder 3 years ago
Matthew Butterick c71303e5f5
badge it 3 years ago
Matthew Butterick a2d7349459
Update README.md 3 years ago
Bogdan Popa 216536ef29
improve CI workflow (#23)
* ci: run a single Xvfb instance for all tests

* ci: add 8.0 and 8.1

* ci: skip failures on 6.7 BC, 7.{7,8,9} CS, currenct BC&CS
3 years ago
Matthew Butterick 7f1f62d714
Update README.md 3 years ago
Matthew Butterick d75a344bee
Update module.rkt 3 years ago
Matthew Butterick f0e2cb5b32 doc fix (closes #22) 3 years ago
Matthew Butterick 68bafddd61
Update ci.yml 3 years ago
Matthew Butterick bac21d8849 Revert "allow false"
This reverts commit dfef06c967.
3 years ago
Matthew Butterick 08698d0573
Update ci.yml 3 years ago
Matthew Butterick 9d86c43758 change CI action 3 years ago
Matthew Butterick bc67284dfc switch Travis for GH actions 3 years ago
Matthew Butterick dfef06c967 allow false 3 years ago
Matthew Butterick db99679d5e less def 4 years ago
Matthew Butterick bf374b1514 missing import 4 years ago
Matthew Butterick f86e14d579 update travis 4 years ago
Matthew Butterick 2aa3dbade1 move br/macro to separate package 4 years ago
Matthew Butterick 1f571fc8de unnecessary predicate 4 years ago
Matthew Butterick 6ec0d25f5d
Update LICENSE.md 4 years ago
Matthew Butterick 853e791e84 new xvfb notation for travis 4 years ago
Matthew Butterick f2eb41aab9 disable @ command char 4 years ago
Matthew Butterick e65ef99a06 touchup 5 years ago
Matthew Butterick 5fc143c123 fix negativity, more 5 years ago
Matthew Butterick 9c168fbd98 fix negativity 5 years ago
Ryan Davis 83206c4521 Extended report-datum to be friendly to eof.
read-syntax returns either a syntax or eof. This allows report-datum
to be used to debug read-syntax issues.
5 years ago
Ryan Davis d0f5fa76a9 strip trailing whitespace
separate from my content commit so you can skip this if you want
5 years ago
Matthew Butterick 0a625a17ee simplify 5 years ago
Matthew Butterick 310651e374 newline 5 years ago
Matthew Butterick 7547324037 omit srcloc 5 years ago
Matthew Butterick efa9ce3264 strip-bindings 5 years ago
Matthew Butterick 3999b3515b tacopocalypse sample 5 years ago
Matthew Butterick 1fe93f59a2 bump version to v1.6 5 years ago
Matthew Butterick 4f3db25a0b adjust numbers 5 years ago
Matthew Butterick 7ea139ac4f refinement 5 years ago
Matthew Butterick d649998e74 omit 5 years ago
Matthew Butterick a948725d58
Update .travis.yml 5 years ago
Matthew Butterick 8677730d47
Update .travis.yml 5 years ago
Matthew Butterick ad48faa13d demo details 5 years ago
Matthew Butterick e0944fea24 update scriptish 5 years ago
Matthew Butterick 944c543db7 refac scriptish 5 years ago
Matthew Butterick 37bc753b27 add `lexer-file-path` 5 years ago
Matthew Butterick 0a0d5831a7 refactor 5 years ago
Matthew Butterick ac5daac9ea more consistent 5 years ago
Matthew Butterick 06a0c155ab update algebra & precalc demos 5 years ago
Matthew Butterick 684abfc3e6 update algebra demo 5 years ago
Matthew Butterick 6d4f0a7b69 changes 5 years ago
Matthew Butterick 0fededb98a use lozenge 5 years ago
Matthew Butterick 5f98d03dab add mb 5 years ago
Matthew Butterick e88e9b164e refac solution 5 years ago
Matthew Butterick d116cfcb82 self-expanding 5 years ago
Matthew Butterick 02a4d9a50e touchup 5 years ago
Matthew Butterick 6024945967 touchup 5 years ago
Matthew Butterick b4c69df771 reversal 5 years ago
Matthew Butterick 5adc13ec08 touchup demos 5 years ago
Matthew Butterick 70acaa4394 omit 5 years ago
Matthew Butterick 081561e9cd add loc 5 years ago
Matthew Butterick 0b24352082 put on source locations 5 years ago
Matthew Butterick 177f0bbb09 scriptish demo 5 years ago
Matthew Butterick 5c40ca6279 loop touchup 5 years ago
Matthew Butterick 57522a1be9 read, expand, conjunction 5 years ago
Matthew Butterick 3c97c01b62 adjust txtadv 5 years ago
Matthew Butterick 67e0064c45 numberstring demo 5 years ago
Matthew Butterick 89c652afd6 mirror demo 5 years ago
Matthew Butterick e5523b2835 dyadic demo 5 years ago
Matthew Butterick c883cb05b2
Update README.md 5 years ago
Matthew Butterick 8744265a90 move it 5 years ago
Matthew Butterick cd68f12985 correct output contracts (fixes #19) 5 years ago
Matthew Butterick 52a91b7183 add dep 5 years ago
Matthew Butterick 1116d43e58 note 5 years ago
Matthew Butterick 15b00031e8 retry 5 years ago
Matthew Butterick 6b4743728b Revert "Update .travis.yml"
This reverts commit f138f7a22a.
5 years ago
Matthew Butterick 9e6349d602 also bump 5 years ago
Matthew Butterick f138f7a22a
Update .travis.yml 5 years ago
Matthew Butterick db0dedfbcf also bump 5 years ago
Matthew Butterick eec4502c4c bump to 1.5; min version 6.7 5 years ago
Matthew Butterick 90c45a7ed6 and quicklang 5 years ago
Matthew Butterick 0bd5c4c09d put debug in default environment 5 years ago
Matthew Butterick 87ce53e51e update info 5 years ago
Matthew Butterick 715bdc66d2 oh, paren 5 years ago
Matthew Butterick a1c4af04aa reorg 5 years ago
Matthew Butterick 60cdb5bf2f figures 5 years ago
Matthew Butterick c1cc8557e8 make arg names consistent 5 years ago
Matthew Butterick eeaa9a41ed
Update README.md 5 years ago
Matthew Butterick b8eb7f14e6 consistency 5 years ago
Matthew Butterick 3003bc61c3 don't forget this case 5 years ago
Matthew Butterick 1d2b75456e correct contract on indenter 5 years ago
Matthew Butterick bac7990c43 space 5 years ago
Matthew Butterick 065364999e
Update .travis.yml 6 years ago
Matthew Butterick ae6303b237 conform names 6 years ago
Matthew Butterick bee6cd8ec1 repair unit tests 6 years ago
Matthew Butterick d92e06231a fix grammar bug 6 years ago
Matthew Butterick 28bc51a793 edits 6 years ago
Matthew Butterick f21e0f7c20 touchups 6 years ago
Matthew Butterick 545b4229fb burnish 6 years ago
Matthew Butterick 1826f8a00f nits 6 years ago
Matthew Butterick fe20dade03 correction 6 years ago
Matthew Butterick ddd430ff75 corrections 6 years ago
Matthew Butterick fb3db2b415 remove a modulo 6 years ago
Matthew Butterick 30200b7551 indent 6 years ago
Matthew Butterick 498a7b2fd0 indents 6 years ago
Matthew Butterick 26f79d4776 indent 6 years ago
Matthew Butterick f4cbcc0ac5 shorten 6 years ago
Matthew Butterick b4588a7767 shorten 6 years ago
Matthew Butterick 9d4292ac85 nits 6 years ago
Matthew Butterick d05ac2ac6a precalc 6 years ago
Matthew Butterick b13ae90903 nudges 6 years ago
Matthew Butterick 8cc09d217c rename simplex 6 years ago
Matthew Butterick 4b5098415d nit 6 years ago
Matthew Butterick 900a7d08f5 bump to 1.4 6 years ago
Matthew Butterick 380f4a2d37 nits 6 years ago
Matthew Butterick 2b776d8ee0 nits 6 years ago
Matthew Butterick 95bfa95b5d demo langs for Racket School 6 years ago
Matthew Butterick b39a1200c3 remove arg 6 years ago
Matthew Butterick cfa5a3598e
Update README.md 6 years ago
Matthew Butterick b3d1d0aaed add an export 6 years ago
Matthew Butterick 2ade55b7ed bump to 1.3 6 years ago
Matthew Butterick 35a4a18976 refactor wires 6 years ago
Matthew Butterick 2e61ddab8d missing `val` 6 years ago
Matthew Butterick ac8aadb6bf with promises 6 years ago
Matthew Butterick 6e1a849339 include promises 6 years ago
Matthew Butterick fadbca3fd2 use guard expr 6 years ago
Matthew Butterick b98131f98a and one more 6 years ago
Matthew Butterick f1969cebd1 change update rule 6 years ago
Matthew Butterick f5b300f6d1 delete unneeded `eof` rules 6 years ago
Matthew Butterick 32f915a844 return #f for line with no indent 6 years ago
Matthew Butterick 51ec447991 return #f not #\nul 6 years ago
Matthew Butterick 8a11393b03 update deps 6 years ago
Matthew Butterick 594ac04ff9
Update .travis.yml 6 years ago
Matthew Butterick 0f002c5586 enable at-reader in `br` languages 6 years ago
Matthew Butterick b2c3988d81 rename `test-reader` → `apply-reader` 6 years ago
Matthew Butterick ece33a624e put `br/module` in #lang br 6 years ago
Matthew Butterick 46a0614a3e provisional `br/module` module 6 years ago
Matthew Butterick 72d551b38b reorder 6 years ago
Matthew Butterick 91f38b554c
Add Rackets 6.11 & 6.12 6 years ago
Matthew Butterick 2f69dda794 unless → when 6 years ago
Matthew Butterick 86b788a304 further simplify literalization 6 years ago
Matthew Butterick 6866c79327 add deps 6 years ago
Matthew Butterick 2912d8392f handle pair patterns 6 years ago
Matthew Butterick 35c7fe7a7a better literal detection 6 years ago
Matthew Butterick 3a6f7c407a nit 6 years ago
Matthew Butterick 5e859a7440 update README 6 years ago
Matthew Butterick 66a826d6f6 edit parser-tester 6 years ago
Matthew Butterick 9c97fe31d7 code typo 6 years ago
Matthew Butterick 6b9dd5a011 test JSON using jsexpr 6 years ago
Matthew Butterick 3cf4fe260e test demo languages 6 years ago
Matthew Butterick b16e11a8a2 source typo 6 years ago
Matthew Butterick 73fb09a017 test that 6 years ago
Matthew Butterick c8bac11d8b check for identifier (fixes #15) 6 years ago
Matthew Butterick 33acb10b31 omit bound id from generated literals (fixes #14) 6 years ago
Matthew Butterick 4bea7423b1 bump to v1.1 6 years ago
Matthew Butterick d4585d825a still more degeneracy 7 years ago
Matthew Butterick 587f5ef946 pair repair 7 years ago
Matthew Butterick f0ec809502 repair 7 years ago
Matthew Butterick 94e19b851e farewell 7 years ago
Matthew Butterick 50bbc22164 prevent `let` collapse 7 years ago
Matthew Butterick d177a7f06f finicky kitty 7 years ago
Matthew Butterick 177dae090f remove duplicates 7 years ago
Matthew Butterick 3c452e4d90 use more `syntax-parse` 7 years ago
Matthew Butterick 91281379f3 correct indenter contract 7 years ago
Matthew Butterick 0af8f1aeeb correct missing `datum?` 7 years ago
Ben Greenman 8000d41389 define-macro: check that ... only follow wildcards 7 years ago
Matthew Butterick 2101e8e9b8 Test Rackets 6.7–6.10 7 years ago
Matthew Butterick b665cd72db naming glitch 7 years ago
Matthew Butterick e4a39ee906 `generate-literals`: treat nonalphabetic identifiers as literals 7 years ago
Matthew Butterick a5dc7b4ea7 nit, picked 7 years ago
Matthew Butterick d5079d88ce fix test file 7 years ago
Matthew Butterick 85759404e9 don't actually install jsonic docs 7 years ago
Matthew Butterick 95fec6d45d allow demo languages to be compiled 7 years ago
Matthew Butterick 2353267090 Update README.md 7 years ago
Matthew Butterick 7c0f97c8ca change linebreak 7 years ago
Matthew Butterick bf8d332bc9 groovier 7 years ago
Matthew Butterick 1b4ef83c1e restore test-reader 7 years ago
Matthew Butterick 6c52696bfb trim 7 years ago
Matthew Butterick 101ec6c41a line breaks 7 years ago
Matthew Butterick 8e405f6287 renames 7 years ago
Matthew Butterick f955987e2b rename predicate 7 years ago
Matthew Butterick 2f1a2b4520 defense 7 years ago
Matthew Butterick bb4dce853c improve test message 7 years ago
Matthew Butterick 25c760a74e bump versions 7 years ago
Matthew Butterick b5f01e1e85 change indenting 7 years ago
Matthew Butterick 242c3dc64e change indenting of while & until 7 years ago
Matthew Butterick 40786d7010 edits 7 years ago
Matthew Butterick b2ad7fbd25 Update README.md 7 years ago
Matthew Butterick c3b8660e1f fixup 7 years ago
Matthew Butterick f7eedcef6f move clargs into runtime 7 years ago
Matthew Butterick 59a63f71dc refactor 7 years ago
Matthew Butterick 5a90f14d0c improve colorer 7 years ago
Matthew Butterick ee35d0d287 reformats 7 years ago
Matthew Butterick db957f3041 samplers 7 years ago
Matthew Butterick eb100cd545 refactor 7 years ago
Matthew Butterick a9b6cb6181 touchup 7 years ago
Matthew Butterick 10bd6435d4 nicer 7 years ago
Matthew Butterick dfe6ef6ffd straighten out lexing 7 years ago
Matthew Butterick c35b02c986 add new token 7 years ago
Matthew Butterick bf76152db6 new sample 7 years ago
Matthew Butterick 0202647959 tokenize only dialect 7 years ago
Matthew Butterick dccdc4ae1d adjustments 7 years ago
Matthew Butterick 04b52e473e better exports 7 years ago
Matthew Butterick 5613323df7 tighten 7 years ago
Matthew Butterick d60ef52e2b resume in parser 7 years ago
Matthew Butterick f5dd28cd05 fix lexer 7 years ago
Matthew Butterick 5c817a33b7 not quite there 7 years ago
Matthew Butterick 76fea3c627 del 7 years ago
Matthew Butterick 2e69bbda33 fix sample 7 years ago
Matthew Butterick e9c10a236e change rule name 7 years ago
Matthew Butterick 42d3eaac68 change error msg 7 years ago
Matthew Butterick 565eb81179 use ID 7 years ago
Matthew Butterick 8452fdfded better error 7 years ago
Matthew Butterick 6acea5ed3d tidying 7 years ago
Matthew Butterick 3dbddf6d1d ignore 7 years ago
Matthew Butterick 199a4a5d8c update docs 7 years ago
Matthew Butterick 198757a437 stub out lang docs 7 years ago
Matthew Butterick 7ede91d508 update repl handling 7 years ago
Matthew Butterick 92a949c08e add `pattern-case` and `pattern-case-filter` 7 years ago
Matthew Butterick 41a898b268 more generous repl 7 years ago
Matthew Butterick 634c1d1f51 update 7 years ago
Matthew Butterick 965ebdde57 add #:context argument to prefix-id et al 7 years ago
Matthew Butterick c1e2939aa6 simplify runtime config 7 years ago
Matthew Butterick 5cc0f73028 repl setup 7 years ago
Matthew Butterick 8be5afd15c remove comment 7 years ago
Matthew Butterick e571d9b372 support shell args 7 years ago
Matthew Butterick 29f13113f7 resume in runtime repl 7 years ago
Matthew Butterick 841f12e09a start demo 3 7 years ago
Matthew Butterick bfbdee9f79 stx-flatten 7 years ago
Matthew Butterick c3eed21f32 Update README.md 7 years ago
Matthew Butterick 05319d0b2f don't test brag 7 years ago
Matthew Butterick 9279ac21da correction 7 years ago
Matthew Butterick b799b4ee28 Update `brag` paths 7 years ago
Matthew Butterick 48cd7f0082 move brag 7 years ago
Matthew Butterick 1dc08fbe92 tidy 7 years ago
Matthew Butterick 5b894d8ae8 tidying 7 years ago
Matthew Butterick 18081e6d6e tidying 7 years ago
Matthew Butterick 50bd8e6301 copy edits 7 years ago
Matthew Butterick d4d5ea638d document push! and pop! 7 years ago
Matthew Butterick f932378a9d touchups 7 years ago
Matthew Butterick 706e20b5fb fiddle with `case-pattern` 7 years ago
Matthew Butterick 17785714fe deletion 7 years ago
Matthew Butterick 86e19e0c0e document `stx-flatten` 7 years ago
Matthew Butterick 92c5eb8a4d tidier 7 years ago
Matthew Butterick 86c57d32dd fix mod 7 years ago
Matthew Butterick c85b0e5cc9 take account of hide property in rule flattening (fixes #8) 7 years ago
Matthew Butterick cf505f2995 improve code comments 7 years ago
Matthew Butterick 711fa643bf null 7 years ago
Matthew Butterick 0652df09eb edits 7 years ago
Matthew Butterick 32acbeb501 updates 7 years ago
Matthew Butterick 33fe21405f add debug dialects 7 years ago
Matthew Butterick 4e5f6d9acd move 7 years ago
Matthew Butterick 1f770220b7 modularize run 7 years ago
Matthew Butterick 26dd72cb7a whitespace 7 years ago
Matthew Butterick c8979b15b8 update docs 7 years ago
Matthew Butterick 024d826003 update docs link 7 years ago
Matthew Butterick 6c3c0940ad rename some identifiers 7 years ago
Matthew Butterick e054cc1273 update sample files 7 years ago
Matthew Butterick 7b573be83c updates 7 years ago
Matthew Butterick 1902d283c9 adjust colorer 7 years ago
Matthew Butterick fad102d545 adjust rem semantics 7 years ago
Matthew Butterick f49f42003a reorg 7 years ago
Matthew Butterick acf9e65315 reorg 7 years ago
Matthew Butterick 715b9c0f1d tiny renaming 7 years ago
Matthew Butterick 422b3d105d update lexer test 7 years ago
Matthew Butterick a48b7824f1 add multiple print args 7 years ago
Matthew Butterick f9d6aa5d18 add basic colorer 7 years ago
Matthew Butterick 31220fc2db add `apply-colorer` 7 years ago
Matthew Butterick 4462141a41 remove `b-func` 7 years ago
Matthew Butterick 0ad47dd273 tweak 7 years ago
Matthew Butterick cc4b7d358c consolidate 7 years ago
Matthew Butterick 696a73052b tidying 7 years ago
Matthew Butterick 12bc37145a handle negative numbers, for / next 7 years ago
Matthew Butterick d0ced4022f remove tech links 7 years ago
Matthew Butterick db8346ceac doc corrections 7 years ago
Matthew Butterick 1f1ea325ec document cuts & splices 7 years ago
Matthew Butterick c5a1126754 new sample grammar 7 years ago
Matthew Butterick 3bc9fc3173 update docs 7 years ago
Matthew Butterick 7ddf8b594d update docs 7 years ago
Matthew Butterick 4c02bf36cd rename `parse-tree` as `parse-to-datum` 7 years ago
Matthew Butterick c58ac2a806 set up basic-demo-2 7 years ago
Matthew Butterick d0f83eb24a add `push!` and `pop!` 7 years ago
Matthew Butterick a0c9de7535 improve error reporting in `with-pattern` 7 years ago
Matthew Butterick 41bf0b964a adjust 7 years ago
Matthew Butterick 42d14dec74 update 7 years ago
Matthew Butterick c43a486f9d add literal generator to `with-pattern` 7 years ago
Matthew Butterick 347722bc27 rearrangements 7 years ago
Matthew Butterick 88b731cb72 detail 7 years ago
Matthew Butterick de98d96c74 basic updates 7 years ago
Matthew Butterick 2392559263 edit 7 years ago
Matthew Butterick c149b13003 edits 7 years ago
Matthew Butterick bd180e6ed6 update lexer 7 years ago
Matthew Butterick 46f6ab0c36 use newlines in lexer 7 years ago
Matthew Butterick 8504cd4d80 stricter about line breaks, less finicky about blank statements 7 years ago
Matthew Butterick eab018a9a2 add `from/stop-before` 7 years ago
Matthew Butterick 0f576805ac Update .travis.yml 7 years ago
Matthew Butterick d1205bb8c2 add `lexer-file-path` 7 years ago
Matthew Butterick 728a06cf0e change doc title 7 years ago
Matthew Butterick 509de033a0 tweakage 7 years ago
Matthew Butterick 85ecc17a9d more 7 years ago
Matthew Butterick 4032a65eb8 add `apply-lexer` 7 years ago
Matthew Butterick d4fe2c92ea return-without-srcloc 7 years ago
Matthew Butterick 5ef1a11a2b quick fix 7 years ago
Matthew Butterick c4f90daf74 spaces 7 years ago
Matthew Butterick 6221ca5959 refactor 7 years ago
Matthew Butterick 50eb4964cd bf-loop nits 7 years ago
Matthew Butterick f25679622a updates 7 years ago
Matthew Butterick 87009e367b changes 7 years ago
Matthew Butterick aa43154777 the tightening 7 years ago
Matthew Butterick afa9af72d8 better names in jsonic 7 years ago
Matthew Butterick 2eb46aaa81 change op & loop to use bf- prefix 7 years ago
Matthew Butterick 7a7e162988 update reader & tokenizer 7 years ago
Matthew Butterick 3347a86c0d update reader & tokenizer 7 years ago
Matthew Butterick fb26d2b7cd change name 7 years ago
Matthew Butterick 5607a7aa02 update docs 7 years ago
Matthew Butterick d20c328d93 renames 7 years ago
Matthew Butterick 1f9b0db91d adjust funstacker module name 7 years ago
Matthew Butterick 5197b0b82f adjust deps 7 years ago
Matthew Butterick 4e950845d6 adjust deps 7 years ago
Matthew Butterick db8f029d5c adjust deps 7 years ago
Matthew Butterick 8a8a780936 delete local docs 7 years ago
Matthew Butterick 906215d03e Update .travis.yml 7 years ago
Matthew Butterick 9e0e64f6d2 Update .travis.yml 7 years ago
Matthew Butterick 5723af898e use br-parser-tools 7 years ago
Matthew Butterick 86df35057c fork parser tools 7 years ago

@ -0,0 +1,72 @@
name: CI
on: [push, pull_request]
jobs:
run:
name: "Build using Racket '${{ matrix.racket-version }}' (${{ matrix.racket-variant }})"
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.xfail == 'yes' }}
strategy:
fail-fast: false
matrix:
racket-version: ["6.7", "6.8", "6.9", "6.11", "6.12", "7.0", "7.1", "7.2", "7.3", "7.4", "7.5", "7.6", "7.7", "7.8", "7.9", "8.0", "8.1", "current"]
racket-variant: ["BC", "CS"]
# CS builds are only provided for versions 7.4 and up so avoid
# running the job for prior versions.
exclude:
- {racket-version: "6.6", racket-variant: "CS"}
- {racket-version: "6.7", racket-variant: "CS"}
- {racket-version: "6.8", racket-variant: "CS"}
- {racket-version: "6.9", racket-variant: "CS"}
- {racket-version: "6.10.1", racket-variant: "CS"}
- {racket-version: "6.11", racket-variant: "CS"}
- {racket-version: "6.12", racket-variant: "CS"}
- {racket-version: "7.0", racket-variant: "CS"}
- {racket-version: "7.1", racket-variant: "CS"}
- {racket-version: "7.2", racket-variant: "CS"}
- {racket-version: "7.3", racket-variant: "CS"}
include:
- {racket-version: "6.7", racket-variant: "BC", xfail: "yes"}
- {racket-version: "7.7", racket-variant: "CS", xfail: "yes"}
- {racket-version: "7.8", racket-variant: "CS", xfail: "yes"}
- {racket-version: "7.9", racket-variant: "CS", xfail: "yes"}
- {racket-version: "current", racket-variant: "BC", xfail: "yes"}
- {racket-version: "current", racket-variant: "CS", xfail: "yes"}
env:
DISPLAY: :99
steps:
- name: Checkout
uses: actions/checkout@master
- uses: Bogdanp/setup-racket@v0.11
with:
distribution: 'full'
version: ${{ matrix.racket-version }}
variant: ${{ matrix.racket-variant }}
- name: Install package and its dependencies
run: raco pkg install --deps search-auto https://github.com/mbutterick/br-parser-tools.git?path=br-parser-tools-lib
- name: install brag
run: raco pkg install --deps search-auto https://github.com/mbutterick/brag.git?path=brag
- name: install br-macro
run: raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket-macro
- name: install br lib
run: raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket-lib
- name: install br demo
run: raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket-demo
- name: install br
run: raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket
- name: Start virtual framebuffer
run: Xvfb "$DISPLAY" -screen 0 1280x1024x24 &
- name: Run the brm tests
run: raco test -p beautiful-racket-macro
- name: Run the lib tests
run: raco test -p beautiful-racket-lib
- name: Run the demo tests
run: raco test -p beautiful-racket-demo
- name: Run the br tests
run: raco test -p beautiful-racket

3
.gitignore vendored

@ -21,4 +21,5 @@ scribblings/*.css
!scribblings/mb.css
scribblings/*.html
scribblings/pollen/*
doc/*
beautiful-racket-lib/br/doc/*
beautiful-racket-demo/jsonic-demo-3/doc/*

@ -1,48 +0,0 @@
# 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:
- "export DISPLAY=:99.0" # needed for testing with `racket/gui`
- "sh -e /etc/init.d/xvfb start" # needed for testing with `racket/gui`
- 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/beautiful-racket.git?path=beautiful-racket-lib
- raco test -p beautiful-racket-lib
- travis_retry raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=brag
- raco test -p brag
- travis_retry raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket-demo
- raco test -p beautiful-racket-demo
- travis_retry raco pkg install --deps search-auto https://github.com/mbutterick/beautiful-racket.git?path=beautiful-racket
- raco test -p beautiful-racket

@ -1,165 +0,0 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

@ -1,3 +0,0 @@
Beautiful Racket
© 2016 Matthew Butterick
Licensed under the LGPL (see "LGPL.txt")

@ -0,0 +1,9 @@
MIT License for `beautiful-racket`
© 2016-2019 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.

@ -1,23 +1,34 @@
beautiful-racket [![Build Status](https://travis-ci.org/mbutterick/beautiful-racket.svg?branch=master)](https://travis-ci.org/mbutterick/beautiful-racket)
-
## beautiful-racket [![Build Status](https://github.com/mbutterick/beautiful-racket/workflows/CI/badge.svg)](https://github.com/mbutterick/beautiful-racket/actions)
Resources for the upcoming “Beautiful Racket” book, including:
* `#lang br` teaching language
Resources for the “Beautiful Racket” book, including:
* `#lang brag` parser generator language (a fork of Danny Yoo's [ragg](http://github.com/jbclements/ragg))
* `#lang br` teaching language
* supporting modules
* sample languages
Installation:
## Installation
`raco pkg install beautiful-racket`
Update:
## Update
`raco pkg update --update-deps beautiful-racket`
## Documentation
http://docs.racket-lang.org/br
## License
MIT
## Project status
`raco pkg update beautiful-racket`
Complete. I will maintain the code but no major updates are planned.

@ -0,0 +1,6 @@
#lang brag
top : (fun | app)*
fun : /"fun" ID /"(" ID [/"," ID] /")" /"=" expr
expr : ID /"+" ID | app
app : ID /"(" (ID | INT) [/"," ID] /")"

@ -0,0 +1,36 @@
#lang br/quicklang
(require brag/support "grammar.rkt")
(provide top fun expr app)
(module+ reader
(provide read-syntax))
(define-lex-abbrev reserved-toks
(:or "fun" "(" ")" "=" "+" ","))
(define tokenize-1
(lexer
[whitespace (token lexeme #:skip? #t)]
[(from/stop-before "#" "\n") (token 'COMMENT #:skip? #t)]
[reserved-toks lexeme]
[(:+ alphabetic) (token 'ID (string->symbol lexeme))]
[(:+ (char-set "0123456789")) (token 'INT (string->number lexeme))]))
(define-macro top #'#%module-begin)
(define-macro-cases fun
[(_ VAR ARG0 EXPR) #'(define (VAR ARG0) EXPR)]
[(_ VAR ARG0 ARG1 EXPR) #'(define (VAR ARG0 ARG1) EXPR)])
(define-macro-cases expr
[(_ LEFT RIGHT) #'(+ LEFT RIGHT)]
[(_ OTHER) #'OTHER])
(define-macro app #'#%app)
(define (read-syntax src ip)
(define parse-tree (parse src (λ () (tokenize-1 ip))))
(strip-bindings
(with-syntax ([PT parse-tree])
#'(module algebra-mod algebra-demo
PT))))

@ -0,0 +1,6 @@
#lang algebra-demo
fun f(x,y) = x + y
# fun f(x,y) = x * y
fun g(zz) = f(zz,zz)
g(10)
g(23)

@ -0,0 +1,16 @@
#lang br
(provide #%top-interaction #%module-begin
(rename-out [my-datum #%datum]
[my-datum #%top]
[my-app #%app]))
(define-syntax (my-datum stx)
(syntax-case stx ()
[(_ . THING) #''taco]))
(define-syntax (my-app stx)
(syntax-case stx ()
[(_ FUNC . ARGS) #'(list (my-datum) . ARGS)]))
(module reader syntax/module-reader
atomic-taco-demo)

@ -0,0 +1,4 @@
#lang atomic-taco-demo
"hello world"
(+ 1 (* 2 (- x)))

@ -0,0 +1,32 @@
#lang br
(require "lexer.rkt" brag/support)
(provide basic-colorer)
(define (basic-colorer port)
(define (handle-lexer-error excn)
(define excn-srclocs (exn:fail:read-srclocs excn))
(srcloc-token (token 'ERROR) (car excn-srclocs)))
(define srcloc-tok
(with-handlers ([exn:fail:read? handle-lexer-error])
(basic-lexer port)))
(match srcloc-tok
[(? eof-object?) (values srcloc-tok 'eof #f #f #f)]
[else
(match-define
(srcloc-token
(token-struct type val _ _ _ _ _)
(srcloc _ _ _ posn span)) srcloc-tok)
(define start posn)
(define end (+ start span))
(match-define (list cat paren)
(match type
['STRING '(string #f)]
['REM '(comment #f)]
['ERROR '(error #f)]
[else (match val
[(? number?) '(constant #f)]
[(? symbol?) '(symbol #f)]
["(" '(parenthesis |(|)]
[")" '(parenthesis |)|)]
[else '(no-color #f)])]))
(values val cat paren start end)]))

@ -0,0 +1,41 @@
#lang br
(require "go.rkt")
(provide b-if b-or-expr b-and-expr b-not-expr b-comp-expr)
(define (bool->int val) (if val 1 0))
(define nonzero? (compose1 not zero?))
(define-macro-cases b-or-expr
[(_ VAL) #'VAL]
[(_ LEFT "or" RIGHT)
#'(bool->int (or (nonzero? LEFT) (nonzero? RIGHT)))])
(define-macro-cases b-and-expr
[(_ VAL) #'VAL]
[(_ LEFT "and" RIGHT)
#'(bool->int (and (nonzero? LEFT) (nonzero? RIGHT)))])
(define-macro-cases b-not-expr
[(_ VAL) #'VAL]
[(_ "not" VAL) #'(if (nonzero? VAL) 0 1)])
(define b= (compose1 bool->int =))
(define b< (compose1 bool->int <))
(define b> (compose1 bool->int >))
(define b<> (compose1 bool->int not =))
(define-macro-cases b-comp-expr
[(_ VAL) #'VAL]
[(_ LEFT "=" RIGHT) #'(b= LEFT RIGHT)]
[(_ LEFT "<" RIGHT) #'(b< LEFT RIGHT)]
[(_ LEFT ">" RIGHT) #'(b> LEFT RIGHT)]
[(_ LEFT "<>" RIGHT) #'(b<> LEFT RIGHT)])
(define-macro-cases b-if
[(_ COND-EXPR THEN-EXPR) #'(b-if COND-EXPR THEN-EXPR (void))]
[(_ COND-EXPR THEN-EXPR ELSE-EXPR)
#'(let ([result (if (nonzero? COND-EXPR)
THEN-EXPR
ELSE-EXPR)])
(when (exact-positive-integer? result)
(b-goto result)))])

@ -0,0 +1,6 @@
#lang br
(require "line.rkt" "go.rkt"
"expr.rkt" "misc.rkt" "cond.rkt")
(provide
(all-from-out "line.rkt" "go.rkt"
"expr.rkt" "misc.rkt" "cond.rkt"))

@ -0,0 +1,26 @@
#lang br/quicklang
(require "struct.rkt" "run.rkt" "elements.rkt")
(provide (rename-out [b-module-begin #%module-begin])
(all-from-out "elements.rkt"))
(define-macro (b-module-begin (b-program LINE ...))
(with-pattern
([((b-line NUM STMT ...) ...) #'(LINE ...)]
[(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))]
[(VAR-ID ...) (find-unique-var-ids #'(LINE ...))])
#'(#%module-begin
(define VAR-ID 0) ...
LINE ...
(define line-table
(apply hasheqv (append (list NUM LINE-FUNC) ...)))
(void (run line-table)))))
(begin-for-syntax
(require racket/list)
(define (find-unique-var-ids line-stxs)
(remove-duplicates
(for/list ([stx (in-list (stx-flatten line-stxs))]
#:when (syntax-property stx 'b-id))
stx)
#:key syntax->datum)))

@ -0,0 +1,24 @@
#lang br
(provide b-expr b-sum b-product b-neg b-expt)
(define (b-expr expr)
(if (integer? expr) (inexact->exact expr) expr))
(define-macro-cases b-sum
[(_ VAL) #'VAL]
[(_ LEFT "+" RIGHT) #'(+ LEFT RIGHT)]
[(_ LEFT "-" RIGHT) #'(- LEFT RIGHT)])
(define-macro-cases b-product
[(_ VAL) #'VAL]
[(_ LEFT "*" RIGHT) #'(* LEFT RIGHT)]
[(_ LEFT "/" RIGHT) #'(/ LEFT RIGHT 1.0)]
[(_ LEFT "mod" RIGHT) #'(modulo LEFT RIGHT)])
(define-macro-cases b-neg
[(_ VAL) #'VAL]
[(_ "-" VAL) #'(- VAL)])
(define-macro-cases b-expt
[(_ VAL) #'VAL]
[(_ LEFT "^" RIGHT) #'(expt LEFT RIGHT)])

@ -0,0 +1,52 @@
#lang br
(require "struct.rkt" "line.rkt" "misc.rkt")
(provide b-end b-goto b-gosub b-return b-for b-next)
(define (b-end) (raise (end-program-signal)))
(define (b-goto num-expr)
(raise (change-line-signal num-expr)))
(define return-ccs empty)
(define (b-gosub num-expr)
(let/cc this-cc
(push! return-ccs this-cc)
(b-goto num-expr)))
(define (b-return)
(when (empty? return-ccs)
(raise-line-error "return without gosub"))
(define top-cc (pop! return-ccs))
(top-cc (void)))
(define next-funcs (make-hasheq))
(define-macro-cases b-for
[(_ LOOP-ID START END) #'(b-for LOOP-ID START END 1)]
[(_ LOOP-ID START END STEP)
#'(b-let LOOP-ID
(let/cc loop-cc
(hash-set! next-funcs
'LOOP-ID
(λ ()
(define next-val
(+ LOOP-ID STEP))
(if (next-val
. in-closed-interval? .
START END)
(loop-cc next-val)
(hash-remove! next-funcs
'LOOP-ID))))
START))])
(define (in-closed-interval? x start end)
((if (< start end) <= >=) start x end))
(define-macro (b-next LOOP-ID)
#'(begin
(unless (hash-has-key? next-funcs 'LOOP-ID)
(raise-line-error
(format "`next ~a` without for" 'LOOP-ID)))
(define func (hash-ref next-funcs 'LOOP-ID))
(func)))

@ -0,0 +1,4 @@
#lang info
(define compile-omit-paths '("private"))
(define test-omit-paths '("private" "sample-input.rkt"))

@ -0,0 +1,25 @@
#lang br
(require brag/support)
(define-lex-abbrev digits (:+ (char-set "0123456789")))
(define-lex-abbrev reserved-terms (:or "print" "goto" "end" "+" ":" ";" "let" "=" "input" "-" "*" "/" "^" "mod" "(" ")" "if" "then" "else" "<" ">" "<>" "and" "or" "not" "gosub" "return" "for" "to" "step" "next"))
(define basic-lexer
(lexer-srcloc
["\n" (token 'NEWLINE lexeme)]
[whitespace (token lexeme #:skip? #t)]
[(from/stop-before "rem" "\n") (token 'REM lexeme)]
[reserved-terms (token lexeme lexeme)]
[(:seq alphabetic (:* (:or alphabetic numeric "$")))
(token 'ID (string->symbol lexeme))]
[digits (token 'INTEGER (string->number lexeme))]
[(:or (:seq (:? digits) "." digits)
(:seq digits "."))
(token 'DECIMAL (string->number lexeme))]
[(:or (from/to "\"" "\"") (from/to "'" "'"))
(token 'STRING
(substring lexeme
1 (sub1 (string-length lexeme))))]))
(provide basic-lexer)

@ -0,0 +1,22 @@
#lang br
(require "struct.rkt")
(provide b-line raise-line-error)
(define-macro (b-line NUM STATEMENT ...)
(with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
#:source #'NUM)])
(syntax/loc caller-stx
(define (LINE-NUM #:error [msg #f])
(with-handlers
([line-error?
(λ (le) (handle-line-error NUM le))])
(when msg (raise-line-error msg))
STATEMENT ...)))))
(define (raise-line-error error-msg)
(raise (line-error error-msg)))
(define (handle-line-error num le)
(error (format "error in line ~a: ~a"
num (line-error-msg le))))

@ -0,0 +1,19 @@
#lang br/quicklang
(require "parser.rkt" "tokenizer.rkt")
(module+ reader
(provide read-syntax get-info))
(define (read-syntax path port)
(define parse-tree (parse path (make-tokenizer port path)))
(strip-bindings
#`(module basic-mod basic-demo-2/expander
#,parse-tree)))
(define (get-info port src-mod src-line src-col src-pos)
(define (handle-query key default)
(case key
[(color-lexer)
(dynamic-require 'basic-demo-2/colorer 'basic-colorer)]
[else default]))
handle-query)

@ -0,0 +1,15 @@
#lang br
(require "struct.rkt")
(provide b-rem b-print b-let b-input)
(define (b-rem val) (void))
(define (b-print . vals)
(displayln (string-append* (map ~a vals))))
(define-macro (b-let ID VAL) #'(set! ID VAL))
(define-macro (b-input ID)
#'(b-let ID (let* ([str (read-line)]
[num (string->number (string-trim str))])
(or num str))))

@ -0,0 +1,14 @@
#lang br/quicklang
(require "parser.rkt" "tokenizer.rkt")
(define (read-syntax path port)
(define parse-tree (parse path (make-tokenizer port path)))
(strip-bindings
#`(module basic-parser-mod basic-demo-2/parse-only
#,parse-tree)))
(module+ reader (provide read-syntax))
(define-macro (parser-only-mb PARSE-TREE)
#'(#%module-begin
'PARSE-TREE))
(provide (rename-out [parser-only-mb #%module-begin]))

@ -0,0 +1,15 @@
#lang br/quicklang
(require "parser.rkt" "tokenizer.rkt")
(define (read-syntax path port)
(define parse-tree (parse path (make-tokenizer port path)))
(strip-bindings
#`(module basic-parser-mod basic-demo-2/parse-stx
#'#,parse-tree)))
(module+ reader (provide read-syntax))
(define-macro (parser-only-mb PARSE-STX)
#'(#%module-begin
PARSE-STX))
(provide (rename-out [parser-only-mb #%module-begin]))
(provide syntax)

@ -0,0 +1,32 @@
#lang brag
b-program : [b-line] (/NEWLINE [b-line])*
b-line : b-line-num [b-statement] (/":" [b-statement])* [b-rem]
@b-line-num : INTEGER
b-rem : REM
@b-statement : b-end | b-print | b-goto
| b-let | b-input | b-if
| b-gosub | b-return | b-for | b-next
b-end : /"end"
b-print : /"print" [b-printable] (/";" [b-printable])*
@b-printable : STRING | b-expr
b-goto : /"goto" b-expr
b-let : [/"let"] b-id /"=" (STRING | b-expr)
b-if : /"if" b-expr /"then" (b-statement | b-expr)
[/"else" (b-statement | b-expr)]
b-input : /"input" b-id
@b-id : ID
b-gosub : /"gosub" b-expr
b-return : /"return"
b-for : /"for" b-id /"=" b-expr /"to" b-expr [/"step" b-expr]
b-next : /"next" b-id
b-expr : b-or-expr
b-or-expr : [b-or-expr "or"] b-and-expr
b-and-expr : [b-and-expr "and"] b-not-expr
b-not-expr : ["not"] b-comp-expr
b-comp-expr : [b-comp-expr ("="|"<"|">"|"<>")] b-sum
b-sum : [b-sum ("+"|"-")] b-product
b-product : [b-product ("*"|"/"|"mod")] b-neg
b-neg : ["-"] b-expt
b-expt : [b-expt ("^")] b-value
@b-value : b-number | b-id | /"(" b-expr /")"
@b-number : INTEGER | DECIMAL

@ -0,0 +1,8 @@
(define (30) (rem print "'ignored'"))
(define (35) (void))
(define (50) (print "never gets here"))
(define (40) (end))
(define (60) (print "three") (print (+ 1.0 3)))
(define (70) (goto (+ 11 18.5 0.5)))
(define (10) (print "one"))
(define (20) (print) (goto 60) (end))

@ -0,0 +1,23 @@
#lang br
(require "line.rkt" "struct.rkt")
(provide run)
(define (run line-table)
(define line-vec
(list->vector (sort (hash-keys line-table) <)))
(with-handlers ([end-program-signal? (λ (exn-val) (void))])
(for/fold ([line-idx 0])
([i (in-naturals)]
#:break (>= line-idx (vector-length line-vec)))
(define line-num (vector-ref line-vec line-idx))
(define line-func (hash-ref line-table line-num))
(with-handlers
([change-line-signal?
(λ (cls)
(define clsv (change-line-signal-val cls))
(or
(and (exact-positive-integer? clsv)
(vector-member clsv line-vec))
(line-func #:error (format "line ~a not found" clsv))))])
(line-func)
(add1 line-idx)))))

@ -0,0 +1,8 @@
#lang basic-demo-2
10 rem all results should be 1
20 a = 5
30 b = 10
40 print a > 4
50 print b = 10
60 print b < 11
70 print rem (b = 100)

@ -0,0 +1,6 @@
#lang basic-demo-2
10 for a = 1 to 3
21 for b = 9 to 7 step -1
22 print a ; b
23 next b
30 next a

@ -0,0 +1,10 @@
#lang basic-demo-2
10 gosub 41
20 print "world"
30 gosub 100
31 print "hi"
35 end
40 return
41 print "hello" : return
100 print "third"
110 goto 40

@ -0,0 +1,4 @@
#lang basic-demo-2
5 print "enter your name: "
10 input A$
20 print "hello, " ; A$ ; "!"

@ -0,0 +1,9 @@
#lang basic-demo-2
10 rem all results should be 1
20 print 1 - 2 * 3 + 4 * 5 - 6 = 9
30 print (1 - 2) * (3 + 4) * (5 - 6) = 7
40 print 1 / 4 = .25
50 print 2 ^ 3 = 8
60 print 9 ^ 0.5 = 3
70 print 6 mod 2 = 0
80 print 5 mod 2 = 1

@ -0,0 +1,8 @@
#lang basic-demo-2
10 a = 1 : a = 5
20 gosub 150
30 a = 25
40 gosub 150
50 end
150 print a + a + a
160 return

@ -0,0 +1,9 @@
#lang basic-demo-2
30 rem print 'ignored'
35
50 print "never gets here"
40 end
60 print 'three' : print 1.0 + 3
70 goto 11. + 18.5 + .5 rem ignored
10 print "o" ; "n" ; "e"
20 print : goto 60.0 : end

@ -0,0 +1,8 @@
#lang br
(provide (struct-out end-program-signal)
(struct-out change-line-signal)
(struct-out line-error))
(struct end-program-signal ())
(struct change-line-signal (val))
(struct line-error (msg))

@ -0,0 +1,34 @@
#lang at-exp br
(require br/test rackunit)
(check-equal? (run-source "sample.rkt") "one
three
4
")
(check-equal? (run-source "sample-var.rkt") "15
75
")
(check-equal? (run-source "sample-math.rkt") "1
1
1
1
1
1
1
")
(check-equal? (run-source "sample-gosub.rkt") "hello
world
third
hi
")
(check-equal? (run-source "sample-for.rkt") "19
18
17
29
28
27
39
38
37
")

@ -0,0 +1,10 @@
#lang br
(require "lexer.rkt" brag/support)
(define (make-tokenizer ip [path #f])
(port-count-lines! ip)
(lexer-file-path path)
(define (next-token) (basic-lexer ip))
next-token)
(provide make-tokenizer)

@ -0,0 +1,6 @@
#lang br
(require "line.rkt" "go.rkt"
"expr.rkt" "misc.rkt")
(provide
(all-from-out "line.rkt" "go.rkt"
"expr.rkt" "misc.rkt"))

@ -0,0 +1,16 @@
#lang br/quicklang
(require "struct.rkt" "run.rkt" "elements.rkt")
(provide (rename-out [b-module-begin #%module-begin])
(all-from-out "elements.rkt"))
(define-macro (b-module-begin (b-program LINE ...))
(with-pattern
([((b-line NUM STMT ...) ...) #'(LINE ...)]
[(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))])
#'(#%module-begin
LINE ...
(define line-table
(apply hasheqv (append (list NUM LINE-FUNC) ...)))
(void (run line-table)))))

@ -0,0 +1,7 @@
#lang br
(provide b-sum b-expr)
(define (b-sum . vals) (apply + vals))
(define (b-expr expr)
(if (integer? expr) (inexact->exact expr) expr))

@ -0,0 +1,8 @@
#lang br
(require "struct.rkt" "line.rkt")
(provide b-end b-goto)
(define (b-end) (raise (end-program-signal)))
(define (b-goto num-expr)
(raise (change-line-signal num-expr)))

@ -0,0 +1,22 @@
#lang br
(require brag/support)
(define-lex-abbrev digits (:+ (char-set "0123456789")))
(define basic-lexer
(lexer-srcloc
["\n" (token 'NEWLINE lexeme)]
[whitespace (token lexeme #:skip? #t)]
[(from/stop-before "rem" "\n") (token 'REM lexeme)]
[(:or "print" "goto" "end"
"+" ":" ";") (token lexeme lexeme)]
[digits (token 'INTEGER (string->number lexeme))]
[(:or (:seq (:? digits) "." digits)
(:seq digits "."))
(token 'DECIMAL (string->number lexeme))]
[(:or (from/to "\"" "\"") (from/to "'" "'"))
(token 'STRING
(substring lexeme
1 (sub1 (string-length lexeme))))]))
(provide basic-lexer)

@ -0,0 +1,9 @@
#lang br
(require "struct.rkt")
(provide b-line)
(define-macro (b-line NUM STATEMENT ...)
(with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
#:source #'NUM)])
(syntax/loc caller-stx
(define (LINE-NUM) (void) STATEMENT ...))))

@ -0,0 +1,11 @@
#lang br/quicklang
(require "parser.rkt" "tokenizer.rkt")
(module+ reader
(provide read-syntax))
(define (read-syntax path port)
(define parse-tree (parse path (make-tokenizer port path)))
(strip-bindings
#`(module basic-mod basic-demo-2a/expander
#,parse-tree)))

@ -0,0 +1,8 @@
#lang br
(require "struct.rkt")
(provide b-rem b-print)
(define (b-rem val) (void))
(define (b-print . vals)
(displayln (string-append* (map ~a vals))))

@ -0,0 +1,13 @@
#lang brag
b-program : [b-line] (/NEWLINE [b-line])*
b-line : b-line-num [b-statement] (/":" [b-statement])* [b-rem]
@b-line-num : INTEGER
@b-statement : b-end | b-print | b-goto
b-rem : REM
b-end : /"end"
b-print : /"print" [b-printable] (/";" [b-printable])*
@b-printable : STRING | b-expr
b-goto : /"goto" b-expr
b-expr : b-sum
b-sum : b-number (/"+" b-number)*
@b-number : INTEGER | DECIMAL

@ -0,0 +1,24 @@
#lang br
(require "line.rkt" "struct.rkt")
(provide run)
(define (run line-table)
(define line-vec
(list->vector (sort (hash-keys line-table) <)))
(with-handlers ([end-program-signal? (λ (exn-val) (void))])
(for/fold ([line-idx 0])
([i (in-naturals)]
#:break (>= line-idx (vector-length line-vec)))
(define line-num (vector-ref line-vec line-idx))
(define line-func (hash-ref line-table line-num))
(with-handlers
([change-line-signal?
(λ (cls)
(define clsv (change-line-signal-val cls))
(or
(and (exact-positive-integer? clsv)
(vector-member clsv line-vec))
(error (format "error in line ~a: line ~a not found"
line-num clsv))))])
(line-func)
(add1 line-idx)))))

@ -0,0 +1,9 @@
#lang basic-demo
30 rem print 'ignored'
35
50 print "never gets here"
40 end
60 print 'three' : print 1.0 + 3
70 goto 11. + 18.5 + .5 rem ignored
10 print "o" ; "n" ; "e"
20 print : goto 60.0 : end

@ -0,0 +1,6 @@
#lang br
(provide (struct-out end-program-signal)
(struct-out change-line-signal))
(struct end-program-signal ())
(struct change-line-signal (val))

@ -0,0 +1,8 @@
#lang at-exp br
(require br/test rackunit)
(check-equal? (run-source "sample.rkt") "one
three
4
")

@ -0,0 +1,10 @@
#lang br
(require "lexer.rkt" brag/support)
(define (make-tokenizer ip [path #f])
(port-count-lines! ip)
(lexer-file-path path)
(define (next-token) (basic-lexer ip))
next-token)
(provide make-tokenizer)

@ -0,0 +1,2 @@
#lang br
(current-command-line-arguments)

@ -0,0 +1,32 @@
#lang br
(require "lexer.rkt" brag/support)
(provide basic-colorer)
(define (basic-colorer port)
(define (handle-lexer-error excn)
(define excn-srclocs (exn:fail:read-srclocs excn))
(srcloc-token (token 'ERROR) (car excn-srclocs)))
(define srcloc-tok
(with-handlers ([exn:fail:read? handle-lexer-error])
(basic-lexer port)))
(match srcloc-tok
[(? eof-object?) (values srcloc-tok 'eof #f #f #f)]
[else
(match-define
(srcloc-token
(token-struct type val _ _ _ _ _)
(srcloc _ _ _ posn span)) srcloc-tok)
(define start posn)
(define end (+ start span))
(match-define (list cat paren)
(match type
['STRING '(string #f)]
['REM '(comment #f)]
['ERROR '(error #f)]
[else (match val
[(? number?)'(constant #f)]
[(? symbol?) '(symbol #f)]
["(" '(parenthesis |(|)]
[")" '(parenthesis |)|)]
[else '(no-color #f)])]))
(values val cat paren start end)]))

@ -0,0 +1,41 @@
#lang br
(require "go.rkt")
(provide b-if b-or-expr b-and-expr b-not-expr b-comp-expr)
(define (bool->int val) (if val 1 0))
(define nonzero? (compose1 not zero?))
(define-macro-cases b-or-expr
[(_ VAL) #'VAL]
[(_ LEFT "or" RIGHT)
#'(bool->int (or (nonzero? LEFT) (nonzero? RIGHT)))])
(define-macro-cases b-and-expr
[(_ VAL) #'VAL]
[(_ LEFT "and" RIGHT)
#'(bool->int (and (nonzero? LEFT) (nonzero? RIGHT)))])
(define-macro-cases b-not-expr
[(_ VAL) #'VAL]
[(_ "not" VAL) #'(if (nonzero? VAL) 0 1)])
(define b= (compose1 bool->int =))
(define b< (compose1 bool->int <))
(define b> (compose1 bool->int >))
(define b<> (compose1 bool->int not =))
(define-macro-cases b-comp-expr
[(_ VAL) #'VAL]
[(_ LEFT "=" RIGHT) #'(b= LEFT RIGHT)]
[(_ LEFT "<" RIGHT) #'(b< LEFT RIGHT)]
[(_ LEFT ">" RIGHT) #'(b> LEFT RIGHT)]
[(_ LEFT "<>" RIGHT) #'(b<> LEFT RIGHT)])
(define-macro-cases b-if
[(_ COND-EXPR THEN-EXPR) #'(b-if COND-EXPR THEN-EXPR (void))]
[(_ COND-EXPR THEN-EXPR ELSE-EXPR)
#'(let ([result (if (nonzero? COND-EXPR)
THEN-EXPR
ELSE-EXPR)])
(when (exact-positive-integer? result)
(b-goto result)))])

@ -0,0 +1,6 @@
#lang br
(require "line.rkt" "go.rkt"
"expr.rkt" "misc.rkt" "cond.rkt")
(provide
(all-from-out "line.rkt" "go.rkt"
"expr.rkt" "misc.rkt" "cond.rkt"))

@ -0,0 +1,58 @@
#lang br/quicklang
(require "struct.rkt" "run.rkt" "elements.rkt" "setup.rkt")
(provide (rename-out [b-module-begin #%module-begin])
(all-from-out "elements.rkt"))
(define-macro (b-module-begin (b-program LINE ...))
(with-pattern
([((b-line NUM STMT ...) ...) #'(LINE ...)]
[(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))]
[(VAR-ID ...) (find-property 'b-id #'(LINE ...))]
[(IMPORT-NAME ...)
(find-property 'b-import-name #'(LINE ...))]
[(EXPORT-NAME ...)
(find-property 'b-export-name #'(LINE ...))]
[((SHELL-ID SHELL-IDX) ...)
(make-shell-ids-and-idxs caller-stx)]
[(UNIQUE-ID ...)
(unique-ids
(syntax->list #'(VAR-ID ... SHELL-ID ...)))])
#'(#%module-begin
(module configure-runtime br
(require basic-demo-3/setup)
(do-setup!))
(require IMPORT-NAME) ...
(provide EXPORT-NAME ...)
(define UNIQUE-ID 0) ...
(let ([clargs (current-command-line-arguments)])
(set! SHELL-ID (get-clarg clargs SHELL-IDX)) ...)
LINE ...
(define line-table
(apply hasheqv (append (list NUM LINE-FUNC) ...)))
(parameterize
([current-output-port (basic-output-port)])
(void (run line-table))))))
(define (get-clarg clargs idx)
(if (<= (vector-length clargs) idx)
0
(let ([val (vector-ref clargs idx)])
(or (string->number val) val))))
(begin-for-syntax
(require racket/list)
(define (unique-ids stxs)
(remove-duplicates stxs #:key syntax->datum))
(define (find-property which line-stxs)
(unique-ids
(for/list ([stx (in-list (stx-flatten line-stxs))]
#:when (syntax-property stx which))
stx)))
(define (make-shell-ids-and-idxs ctxt)
(define arg-count 10)
(for/list ([idx (in-range arg-count)])
(list (suffix-id #'arg idx #:context ctxt) idx))))

@ -0,0 +1,45 @@
#lang br
(require "line.rkt")
(provide b-expr b-sum b-product b-neg b-expt b-def b-func)
(define (b-expr expr)
(if (integer? expr) (inexact->exact expr) expr))
(define-macro-cases b-sum
[(_ VAL) #'VAL]
[(_ LEFT "+" RIGHT) #'(+ LEFT RIGHT)]
[(_ LEFT "-" RIGHT) #'(- LEFT RIGHT)])
(define-macro-cases b-product
[(_ VAL) #'VAL]
[(_ LEFT "*" RIGHT) #'(* LEFT RIGHT)]
[(_ LEFT "/" RIGHT) #'(/ LEFT RIGHT 1.0)]
[(_ LEFT "mod" RIGHT) #'(modulo LEFT RIGHT)])
(define-macro-cases b-neg
[(_ VAL) #'VAL]
[(_ "-" VAL) #'(- VAL)])
(define-macro-cases b-expt
[(_ VAL) #'VAL]
[(_ LEFT "^" RIGHT) #'(expt LEFT RIGHT)])
(define-macro (b-def FUNC-ID VAR-ID ... EXPR)
(syntax-local-lift-expression
#'(set! FUNC-ID (λ (VAR-ID ...) EXPR))))
(define-macro (b-func FUNC-ID ARG ...)
#'(if (procedure? FUNC-ID)
(convert-result (FUNC-ID ARG ...))
(raise-line-error
(format "expected ~a to be a function, got ~v"
'FUNC-ID FUNC-ID))))
(define (convert-result result)
(cond
[(number? result) (b-expr result)]
[(string? result) result]
[(boolean? result) (if result 1 0)]
[else
(raise-line-error
(format "unknown data type: ~v" result))]))

@ -0,0 +1,52 @@
#lang br
(require "struct.rkt" "line.rkt" "misc.rkt")
(provide b-end b-goto b-gosub b-return b-for b-next)
(define (b-end) (raise (end-program-signal)))
(define (b-goto num-expr)
(raise (change-line-signal num-expr)))
(define return-ccs empty)
(define (b-gosub num-expr)
(let/cc this-cc
(push! return-ccs this-cc)
(b-goto num-expr)))
(define (b-return)
(when (empty? return-ccs)
(raise-line-error "return without gosub"))
(define top-cc (pop! return-ccs))
(top-cc (void)))
(define next-funcs (make-hasheq))
(define-macro-cases b-for
[(_ LOOP-ID START END) #'(b-for LOOP-ID START END 1)]
[(_ LOOP-ID START END STEP)
#'(b-let LOOP-ID
(let/cc loop-cc
(hash-set! next-funcs
'LOOP-ID
(λ ()
(define next-val
(+ LOOP-ID STEP))
(if (next-val
. in-closed-interval? .
START END)
(loop-cc next-val)
(hash-remove! next-funcs
'LOOP-ID))))
START))])
(define (in-closed-interval? x start end)
((if (< start end) <= >=) start x end))
(define-macro (b-next LOOP-ID)
#'(begin
(unless (hash-has-key? next-funcs 'LOOP-ID)
(raise-line-error
(format "`next ~a` without for" 'LOOP-ID)))
(define func (hash-ref next-funcs 'LOOP-ID))
(func)))

@ -0,0 +1,4 @@
#lang info
(define compile-omit-paths '("private"))
(define test-omit-paths '("private" "sample-input.rkt"))

@ -0,0 +1,31 @@
#lang br
(require brag/support)
(define-lex-abbrev digits (:+ (char-set "0123456789")))
(define-lex-abbrev reserved-terms (:or "print" "goto" "end" "+" ":" ";" "let" "=" "input" "-" "*" "/" "^" "mod" "(" ")" "if" "then" "else" "<" ">" "<>" "and" "or" "not" "gosub" "return" "for" "to" "step" "next" "def" "," "import" "export"))
(define-lex-abbrev racket-id-kapu
(:or whitespace (char-set "()[]{}\",'`;#|\\")))
(define basic-lexer
(lexer-srcloc
["\n" (token 'NEWLINE lexeme)]
[whitespace (token lexeme #:skip? #t)]
[(from/stop-before "rem" "\n") (token 'REM lexeme)]
[(:seq "[" (:+ (:~ racket-id-kapu)) "]")
(token 'RACKET-ID
(string->symbol (trim-ends "[" lexeme "]")))]
[reserved-terms (token lexeme lexeme)]
[(:seq alphabetic (:* (:or alphabetic numeric "$")))
(token 'ID (string->symbol lexeme))]
[digits (token 'INTEGER (string->number lexeme))]
[(:or (:seq (:? digits) "." digits)
(:seq digits "."))
(token 'DECIMAL (string->number lexeme))]
[(:or (from/to "\"" "\"") (from/to "'" "'"))
(token 'STRING
(substring lexeme
1 (sub1 (string-length lexeme))))]))
(provide basic-lexer)

@ -0,0 +1,22 @@
#lang br
(require "struct.rkt")
(provide b-line raise-line-error)
(define-macro (b-line NUM STATEMENT ...)
(with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
#:source #'NUM)])
(syntax/loc caller-stx
(define (LINE-NUM #:error [msg #f])
(with-handlers
([line-error?
(λ (le) (handle-line-error NUM le))])
(when msg (raise-line-error msg))
STATEMENT ...)))))
(define (raise-line-error error-msg)
(raise (line-error error-msg)))
(define (handle-line-error num le)
(error (format "error in line ~a: ~a"
num (line-error-msg le))))

@ -0,0 +1,19 @@
#lang br/quicklang
(require "parser.rkt" "tokenizer.rkt")
(module+ reader
(provide read-syntax get-info))
(define (read-syntax path port)
(define parse-tree (parse path (make-tokenizer port path)))
(strip-bindings
#`(module basic-mod basic-demo-3/expander
#,parse-tree)))
(define (get-info port src-mod src-line src-col src-pos)
(define (handle-query key default)
(case key
[(color-lexer)
(dynamic-require 'basic-demo-3/colorer 'basic-colorer)]
[else default]))
handle-query)

@ -0,0 +1,34 @@
#lang br
(require "struct.rkt" "expr.rkt")
(provide b-rem b-print b-let b-input b-import b-export b-repl)
(define (b-rem val) (void))
(define (b-print . vals)
(displayln (string-append* (map ~a vals))))
(define-macro (b-let ID VAL) #'(set! ID VAL))
(define-macro (b-input ID)
#'(b-let ID (let* ([str (read-line)]
[num (string->number (string-trim str))])
(or num str))))
(define-macro (b-import NAME) #'(void))
(define-macro (b-export NAME) #'(void))
(define-macro (b-repl . ALL-INPUTS)
(with-pattern
([INPUTS (pattern-case-filter #'ALL-INPUTS
[(b-print . PRINT-ARGS)
#'(b-print . PRINT-ARGS)]
[(b-expr . EXPR-ARGS)
#'(b-print (b-expr . EXPR-ARGS))]
[(b-let ID VAL)
#'(define ID VAL)]
[(b-def FUNC-ID VAR-ID ... EXPR)
#'(define (FUNC-ID VAR-ID ...) EXPR)]
[ANYTHING-ELSE
#'(error 'invalid-repl-input)])])
#'(begin . INPUTS)))

@ -0,0 +1,14 @@
#lang br/quicklang
(require "parser.rkt" "tokenizer.rkt")
(define (read-syntax path port)
(define parse-tree (parse path (make-tokenizer port path)))
(strip-bindings
#`(module basic-parser-mod basic-demo-3/parse-only
#,parse-tree)))
(module+ reader (provide read-syntax))
(define-macro (parser-only-mb PARSE-TREE)
#'(#%module-begin
'PARSE-TREE))
(provide (rename-out [parser-only-mb #%module-begin]))

@ -0,0 +1,15 @@
#lang br/quicklang
(require "parser.rkt" "tokenizer.rkt")
(define (read-syntax path port)
(define parse-tree (parse path (make-tokenizer port path)))
(strip-bindings
#`(module basic-parser-mod basic-demo-3/parse-stx
#'#,parse-tree)))
(module+ reader (provide read-syntax))
(define-macro (parser-only-mb PARSE-STX)
#'(#%module-begin
PARSE-STX))
(provide (rename-out [parser-only-mb #%module-begin]))
(provide syntax)

@ -0,0 +1,40 @@
#lang brag
b-program : [b-line] (/NEWLINE [b-line])* | b-statement /NEWLINE
b-line : b-line-num [b-statement] (/":" [b-statement])* [b-rem]
@b-line-num : INTEGER
b-rem : REM
@b-statement : b-end | b-print | b-goto
| b-let | b-input | b-if
| b-gosub | b-return | b-for | b-next
| b-def | b-import | b-export
b-end : /"end"
b-print : /"print" [b-printable] (/";" [b-printable])*
@b-printable : STRING | b-expr
b-goto : /"goto" b-expr
b-let : [/"let"] b-id /"=" (STRING | b-expr)
b-if : /"if" b-expr /"then" (b-statement | b-expr)
[/"else" (b-statement | b-expr)]
b-input : /"input" b-id
@b-id : ID
b-gosub : /"gosub" b-expr
b-return : /"return"
b-for : /"for" b-id /"=" b-expr /"to" b-expr [/"step" b-expr]
b-next : /"next" b-id
b-def : /"def" b-id /"(" ID [/"," ID]* /")" /"=" b-expr
b-import : /"import" b-import-name
@b-import-name : RACKET-ID | STRING
b-export : /"export" b-export-name
@b-export-name : ID
b-expr : b-or-expr
b-or-expr : [b-or-expr "or"] b-and-expr
b-and-expr : [b-and-expr "and"] b-not-expr
b-not-expr : ["not"] b-comp-expr
b-comp-expr : [b-comp-expr ("="|"<"|">"|"<>")] b-sum
b-sum : [b-sum ("+"|"-")] b-product
b-product : [b-product ("*"|"/"|"mod")] b-neg
b-neg : ["-"] b-expt
b-expt : [b-expt ("^")] b-value
@b-value : b-number | b-id | /"(" b-expr /")" | b-func
b-func : (ID | RACKET-ID) /"(" b-expr [/"," b-expr]* /")"
@b-number : INTEGER | DECIMAL
b-repl : (b-statement | b-expr) (/":" [@b-repl])*

@ -0,0 +1,8 @@
(define (30) (rem print "'ignored'"))
(define (35) (void))
(define (50) (print "never gets here"))
(define (40) (end))
(define (60) (print "three") (print (+ 1.0 3)))
(define (70) (goto (+ 11 18.5 0.5)))
(define (10) (print "one"))
(define (20) (print) (goto 60) (end))

@ -0,0 +1,5 @@
#lang basic-demo-3
10 print "arg0 is " ; arg0
20 print "arg1 + arg1 is " ; arg1 + arg1
40 print "arg3 is " ; arg3
50 print "arg4 is " ; arg4

@ -0,0 +1,23 @@
#lang br
(require "line.rkt" "struct.rkt")
(provide run)
(define (run line-table)
(define line-vec
(list->vector (sort (hash-keys line-table) <)))
(with-handlers ([end-program-signal? (λ (exn-val) (void))])
(for/fold ([line-idx 0])
([i (in-naturals)]
#:break (>= line-idx (vector-length line-vec)))
(define line-num (vector-ref line-vec line-idx))
(define line-func (hash-ref line-table line-num))
(with-handlers
([change-line-signal?
(λ (cls)
(define clsv (change-line-signal-val cls))
(or
(and (exact-positive-integer? clsv)
(vector-member clsv line-vec))
(line-func #:error (format "line ~a not found" clsv))))])
(line-func)
(add1 line-idx)))))

@ -0,0 +1,8 @@
#lang basic-demo-3
10 rem all results should be 1
20 a = 5
30 b = 10
40 print a > 4
50 print b = 10
60 print b < 11
70 print rem (b = 100)

@ -0,0 +1,7 @@
#lang basic-demo-3
10 x = 2 : y = 3 : z = 5
20 print f(3, 4)
30 print f(f(3, g(2)), 2)
40 def f(x, y) = x * y * z
50 def g(i) = i + i
60 print y

@ -0,0 +1,9 @@
#lang basic-demo-3
10 def div(num, denom) = num / denom
20 x = 5 : y = 10
30 print x - 4
40 x = 15 : y = 30
50 print div(y, x)
60 x = 20
70 print div((x + x + x), x)
80 export div : export x

@ -0,0 +1,6 @@
#lang basic-demo-3
10 for a = 1 to 3
21 for b = 9 to 7 step -1
22 print a : print b
23 next b
30 next a

@ -0,0 +1,10 @@
#lang basic-demo-3
10 gosub 41
20 print "second"
30 gosub 100
31 print "fourth"
35 end
40 return
41 print "first" : return
100 print "third"
110 goto 40

@ -0,0 +1,7 @@
#lang basic-demo-3
10 import [math/number-theory]
20 print [nth-prime](15)
30 print [prime?](24)
40 import [racket/base]
50 print [max](f(1), f(2), f(5), f(4))
60 def f(x) = x + x

@ -0,0 +1,5 @@
#lang br
(require basic-demo-3/sample-exporter)
div
x
(div x 10)

@ -0,0 +1,4 @@
#lang basic-demo-3
5 print "enter your name: "
10 input A$
20 print "hello, " ; A$ ; "!"

@ -0,0 +1,9 @@
#lang basic-demo-3
10 rem all results should be 1
20 print 1 - 2 * 3 + 4 * 5 - 6 = 9
30 print (1 - 2) * (3 + 4) * (5 - 6) = 7
40 print 1 / 4 = .25
50 print 2 ^ 3 = 8
60 print 9 ^ 0.5 = 3
70 print 6 mod 2 = 0
80 print 5 mod 2 = 1

@ -0,0 +1,6 @@
#lang br
(require "sample-exporter.rkt")
(provide (all-from-out "sample-exporter.rkt"))
div
x
(div x 10)

@ -0,0 +1,2 @@
#lang basic-demo-3
10 print "got shell args: " ; arg0 ; arg1 ; arg2

@ -0,0 +1,9 @@
#lang basic-demo-3
30 rem print 'ignored'
35
50 print "never gets here"
40 end
60 print 'three' : print 1.0 + 3
70 goto 11. + 18.5 + .5 rem ignored
10 print "o" ; "n" ; "e"
20 print : goto 60.0 : end

@ -0,0 +1,19 @@
#lang br
(require "parser.rkt" "tokenizer.rkt")
(provide basic-output-port do-setup!)
(define basic-output-port
(make-parameter (open-output-nowhere)))
(define repl-parse (make-rule-parser b-repl))
(define (read-one-line origin port)
(define one-line (read-line port))
(if (eof-object? one-line)
eof
(repl-parse
(make-tokenizer (open-input-string one-line)))))
(define (do-setup!)
(basic-output-port (current-output-port))
(current-read-interaction read-one-line))

@ -0,0 +1,8 @@
#lang br
(provide (struct-out end-program-signal)
(struct-out change-line-signal)
(struct-out line-error))
(struct end-program-signal ())
(struct change-line-signal (val))
(struct line-error (msg))

@ -0,0 +1,7 @@
#lang br
(provide (all-defined-out))
(struct end-program-signal ())
(struct change-line-signal (val))
(struct line-error (msg))

@ -0,0 +1,72 @@
#lang at-exp br
(require br/test rackunit)
(check-equal? (run-source "sample.rkt") "one
three
4
")
(check-equal? (run-source "sample-cond.rkt") "1
1
1
")
(check-equal? (run-source "sample-def.rkt") "60
600
3
")
(check-equal? (run-source "sample-exporter.rkt") "1
2
3
")
(check-equal? (run-source "sample-for.rkt") "1
9
1
8
1
7
2
9
2
8
2
7
3
9
3
8
3
7
")
(check-equal? (run-source "sample-gosub.rkt") "first
second
third
fourth
")
(check-equal? (run-source "sample-import.rkt") "53
0
10
")
(check-equal? (run-source "sample-importer.rkt") "#<procedure:div>
20
2
")
(check-equal? (run-source "sample-math.rkt") "1
1
1
1
1
1
1
")
(check-equal? (run-source "sample-shell.rkt") "got shell args: 000\n")

@ -0,0 +1,14 @@
#lang br/quicklang
(require "parser.rkt" "tokenizer.rkt" brag/support)
(define (read-syntax path port)
(define tokens (apply-tokenizer-maker make-tokenizer port))
(strip-bindings
#`(module basic-parser-mod basic-demo-3/parse-only
'#,tokens)))
(module+ reader (provide read-syntax))
(define-macro (mb PARSE-TREE)
#'(#%module-begin
'PARSE-TREE))
(provide (rename-out [mb #%module-begin]))

@ -0,0 +1,10 @@
#lang br
(require "lexer.rkt" brag/support)
(define (make-tokenizer ip [path #f])
(port-count-lines! ip)
(lexer-file-path path)
(define (next-token) (basic-lexer ip))
next-token)
(provide make-tokenizer)

@ -10,7 +10,6 @@
(define basic-lexer
(lexer-src-pos
[(eof) eof]
[whitespace (token 'WHITE lexeme #:skip? #t
#:position (pos lexeme-start)
#:line (line lexeme-start)

@ -1,7 +0,0 @@
#lang basic-demo
10 rem what?
20 print "hello"
30 rem goto 50
45 print "shite"
50 print "foobar"
60 goto 45

@ -1,51 +0,0 @@
#lang br
(require brag/support syntax-color/racket-lexer racket/contract
basic-demo/tokenizer sugar/coerce)
(define (color-basic ip)
(define postok (basic-lexer ip))
(define tok (position-token-token postok))
(define-values (type val)
(cond
[(eof-object? tok) (values eof eof)]
[(string? tok) (values 'string tok)]
[else (values (token-struct-type tok)
(format "~a" (token-struct-val tok)))]))
(values val
(caseq type
[(WHITE) 'white-space]
[(COMMENT) 'comment]
[(NUMBER) 'constant]
[(STRING) 'string]
[else 'keyword])
#f
(position-offset (position-token-start-pos postok))
(position-offset (position-token-end-pos postok))))
#;(provide
(contract-out
[color-basic
(input-port? . -> . (values
(or/c string? eof-object?)
symbol?
(or/c symbol? #f)
(or/c exact-positive-integer? #f)
(or/c exact-positive-integer? #f)))]))
(define (apply-colorer colorer-proc str)
(let loop ([p (open-input-string str)][color-recs empty])
(define color-rec (values->list (colorer-proc p)))
(if (eof-object? (car color-rec))
(reverse color-recs)
(loop p (cons color-rec color-recs)))))
(module+ main
(define str #<<HERE
10 rem 20
20 x = 42
30 print x
HERE
)
(apply-colorer color-basic str))

@ -1,46 +1,54 @@
#lang br/quicklang
(provide (matching-identifiers-out #rx"^b-" (all-defined-out)))
(define-macro (b-line NUM STATEMENT ...)
(with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
#:source #'NUM)])
(syntax/loc caller-stx
(define (LINE-NUM) (void) STATEMENT ...))))
(define-macro (b-module-begin (b-program LINE ...))
(with-pattern ([(LINE-NUM ...)
(filter-stx-prop 'b-line-number (syntax-flatten #'(LINE ...)))]
[(LINE-ID ...) (syntax-map (λ (stx) (prefix-id "line-" stx)) #'(LINE-NUM ...))])
(with-pattern
([((b-line NUM STMT ...) ...) #'(LINE ...)]
[(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))])
#'(#%module-begin
LINE ...
(define line-table (apply hasheqv (append (list LINE-NUM LINE-ID) ...)))
(run line-table))))
(define line-table
(apply hasheqv (append (list NUM LINE-FUNC) ...)))
(void (run line-table)))))
(provide (rename-out [b-module-begin #%module-begin]))
(define-macro (b-line LINE-NUMBER STATEMENT)
(with-pattern ([LINE-NUMBER-ID (prefix-id "line-" #'LINE-NUMBER
#:source #'LINE-NUMBER)]
[ORIG-LOC caller-stx])
(syntax/loc caller-stx (define (LINE-NUMBER-ID #:srcloc? [srcloc #f])
(if srcloc
(syntax-srcloc #'ORIG-LOC)
STATEMENT)))))
(define (b-statement stmt) stmt)
(define (b-rem str) #f)
(define (b-print str) (displayln str))
(define (b-goto line-number) line-number)
(define-exn end-program-signal exn:fail)
(define (b-end) (raise-end-program-signal))
(struct end-program-signal ())
(struct change-line-signal (val))
(provide b-line b-statement b-rem b-print b-goto b-end)
(define-exn-srcloc line-not-found exn:fail)
(define (b-end) (raise (end-program-signal)))
(define (b-goto expr) (raise (change-line-signal expr)))
(define (run line-table)
(define line-vec (list->vector (sort (hash-keys line-table) <)))
(with-handlers ([end-program-signal? void])
(define line-vec
(list->vector (sort (hash-keys line-table) <)))
(with-handlers ([end-program-signal? (λ (exn-val) (void))])
(for/fold ([line-idx 0])
([i (in-naturals)])
(unless (< line-idx (vector-length line-vec)) (b-end))
([i (in-naturals)]
#:break (>= line-idx (vector-length line-vec)))
(define line-num (vector-ref line-vec line-idx))
(define line-proc (hash-ref line-table line-num))
(define line-result (line-proc))
(if (exact-positive-integer? line-result)
(or (vector-member line-result line-vec)
(raise-line-not-found (line-proc #:srcloc? #t)))
(add1 line-idx)))))
(define line-func (hash-ref line-table line-num))
(with-handlers
([change-line-signal?
(λ (cls)
(define clsv (change-line-signal-val cls))
(or
(and (exact-positive-integer? clsv)
(vector-member clsv line-vec))
(error
(format "error in line ~a: line ~a not found"
line-num clsv))))])
(line-func)
(add1 line-idx)))))
(define (b-rem val) (void))
(define (b-print . vals)
(displayln (string-append* (map ~a vals))))
(define (b-sum . vals) (apply + vals))
(define (b-expr expr)
(if (integer? expr) (inexact->exact expr) expr))

@ -1,8 +0,0 @@
#lang br
(provide (rename-out [my-app #%app]))
(define-macro (my-app ID . ARGS)
(report caller-stx)
(if (number? (syntax->datum #'ID))
(with-pattern ([NEW-ID (report* #'ID (prefix-id "@" #'ID))])
#'(NEW-ID . ARGS))
#'(ID . ARGS)))

@ -1,2 +0,0 @@
#lang br
(require "basic-test.rkt")

@ -0,0 +1,4 @@
#lang info
(define test-omit-paths '("private"))
(define compile-omit-paths '("private"))

@ -0,0 +1,66 @@
#lang br
(require "lexer.rkt" brag/support rackunit)
(define (lex str)
(apply-port-proc basic-lexer str))
(check-equal? (lex "") empty)
(check-equal?
(lex " ")
(list (srcloc-token (token " " #:skip? #t)
(srcloc 'string 1 0 1 1))))
(check-equal?
(lex "rem ignored\n")
(list (srcloc-token (token 'REM "rem ignored")
(srcloc 'string 1 0 1 11))
(srcloc-token (token 'NEWLINE "\n")
(srcloc 'string 1 11 12 1))))
(check-equal?
(lex "print")
(list (srcloc-token (token "print" "print")
(srcloc 'string 1 0 1 5))))
(check-equal?
(lex "goto")
(list (srcloc-token (token "goto" "goto")
(srcloc 'string 1 0 1 4))))
(check-equal?
(lex "end")
(list (srcloc-token (token "end" "end")
(srcloc 'string 1 0 1 3))))
(check-equal?
(lex "+")
(list (srcloc-token (token "+" "+")
(srcloc 'string 1 0 1 1))))
(check-equal?
(lex ";")
(list (srcloc-token (token ";" ";")
(srcloc 'string 1 0 1 1))))
(check-equal?
(lex ":")
(list (srcloc-token (token ":" ":")
(srcloc 'string 1 0 1 1))))
(check-equal?
(lex "12")
(list (srcloc-token (token 'INTEGER 12)
(srcloc 'string 1 0 1 2))))
(check-equal?
(lex "1.2")
(list (srcloc-token (token 'DECIMAL 1.2)
(srcloc 'string 1 0 1 3))))
(check-equal?
(lex "12.")
(list (srcloc-token (token 'DECIMAL 12.)
(srcloc 'string 1 0 1 3))))
(check-equal?
(lex ".12")
(list (srcloc-token (token 'DECIMAL .12)
(srcloc 'string 1 0 1 3))))
(check-equal?
(lex "\"foo\"")
(list (srcloc-token (token 'STRING "foo")
(srcloc 'string 1 0 1 5))))
(check-equal?
(lex "'foo'")
(list (srcloc-token (token 'STRING "foo")
(srcloc 'string 1 0 1 5))))
(check-exn exn:fail:read? (lambda () (lex "x")))

@ -0,0 +1,22 @@
#lang br
(require brag/support)
(define-lex-abbrev digits (:+ (char-set "0123456789")))
(define basic-lexer
(lexer-srcloc
["\n" (token 'NEWLINE lexeme)]
[whitespace (token lexeme #:skip? #t)]
[(from/stop-before "rem" "\n") (token 'REM lexeme)]
[(:or "print" "goto" "end"
"+" ":" ";") (token lexeme lexeme)]
[digits (token 'INTEGER (string->number lexeme))]
[(:or (:seq (:? digits) "." digits)
(:seq digits "."))
(token 'DECIMAL (string->number lexeme))]
[(:or (from/to "\"" "\"") (from/to "'" "'"))
(token 'STRING
(substring lexeme
1 (sub1 (string-length lexeme))))]))
(provide basic-lexer)

@ -1,14 +1,11 @@
#lang br/quicklang
(require "parser.rkt" "tokenizer.rkt")
(module+ reader (provide read-syntax))
(define (read-syntax path port)
(define-values (line col pos) (port-next-location port))
(define port+newline (input-port-append #f port (open-input-string "\n")))
(port-count-lines! port+newline)
(set-port-next-location! port+newline line col pos)
(define parse-tree (parse path (tokenize port+newline)))
(define parse-tree (parse path (make-tokenizer port path)))
(strip-bindings
#`(module basic-mod basic-demo/expander
#,parse-tree)))
(module+ reader
(provide read-syntax))

@ -0,0 +1,14 @@
#lang br/quicklang
(require "parser.rkt" "tokenizer.rkt")
(define (read-syntax path port)
(define parse-tree (parse path (make-tokenizer port path)))
(strip-bindings
#`(module basic-parser-mod basic-demo/parse-only
#,parse-tree)))
(module+ reader (provide read-syntax))
(define-macro (parser-only-mb PARSE-TREE)
#'(#%module-begin
'PARSE-TREE))
(provide (rename-out [parser-only-mb #%module-begin]))

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save