*** empty log message ***
original commit: 6f4bc60db3c345db50ebd3d711b4571abc01e905tokens
parent
fb9cf08639
commit
ba3e2af0f8
@ -1,40 +1,102 @@
|
|||||||
#cs
|
#cs
|
||||||
(module yacc mzscheme
|
(module yacc mzscheme
|
||||||
|
|
||||||
(require-for-syntax "private-yacc/parser-builder.ss")
|
(require-for-syntax "private-yacc/parser-builder.ss"
|
||||||
|
"private-yacc/yacc-helper.ss")
|
||||||
(require "private-yacc/terminal.ss"
|
(require "private-yacc/terminal.ss"
|
||||||
"private-yacc/parser-actions.ss"
|
"private-yacc/parser-actions.ss"
|
||||||
"private-yacc/array2d.ss")
|
"private-yacc/array2d.ss")
|
||||||
|
|
||||||
(provide define-tokens define-empty-tokens parser parser-debug)
|
(provide define-tokens define-empty-tokens parser)
|
||||||
|
|
||||||
(define-syntax parser
|
(define-syntax parser
|
||||||
(lambda (stx)
|
(lambda (stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
((_ start input-terms assocs prods)
|
((_ args ...)
|
||||||
(build-parser (syntax start) (syntax input-terms)
|
(let ((arg-list (syntax->list (syntax (args ...))))
|
||||||
(syntax assocs) (syntax prods)
|
(debug #f)
|
||||||
"" #'here stx))
|
(error #f)
|
||||||
(_
|
(tokens #f)
|
||||||
|
(start #f)
|
||||||
|
(end #f)
|
||||||
|
(precs #f)
|
||||||
|
(grammar #f))
|
||||||
|
(for-each
|
||||||
|
(lambda (arg)
|
||||||
|
(syntax-case arg (debug error tokens start end precs grammar)
|
||||||
|
((debug filename)
|
||||||
|
(cond
|
||||||
|
((not (string? (syntax-object->datum (syntax filename))))
|
||||||
(raise-syntax-error
|
(raise-syntax-error
|
||||||
#f
|
'parser-debug
|
||||||
"parser must have the form (parser start-symbol tokens precedence/associativity productions)"
|
"Debugging filename must be a string"
|
||||||
stx)))))
|
(syntax filename)))
|
||||||
|
(debug
|
||||||
|
(raise-syntax-error #f "Multiple debug declarations" stx))
|
||||||
(define-syntax parser-debug
|
(else
|
||||||
(lambda (stx)
|
(set! debug (syntax-object->datum (syntax filename))))))
|
||||||
(syntax-case stx ()
|
((error expression)
|
||||||
((_ filename start input-terms assocs prods)
|
(if error
|
||||||
(string? (syntax-object->datum (syntax filename)))
|
(raise-syntax-error #f "Multiple error declarations" stx)
|
||||||
(build-parser (syntax start) (syntax input-terms)
|
(set! error (syntax expression))))
|
||||||
(syntax assocs) (syntax prods)
|
((tokens def ...)
|
||||||
(syntax-object->datum (syntax filename))
|
(if tokens
|
||||||
#'here stx))
|
(raise-syntax-error #f "Multiple tokens declarations" stx)
|
||||||
|
(set! tokens arg)))
|
||||||
|
((start symbol)
|
||||||
|
(cond
|
||||||
|
((not (identifier? (syntax symbol)))
|
||||||
|
(raise-syntax-error
|
||||||
|
'parser-start
|
||||||
|
"Start non-terminal must be a symbol"
|
||||||
|
(syntax symbol)))
|
||||||
|
(start
|
||||||
|
(raise-syntax-error #f "Multiple start declarations" stx))
|
||||||
|
(else
|
||||||
|
(set! start (syntax symbol)))))
|
||||||
|
((end symbols ...)
|
||||||
|
(begin
|
||||||
|
(for-each
|
||||||
|
(lambda (sym)
|
||||||
|
(if (not (identifier? sym))
|
||||||
|
(raise-syntax-error
|
||||||
|
'parser-end
|
||||||
|
"End token must be a symbol"
|
||||||
|
sym)))
|
||||||
|
(syntax->list (syntax (symbols ...))))
|
||||||
|
(if end
|
||||||
|
(raise-syntax-error #f "Multiple end declarations" stx))
|
||||||
|
(set! end (syntax->list (syntax (symbols ...))))))
|
||||||
|
((precs decls ...)
|
||||||
|
(if precs
|
||||||
|
(raise-syntax-error #f "Multiple precs declarations" stx)
|
||||||
|
(set! precs arg)))
|
||||||
|
((grammar prods ...)
|
||||||
|
(if grammar
|
||||||
|
(raise-syntax-error #f "Multiple grammar declarations" stx)
|
||||||
|
(set! grammar arg)))
|
||||||
|
(_ (raise-syntax-error 'parser-args "argument must match (debug filename), (error expression), (tokens def ...), (start non-term), (end tokens ...), (precs decls ...), or (grammar prods ...)" arg))))
|
||||||
|
(syntax->list (syntax (args ...))))
|
||||||
|
(if (not tokens)
|
||||||
|
(raise-syntax-error #f "missing tokens declaration" stx))
|
||||||
|
(if (not grammar)
|
||||||
|
(raise-syntax-error #f "missing error declaration" stx))
|
||||||
|
(if (not end)
|
||||||
|
(raise-syntax-error #f "missing end declaration" stx))
|
||||||
|
(build-parser (if debug debug "")
|
||||||
|
error
|
||||||
|
tokens
|
||||||
|
start
|
||||||
|
end
|
||||||
|
precs
|
||||||
|
grammar
|
||||||
|
#'here
|
||||||
|
stx)))
|
||||||
(_
|
(_
|
||||||
(raise-syntax-error
|
(raise-syntax-error
|
||||||
#f
|
#f
|
||||||
"parser must have the form (parser-debug filename start-symbol tokens precedence/associativity productions) where filename is a string"
|
"parser must have the form (parser args ...)"
|
||||||
stx)))))
|
stx)))))
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
Loading…
Reference in New Issue