diff --git a/bracket/bracket-info.rkt b/bracket/bracket-info.rkt index fa95875f0..24843e605 100644 --- a/bracket/bracket-info.rkt +++ b/bracket/bracket-info.rkt @@ -1,10 +1,29 @@ #lang racket -(provide get-language-info) - +(provide get-language-info get-info) + (define (get-language-info data) (lambda (key default) + (displayln (list 'bracket-info/get-language-info key default)) (case key [(configure-runtime) '(#(bracket/runtime-config configure #f))] + [(color-lexer) + (dynamic-require 'syntax-color/default-lexer + 'default-lexer) + (displayln "HErE") + (dynamic-require "parser.rkt" + 'color-expression-lexer)] + [else default]))) + +(require racket/runtime-path) +(define-runtime-path color-lexer-path "parser.rkt") + +(define (get-info in mod line col pos) + (displayln (list 'bracket-info/get-info in mod line col pos)) + (lambda (key default) + (displayln (list 'reader/get-info key default)) + (case key + [(color-lexer) + (dynamic-require color-lexer-path 'color-expression-lexer)] [else default]))) diff --git a/bracket/graphics.rkt b/bracket/graphics.rkt new file mode 100644 index 000000000..1d14ee467 --- /dev/null +++ b/bracket/graphics.rkt @@ -0,0 +1,21 @@ +#lang racket + +(require "../graphics/graphics.rkt") + +(define-syntax (declare/provide-vars stx) + (syntax-case stx () + [(_ id ...) + #'(begin + (define id 'id) ... + (provide id) ...)])) + +(provide Graphics) + +(declare/provide-vars + Blend Darker Hue Lighter + Circle Disk Line Point Rectangle + Text Thickness + ; Colors + Red Blue Green Black White Yellow + ; Options + ImageSize PlotRange) diff --git a/bracket/lang/parser.rkt b/bracket/lang/parser.rkt index 5a00ebfbd..77d538c6e 100644 --- a/bracket/lang/parser.rkt +++ b/bracket/lang/parser.rkt @@ -34,7 +34,8 @@ ; A number is a " followed by a series of non-" characters followed by a " . -(provide parse-expression) +(provide parse-expression + color-lexer) (require parser-tools/yacc parser-tools/lex @@ -122,6 +123,48 @@ [(:+ digit) (token-NUMBER (string->number lexeme))] [(:: (:+ digit) #\. (:* digit)) (token-NUMBER (string->number lexeme))])) +; The color-expression-lexer is for syntax coloring. +; The function returns 5 values: +; - Either a string containing the matching text or the eof object. +; Block comments and specials currently return an empty string. +; This may change in the future to other string or non-string data. +; - A symbol in '(error comment sexp-comment white-space constant +; string no-color parenthesis other symbol eof). +; - A symbol in '(|(| |)| |[| |]| |{| |}|) or #f. +; - A number representing the starting position of the match (or #f if eof). +; - A number representing the ending position of the match (or #f if eof). + +(define color-lexer + (lexer-src-pos + [(eof) + (values eof #f #f start-pos end-pos)] + [(:or #\tab #\space #\newline) + (values lexeme 'white-space #f start-pos end-pos)] + [#\newline + (begin + (/ 0 0) + (values lexeme 'white-space #f start-pos end-pos))] + [(:or ":=" "+" "-" "*" "/" "^" "<" ">" "=" "\"") + (values lexeme 'symbol #f start-pos end-pos)] + [(:or "(" ")" "[" "]" "{" "}") + (values lexeme 'parenthesis #f start-pos end-pos)] + [(:or "[[" "," ";" "." "λ" "lambda" "√" "¬" "≤" "<=" "≥" ">=" "<>" "≠") + (values lexeme 'no-color #f start-pos end-pos)] + ["define" + (values lexeme 'constant (/ 0 0) start-pos end-pos)] + [string + (values lexeme 'string #f start-pos end-pos)] + ; The parser can only look ahead 1 token, so we have 3 + ; different identifiers to see whether := or ( comes after the identfier. + ; This is enough to prevent shift/reduce conflicts between atom, definition, + ; and application. + [(:or identifier:= identifierOP identifier) + (values lexeme 'symbol #f start-pos end-pos)] + [(:+ digit) + (values lexeme 'constant #f start-pos end-pos)] + [(:: (:+ digit) #\. (:* digit)) + (values lexeme 'constant #f start-pos end-pos)])) + ;; A macro to build the syntax object (define-syntax (b stx) diff --git a/bracket/lang/reader.rkt b/bracket/lang/reader.rkt index 2a371bf77..47e2dbf9b 100644 --- a/bracket/lang/reader.rkt +++ b/bracket/lang/reader.rkt @@ -1,7 +1,16 @@ #lang racket +; #lang s-exp syntax/module-reader +; bracket +; #:read bracket-read +; #:read-syntax bracket-read-syntax +; #:whole-body-readers? #t +; #:info get-info +; #:language-info #(bracket/bracket-info get-language-info #f) + (provide (rename-out - [bracket-read read] - [bracket-read-syntax read-syntax])) + [bracket-read read] + [bracket-read-syntax read-syntax]) + get-info) (require "parser.rkt") (require syntax/strip-context) @@ -11,6 +20,8 @@ (bracket-read-syntax #'from-my-read in))) (define (bracket-read-syntax src in) + (displayln 'bracket-read-syntax) + (define out (if (eof-object? (peek-byte in)) eof (with-syntax ([body (parse-expression @@ -23,7 +34,9 @@ (resolved-module-path-name (module-path-index-resolve (syntax-source-module #'here))))) - (build-path base "../bracket-lang.rkt"))] + (path->string + (simplify-path + (build-path base "../bracket-lang.rkt"))))] [bracket.rkt (let () (define-values (base file _) @@ -31,13 +44,14 @@ (resolved-module-path-name (module-path-index-resolve (syntax-source-module #'here))))) - (build-path base "../bracket.rkt"))]) + (path->string + (simplify-path + (build-path base "../bracket.rkt"))))]) (syntax-property (strip-context - #'(module anything bracket-lang - (require (submod bracket.rkt bracket) - (submod bracket.rkt symbolic-application) - #;(submod bracket.rkt bracket-graphics)) + #'(module main bracket/bracket-lang ; "bracket-lang.rkt" ; (file bracket-lang) + (require (submod (file bracket.rkt) bracket) + (submod (file bracket.rkt) symbolic-application)) (define-syntax (#%infix stx) (syntax-case stx () [(_ expr) #'expr])) ; This lists the operators used by the parser. @@ -55,11 +69,36 @@ body)) 'module-language '#(bracket/bracket-info get-language-info #f))))) + ;(write (syntax->datum out)) + (write out) + (newline) + out) + + +;(require racket/runtime-path) +;(define-runtime-path color-lexer-path "parser.rkt") +;(write color-lexer-path) (define (get-info in mod line col pos) + (displayln (list 'reader/get-info in mod line col pos)) (lambda (key default) + (displayln (list 'reader/get-info key default)) (case key [(color-lexer) - (dynamic-require 'syntax-color/default-lexer - 'default-lexer)] + (dynamic-require 'bracket/lang/parser 'color-lexer)] [else default]))) + +#;(define (get-info in mod line col pos) + (/ 0 0) + (lambda (key default) + (/ 0 0) + (case key + [(color-lexer) + #;(dynamic-require 'syntax-color/default-lexer + 'default-lexer) + (displayln "HErE") + (dynamic-require "parser.rkt" + 'color-lexer)] + [else default]))) + +;(require syntax-color/default-lexer) diff --git a/bracket/main.rkt b/bracket/main.rkt new file mode 100644 index 000000000..810d0a26a --- /dev/null +++ b/bracket/main.rkt @@ -0,0 +1,19 @@ +#lang racket + +(require "lang/parser.rkt") +(error-print-source-location #t) + +(require (submod "bracket.rkt" symbolic-application) + (submod "bracket.rkt" bracket)) + +(provide (all-from-out racket)) +(provide (all-defined-out) + (for-syntax #%module-begin) + #%module-begin) + +(define-syntax (DeclareVars stx) + (syntax-case stx () + [(_ sym ...) + #'(begin (define sym 'sym) ...)])) + + diff --git a/bracket/runtime-config.rkt b/bracket/runtime-config.rkt index c0f2f09ef..8016149a6 100644 --- a/bracket/runtime-config.rkt +++ b/bracket/runtime-config.rkt @@ -1,7 +1,12 @@ #lang racket -(require "show.rkt") +(provide show show-enabled configure) -(provide configure) +(define show-enabled (make-parameter #f)) + +(define (show v) + (when (show-enabled) + (display v))) (define (configure data) - (show-enabled #t)) \ No newline at end of file + (show-enabled #t)) + diff --git a/bracket/tests/testing.rkt b/bracket/tests/testing.rkt index 883796f17..f8125e5b2 100644 --- a/bracket/tests/testing.rkt +++ b/bracket/tests/testing.rkt @@ -1,6 +1,5 @@ #lang bracket DeclareVars(x,y,z,x0,y0,z0,w); - {2,3}*{4,5}; 2*{3,4}; {3,4}*5; @@ -30,4 +29,6 @@ x=0; If(x=0,1,2); If(x=0,1,2); If(x=42,1,2); -If(3+z,1,2) \ No newline at end of file +If(3+z,1,2); +define(x,3); +x