Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

working on auto-parser

  • Loading branch information...
commit d9c57ad471f0bee2b530e4dcc924bb1067ea339b 1 parent 02f625e
John Clements authored
15 antlr-parser.rkt
View
@@ -7,10 +7,10 @@
syntax/readerr
racket/generator)
-(provide magically-create-rules)
+(provide rust-rules)
(define lines
- (file->lines "/Users/clements/rust-antlr/Rust.g4")
+ (file->lines "/Users/clements/rust-antlr/Rust-massaged.g4")
#;(list "a" "b" "/// <foo>" ))
(define ((parse-line tags) line)
@@ -167,6 +167,8 @@
"too late! name ~e already appears in the table"
name)]
[(hash-set! aux-defn-bucket name #f)]))
+(define (reset-aux-defns!)
+ (set! aux-defn-bucket (make-hash)))
;; NOTE! I'VE ONLY IMPLEMENTED THE ONES I NEEDED, HERE...
@@ -231,7 +233,9 @@
(define ((rewrite-pat-to-or-of-seqs name) pat)
(match pat
[(cons 'or pats)
- (map (rewrite-pat-to-seq name) pats)]))
+ (map (rewrite-pat-to-seq name) pats)]
+ [(cons 'seq pats)
+ (list ((rewrite-pat-to-seq name) pat))]))
(define ((rewrite-pat-to-seq name) pat)
(match pat
@@ -255,6 +259,8 @@
(check-equal? (hash-ref aux-defn-bucket "bogo*_1")
'(() ("frongy" "bogo*_1")))
+(reset-aux-defns!)
+
(define (post-process-rules grammar)
(for/list ([rule grammar])
@@ -272,11 +278,10 @@
(define grammar-port (open-input-string the-grammar-text))
-(define (magically-create-rules)
+(define rust-rules
(post-process-rules
(append
(rs grammar-port)
(filter (lambda (rule) (not (false? (second rule))))
(hash-map aux-defn-bucket list)))))
-(magically-create-rules)
3  rust-lexer.rkt
View
@@ -147,6 +147,9 @@
(define-lex-abbrevs
[ident (:: xid-start (:* xid-continue))]
+ ;; DARN! haven't committed xid-start to racket tree yet...
+ [xid-start (:or (:/ #\a #\z) (:/ #\A #\Z) #\_)]
+ [xid-continue (:or (:/ #\a #\z) (:/ #\A #\Z) (:/ #\0 #\9) #\_)]
[dec-digits (:: dec-digit-start (:* dec-digit-cont))]
[dec-digit-start (:/ #\0 #\9)]
[dec-digit-cont (:or dec-digit-start #\_)]
28 rust-parser.rkt
View
@@ -5,29 +5,33 @@
parser-tools/lex
parser-tools/yacc)
-#;(require rackunit
- (prefix-in : parser-tools/lex-sre)
-
- syntax/readerr)
+(provide parse-file)
(define-syntax (generate-rust-parser stx)
(syntax-case stx ()
[(_)
#`(parser
(src-pos)
- (start tts)
+ (start prog)
(end EOF)
(error (lambda (a name val start end)
(error 'antlr-parser
"error-vals: ~e"
(list a name val start end))))
- #;(debug "/tmp/grammar-debug")
+ (debug "/tmp/grammar-debug")
(tokens empty-toks data hack)
(grammar
- ;; urg, I didn't expect that to work...
- (tts ((tts*_1) #f))
- #,@(datum->syntax
- #'stx
- (magically-create-rules))))]))
+ #,@rust-rules)
+ )]))
+
+(define rust-parser
+ (generate-rust-parser))
+
+(define (parse-file f)
+ (call-with-input-file f
+ (lambda (port)
+ (rust-parser (lambda () (rust-lexer port))))))
+
+(parse-file "/tmp/f.rs")
+
-(generate-rust-parser)
18 test-rackety-driver.rkt
View
@@ -1,12 +1,22 @@
#lang racket
(require "rust-file-list.rkt"
- "rust-lexer.rkt")
+ "rust-lexer.rkt"
+ "rust-parser.rkt")
-(define lexer-files (make-lexer-list "/Users/clements/tryrust"))
+#;(define lexer-files (make-lexer-list "/Users/clements/tryrust"))
-(for ([f lexer-files]
+#;(for ([f lexer-files]
[i (in-naturals)])
(when (= (modulo i 100) 0)
(printf "processed ~a files\n" i))
- (lex-file f))
+ (lex-file f))
+
+
+(define parser-files (make-parser-list "/Users/clements/tryrust"))
+
+(for ([f parser-files]
+ [i 8 #;(in-naturals)])
+ (when (= (modulo i 100) 0)
+ (printf "processed ~a files\n" i))
+ (parse-file f))
Please sign in to comment.
Something went wrong with that request. Please try again.