Permalink
Browse files

adding simple emacs highlighting

  • Loading branch information...
1 parent 55fb724 commit 93f291bb908e483955252b44a5146bf3cd5984a2 @dbp dbp committed Jan 11, 2013
Showing with 40 additions and 7 deletions.
  1. +1 −1 htdp/def.arr
  2. +21 −0 src/emacs/pyret.el
  3. +10 −3 src/lang/eval.rkt
  4. +2 −2 src/lang/grammar.rkt
  5. +6 −1 src/lang/tokenizer.rkt
View
@@ -1,6 +1,6 @@
#lang reader "../src/lang/pyret.rkt"
-fun y(x): x:times(x) end
+fun y(x): x.times(x) end
y(1)
y(2)
View
@@ -0,0 +1,21 @@
+(require 'generic-x) ;; we need this
+
+(define-generic-mode
+ 'pyret-mode
+ '("#") ;; comments start with #
+ '("fun" "def" "cond" "import" "provide"
+ "data" "end" "true" "false" "do" ) ;; keywords
+ '(("=" . 'font-lock-operator)
+ (":" . 'font-lock-builtin)
+ ("::" . 'font-lock-bultin)
+ ("=>" . 'font-lock-builtin)
+ ("," . 'font-lock-builtin)
+ ("{" . 'font-lock-builtin)
+ ("}" . 'font-lock-builtin)
+ ("." . 'font-lock-builtin)
+ ("\\" . 'font-lock-builtin)
+ (";" . 'font-lock-builtin))
+ '("\\.arr$") ;; files for which to activate this mode
+ nil ;; other functions to call
+ "A mode for Pyret files" ;; doc string for this mode
+)
View
@@ -17,12 +17,19 @@
(dynamic-require parser 0)
(define ns (module->namespace (resolved-module-path-name parser)))
-(define (pyret->racket src in)
+(define (stx->racket stx)
(strip-context
(compile-pyret
(contract-check-pyret
(desugar-pyret
- (eval (get-syntax src in) ns))))))
+ (eval stx ns))))))
+
+(define (pyret->racket src in)
+ (stx->racket (get-syntax src in)))
+
+;; for the repl, we parse statement by statement
+(define (pyret->racket-repl src in)
+ (stx->racket (get-stmt-syntax src in)))
(define (repl-eval-pyret src in)
;; the parameterize is stolen from
@@ -31,7 +38,7 @@
[read-accept-lang #f])
(if (eof-object? (peek-char in))
eof
- (pyret->racket src in))))
+ (pyret->racket-repl src in))))
(define (simplify-pyret val)
(match val
View
@@ -9,8 +9,8 @@ provide-stmt: "provide" stmt "end"
block: stmt*
-stmt: def-expr | fun-expr | data-expr | do-expr | expr
- | assign-expr | dot-assign-expr | bracket-assign-expr
+stmt: (def-expr | fun-expr | data-expr | do-expr | expr
+ | assign-expr | dot-assign-expr | bracket-assign-expr) [ENDMARKER]
expr: obj-expr | list-expr | app-expr | id-expr | prim-expr
| dot-expr | bracket-expr | dot-method-expr | bracket-method-expr
View
@@ -3,7 +3,8 @@
;; NOTE(joe): This has been ripped from Danny's test cases for
;; autogrammar
(provide
- get-syntax)
+ get-syntax
+ get-stmt-syntax)
(require
rackunit
racket/match
@@ -52,6 +53,10 @@
(define (get-syntax name input-port)
(parse name (adapt-pyret-tokenizer input-port)))
+(define (get-stmt-syntax name input-port)
+ (define parse-stmt (make-rule-parser stmt))
+ (parse-stmt (adapt-pyret-tokenizer input-port)))
+
(define (get-string-syntax str)
(get-syntax str (open-input-string str)))

0 comments on commit 93f291b

Please sign in to comment.