Attempt to get syntax coloring working.
This commit is contained in:
parent
ab9dca4cd9
commit
2d90353d39
|
@ -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])))
|
||||
|
|
21
bracket/graphics.rkt
Normal file
21
bracket/graphics.rkt
Normal file
|
@ -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)
|
|
@ -34,7 +34,8 @@
|
|||
|
||||
; <string> 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)
|
||||
|
|
|
@ -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)
|
||||
|
|
19
bracket/main.rkt
Normal file
19
bracket/main.rkt
Normal file
|
@ -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) ...)]))
|
||||
|
||||
|
|
@ -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))
|
||||
(show-enabled #t))
|
||||
|
||||
|
|
|
@ -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)
|
||||
If(3+z,1,2);
|
||||
define(x,3);
|
||||
x
|
||||
|
|
Loading…
Reference in New Issue
Block a user