From 00bae08fd76b177748f440275084459da05555d0 Mon Sep 17 00:00:00 2001 From: Scott Owens Date: Fri, 9 Nov 2001 08:29:09 +0000 Subject: [PATCH] *** empty log message *** original commit: 3ea7c7c7074409e1eaf541fe623f0a7229d2e7d0 --- collects/parser-tools/lex.ss | 52 ++++++++++++++----- .../token-syntax.ss} | 2 +- .../terminal.ss => private-lex/token.ss} | 4 +- .../private-yacc/input-file-parser.ss | 2 +- collects/parser-tools/yacc.ss | 8 +-- 5 files changed, 48 insertions(+), 20 deletions(-) rename collects/parser-tools/{private-yacc/terminal-syntax.ss => private-lex/token-syntax.ss} (97%) rename collects/parser-tools/{private-yacc/terminal.ss => private-lex/token.ss} (85%) diff --git a/collects/parser-tools/lex.ss b/collects/parser-tools/lex.ss index af4e1ba..49d3fe4 100644 --- a/collects/parser-tools/lex.ss +++ b/collects/parser-tools/lex.ss @@ -5,10 +5,12 @@ (require-for-syntax "private-lex/generate-code.ss") (require-for-syntax "private-lex/structs.ss") - (require (lib "list.ss")) + (require (lib "list.ss") + "private-lex/token.ss") (provide lex define-lex-abbrev define-lex-abbrevs make-lex-buf - get-position position-offset position-line position-col position?) + get-position position-offset position-line position-col position? + define-tokens define-empty-tokens) (define-syntax lex @@ -91,19 +93,45 @@ ,code))) (datum->syntax-object #'here code #f))))))) - - + + (define-syntax define-lex-abbrev - (syntax-rules () - ((_ name val) (define-syntax name - (make-lex-abbrev (quote-syntax val)))))) + (lambda (stx) + (syntax-case stx () + ((_ name val) + (syntax + (define-syntax name + (make-lex-abbrev (quote-syntax val))))) + (_ + (raise-syntax-error + #f + "Form should be (define-lex-abbrev name val)" + stx))))) (define-syntax define-lex-abbrevs - (syntax-rules () - ((_ (name val) ...) - (define-syntaxes (name ...) - (values (make-lex-abbrev (quote-syntax val)) ...))))) - + (lambda (stx) + (syntax-case stx () + ((_ x ...) + (let* ((abbrev (syntax->list (syntax (x ...)))) + (r (map (lambda (a) + (syntax-case a () + ((name val) + (identifier? (syntax name)) + (syntax (define-lex-abbrev name val))) + (_ (raise-syntax-error + #f + "Lexer abbreviation must be (identifier value)" + a)))) + abbrev))) + (datum->syntax-object + #'here + (cons 'begin r) + stx))) + (_ + (raise-syntax-error + #f + "Form should be (define-lex-abbrevs (name val) ...)" + stx))))) ;; Lex buffer is NOT thread safe diff --git a/collects/parser-tools/private-yacc/terminal-syntax.ss b/collects/parser-tools/private-lex/token-syntax.ss similarity index 97% rename from collects/parser-tools/private-yacc/terminal-syntax.ss rename to collects/parser-tools/private-lex/token-syntax.ss index ca51f24..f560de5 100644 --- a/collects/parser-tools/private-yacc/terminal-syntax.ss +++ b/collects/parser-tools/private-lex/token-syntax.ss @@ -1,5 +1,5 @@ #cs -(module terminal-syntax mzscheme +(module token-syntax mzscheme ;; The things needed at compile time to handle definition of tokens diff --git a/collects/parser-tools/private-yacc/terminal.ss b/collects/parser-tools/private-lex/token.ss similarity index 85% rename from collects/parser-tools/private-yacc/terminal.ss rename to collects/parser-tools/private-lex/token.ss index fa3d317..d7a9ec7 100644 --- a/collects/parser-tools/private-yacc/terminal.ss +++ b/collects/parser-tools/private-lex/token.ss @@ -1,9 +1,9 @@ #cs -(module terminal mzscheme +(module token mzscheme ;; Defining tokens - (require-for-syntax "terminal-syntax.ss") + (require-for-syntax "token-syntax.ss") (provide define-tokens define-empty-tokens token-name token-value token?) diff --git a/collects/parser-tools/private-yacc/input-file-parser.ss b/collects/parser-tools/private-yacc/input-file-parser.ss index 2b08885..c7a4b13 100644 --- a/collects/parser-tools/private-yacc/input-file-parser.ss +++ b/collects/parser-tools/private-yacc/input-file-parser.ss @@ -4,7 +4,7 @@ ;; routines for parsing the input to the parser generator and producing a ;; grammar (See grammar.ss) - (require "yacc-helper.ss" "terminal-syntax.ss" "grammar.ss" (lib "list.ss")) + (require "yacc-helper.ss" "../private-lex/token-syntax.ss" "grammar.ss" (lib "list.ss")) (provide parse-input) diff --git a/collects/parser-tools/yacc.ss b/collects/parser-tools/yacc.ss index de9c1a9..629e1ae 100644 --- a/collects/parser-tools/yacc.ss +++ b/collects/parser-tools/yacc.ss @@ -3,11 +3,11 @@ (require-for-syntax "private-yacc/parser-builder.ss" "private-yacc/yacc-helper.ss") - (require "private-yacc/terminal.ss" - "private-yacc/parser-actions.ss" - "private-yacc/array2d.ss") + (require "private-yacc/parser-actions.ss" + "private-yacc/array2d.ss" + "private-lex/token.ss") - (provide define-tokens define-empty-tokens parser) + (provide parser) (define-syntax parser (lambda (stx)