Skip to content

Commit

Permalink
bbp-lang experimental impl of shortnames for bbp
Browse files Browse the repository at this point in the history
  • Loading branch information
tgbugs committed Apr 13, 2017
1 parent 18269fe commit 392dc9f
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
81 changes: 81 additions & 0 deletions bbp-lang.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#lang racket/base

(require "bbp-parser.rkt")
(require brag/support)
(require (for-syntax racket/base syntax/parse))

(define (read-syntax path port)
(define parse-tree (parse path (make-tokenizer port)))
(define module-datum `(module bbp-mod "bbp-expander.rkt"
,parse-tree))
(datum->syntax #f module-datum))
(provide read-syntax)

(define-lex-abbrev
mtypes
(:or
"PC"
"BPC"
"IPC"
"NPC"
"SPC"
"NTPC"
"STPC"
"TTPC"
"TTPCLB"
"TTPCEB"
"TPCLB"
"TPCEB"
"UPC"
"BTC"
"BPC"
"ChC"
"DBC"
"DAC"
"HAC"
"LAC"
"SAC"
"MC"
"NGC"
"NGCDA"
"NGCSA"
"BC"
"SBC"
"LBC"
"NBC"
"SS"
"BC"
"BP"
"LBC"
"NBC"
"SBC"
)) ; this is infuriating check a macro
(define-lex-abbrev layer (:or "L1" "L2" "L23" "L3" "L4" "L5" "L6"))
(define-lex-abbrev init (:or "b" "c" "d"))
(define-lex-abbrev sust (:or "NAC" "AC" "STUT" "IR"))
(define-lex-abbrev species (:or "Rat" "Mouse"))
(define-lex-abbrev region (:or "S1"))
(define-lex-abbrev projection (:or "L1P" "L3P" "L4P")) ; not wokring :/

(define (make-tokenizer port)
(define (next-token)
(define bbp-lexer
(lexer
[(eof) eof]
[layer (token 'LAYER lexeme)]
[mtypes (token 'M-TYPE lexeme)]
[init (token 'INIT lexeme)]
[sust (token 'SUST lexeme)]
[species (token 'SPECIES lexeme)]
[region (token 'REGION lexeme)]
[projection (token 'PROJECTION lexeme)] ; a problem
["_" (token 'UNDERSCORE)]
))
(bbp-lexer port))
next-token)

(apply-tokenizer-maker make-tokenizer "L1_PC")
(parse-to-datum (apply-tokenizer-maker make-tokenizer "L1_PC"))
(parse-to-datum (apply-tokenizer-maker make-tokenizer "L23_PC"))
(parse-to-datum (apply-tokenizer-maker make-tokenizer "PC"))
(parse-to-datum (apply-tokenizer-maker make-tokenizer "Rat_S1_L4_PC_cAC_L3P"))
22 changes: 22 additions & 0 deletions bbp-parser.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#lang brag

short-name : base
base : (m-type | e-type) | reps
reps : (m-type | e-type | location | projection | species) more*
more : underscore reps

e-type : init sust
init : INIT
sust : SUST

location : layer | region
layer : LAYER
region : REGION

underscore : UNDERSCORE
m-type : M-TYPE

projection : PROJECTION

species : SPECIES

0 comments on commit 392dc9f

Please sign in to comment.