From 60a142f90c681f5d25e29fc8cb6761fbe2094569 Mon Sep 17 00:00:00 2001 From: Jack Firth Date: Wed, 13 Apr 2022 17:40:57 -0700 Subject: [PATCH] Move symbols into their own module too --- base/grammar.rkt | 15 ++------------- base/symbol.rkt | 22 ++++++++++++++++++++++ parser/earley.rkt | 2 ++ 3 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 base/symbol.rkt diff --git a/base/grammar.rkt b/base/grammar.rkt index 8538b5b..991f26c 100644 --- a/base/grammar.rkt +++ b/base/grammar.rkt @@ -5,12 +5,9 @@ (provide - (struct-out terminal-symbol) - (struct-out nonterminal-symbol) (struct-out cf-grammar) (struct-out cf-production-rule) (contract-out - [grammar-symbol? predicate/c] [cf-grammar-start-rules (-> cf-grammar? (set/c cf-production-rule? #:kind 'immutable))] [make-cf-grammar (-> #:rules (sequence/c cf-production-rule?) #:start-symbol any/c cf-grammar?)] [make-cf-production-rule @@ -22,7 +19,8 @@ racket/set rebellion/collection/vector yaragg/base/derivation - yaragg/base/semantic-action) + yaragg/base/semantic-action + yaragg/base/symbol) ;@---------------------------------------------------------------------------------------------------- @@ -52,15 +50,6 @@ (struct cf-production-rule (nonterminal action substitution) #:transparent) -;; A (Grammar-Symbol T S) is either a (Terminal-Symbol T) or a (Nonterminal-Symbol S) -(define (grammar-symbol? v) - (or (terminal-symbol? v) (nonterminal-symbol? v))) - - -(struct terminal-symbol (value) #:transparent) -(struct nonterminal-symbol (value) #:transparent) - - (define (make-cf-grammar #:rules rules #:start-symbol start) (cf-grammar (sequence->vector rules) start)) diff --git a/base/symbol.rkt b/base/symbol.rkt new file mode 100644 index 0000000..7f64b8d --- /dev/null +++ b/base/symbol.rkt @@ -0,0 +1,22 @@ +#lang racket/base + + +(require racket/contract/base) + + +(provide + (struct-out terminal-symbol) + (struct-out nonterminal-symbol) + (contract-out + [grammar-symbol? predicate/c])) + + +;@---------------------------------------------------------------------------------------------------- + + +(define (grammar-symbol? v) + (or (terminal-symbol? v) (nonterminal-symbol? v))) + + +(struct terminal-symbol (value) #:transparent) +(struct nonterminal-symbol (value) #:transparent) diff --git a/parser/earley.rkt b/parser/earley.rkt index 0d68425..94b5f05 100644 --- a/parser/earley.rkt +++ b/parser/earley.rkt @@ -18,6 +18,8 @@ rebellion/private/guarded-block yaragg/base/derivation yaragg/base/grammar + yaragg/base/semantic-action + yaragg/base/symbol yaragg/base/token yaragg/parser (submod yaragg/parser private))