Skip to content

Instantly share code, notes, and snippets.

@danking
Created October 19, 2011 15:03
Show Gist options
  • Select an option

  • Save danking/1298549 to your computer and use it in GitHub Desktop.

Select an option

Save danking/1298549 to your computer and use it in GitHub Desktop.
odd syntax-parse behavior
-*- mode: compilation; default-directory: "/home/danking/development/olin-coop/pda-to-pda-risc/" -*-
Compilation started at Wed Oct 19 11:01:54
racket parse-pda-macro.rkt
compile: bad syntax; literal data is not allowed, because no #%datum syntax transformer is bound in: #(struct:goto #<syntax:/home/danking/development/olin-coop/pda-to-pda-risc/parse-pda-macro.rkt:23:29 (A)> #<syntax:/home/danking/development/olin-coop/pda-to-pda-risc/parse-pda-macro.rkt:23:33 bar>)
=== context ===
standard-module-name-resolver
Compilation exited abnormally with code 1 at Wed Oct 19 11:01:55
#lang racket
(require (for-syntax "pda-syntax-classes.rkt"
syntax/parse))
(provide parse-pda)
(define-syntax (parse-pda stx)
(syntax-parse stx
#:local-conventions ([token identifier])
#:literal-sets (pda-literals)
((_ s:untyped-state-stx . any)
#'s)
((_ r:untyped-rule-stx . any)
#'r)
((_ (EOS token) . any)
#'token)
((_ (START token) . any)
#'token)
((_ (COMMENT . etc) . any)
#''WOOOOOOOOOOOOoooo)
((_ (STATE name:identifier action:action-stx ...) . any)
#'(list action.compiled ...))))
(parse-pda (STATE foo (SHIFT (A) bar)))
#lang racket
(require syntax/parse
(prefix-in pda-
"pda-data.rkt"))
(provide (all-defined-out))
(define-syntax define-literals
(syntax-rules ()
((_ set-name (literal ...))
(begin (define literal
(lambda (stx)
(raise-syntax-error 'parse-pda
"~a should only be used inside parse-pda"
stx)))
...
(define-literal-set set-name
(literal ...))))))
(define-literals pda-literals
(EOS START TOKENS COMMENT))
(define-literals action-literals
(STATE RULE SHIFT REDUCE ACCEPT))
(define-syntax-class untyped-pda
#:description "a pda"
(pattern (clauses:untyped-state-or-rule ...)))
(define-syntax-class untyped-state-or-rule
#:description #f
(pattern x:untyped-state-stx)
(pattern x:untyped-rule-stx))
(define-syntax-class untyped-state-stx
#:description "a pda state"
#:literal-sets (action-literals)
(pattern (STATE name:identifier action:action-stx ...)
#:with compiled (pda-make-state
#'name
#'(list action.compiled ...))))
(define-syntax-class untyped-rule-stx
#:description "a pda rule"
#:attributes (name non-terminal (bindings 1) sem-act)
#:literal-sets (action-literals)
(pattern (RULE name:identifier non-terminal:identifier
(bindings:maybe-id ...)
sem-act)
#:with compiled (pda-make-rule #'name
#'#f
#'non-terminal
#'(bindings ...)
#'sem-act)))
(define-syntax-class action-stx
(pattern a:accept-stx
#:with compiled #'a.compiled)
(pattern r:reduce-stx
#:with compiled #'r.compiled)
(pattern s:shift-stx
#:with compiled #'s.compiled)
(pattern g:goto-stx
#:with compiled #'g.compiled))
(define-syntax-class shift-stx
#:description "a shift action"
#:attributes (compiled)
#:literal-sets (action-literals)
(pattern (SHIFT lookahead target)
#:with compiled (pda-make-shift #'lookahead #'target)))
(define-syntax-class reduce-stx
#:description "a reduce action"
#:attributes (compiled)
#:literal-sets (action-literals)
(pattern (REDUCE lookahead target)
#:with compiled (pda-make-reduce #'lookahead #'target)))
(define-syntax-class goto-stx
#:description "an accept action"
#:attributes (compiled)
#:literal-sets (action-literals)
(pattern (GOTO lookahead target)
#:with compiled (pda-make-goto #'lookahead #'target)))
(define-syntax-class accept-stx
#:description "an accept action"
#:attributes (compiled)
#:literal-sets (action-literals)
(pattern (ACCEPT lookahead)
#:with compiled (pda-make-accept #'lookahead)))
(define-syntax-class maybe-id
#:description "an identifier or #f"
(pattern (~or boolean identifier)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment