From 392dc9f58260156245279cf078a1ad14d413828e Mon Sep 17 00:00:00 2001 From: Tom Gillespie Date: Thu, 13 Apr 2017 15:15:27 -0700 Subject: [PATCH] bbp-lang experimental impl of shortnames for bbp --- bbp-lang.rkt | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ bbp-parser.rkt | 22 ++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 bbp-lang.rkt create mode 100644 bbp-parser.rkt diff --git a/bbp-lang.rkt b/bbp-lang.rkt new file mode 100644 index 00000000..f45a83e7 --- /dev/null +++ b/bbp-lang.rkt @@ -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")) diff --git a/bbp-parser.rkt b/bbp-parser.rkt new file mode 100644 index 00000000..0d7fada4 --- /dev/null +++ b/bbp-parser.rkt @@ -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 +