From 509ed99c794af1adc711b251987dd24c4a287589 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Sun, 30 Aug 2009 22:37:37 -0500 Subject: [PATCH] refactor struct slot parsing so that there's a word for easily constructing struct slots outside classes.struct --- basis/classes/struct/struct-tests.factor | 2 +- basis/classes/struct/struct.factor | 27 ++++++++++-------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/basis/classes/struct/struct-tests.factor b/basis/classes/struct/struct-tests.factor index 271138df4a..86ac0c657a 100644 --- a/basis/classes/struct/struct-tests.factor +++ b/basis/classes/struct/struct-tests.factor @@ -6,7 +6,7 @@ kernel libc literals math multiline namespaces prettyprint prettyprint.config see sequences specialized-arrays.ushort system tools.test compiler.tree.debugger struct-arrays classes.tuple.private specialized-arrays.direct.int -compiler.units byte-arrays specialized-arrays.char ; +compiler.units specialized-arrays.char ; IN: classes.struct.tests << diff --git a/basis/classes/struct/struct.factor b/basis/classes/struct/struct.factor index f96c6f5f8b..4b829c8935 100644 --- a/basis/classes/struct/struct.factor +++ b/basis/classes/struct/struct.factor @@ -254,19 +254,22 @@ PRIVATE> ERROR: invalid-struct-slot token ; - ( name c-type attributes -- slot-spec ) + [ struct-slot-spec new ] 3dip + [ >>name ] + [ [ >>c-type ] [ struct-slot-class >>class ] bi ] + [ [ dup empty? ] [ peel-off-attributes ] until drop ] tri* ; + +array ] when ; : parse-struct-slot ( -- slot ) - struct-slot-spec new - scan >>name - scan-c-type [ >>c-type ] [ struct-slot-class >>class ] bi - \ } parse-until [ dup empty? ] [ peel-off-attributes ] until drop ; + scan scan-c-type \ } parse-until ; : parse-struct-slots ( slots -- slots' more? ) scan { @@ -296,17 +299,9 @@ SYNTAX: S@ : scan-c-type` ( -- c-type/param ) scan dup "{" = [ drop \ } parse-until >array ] [ >string-param ] if ; -:: parse-struct-slot` ( accum -- accum ) - scan-string-param :> name - scan-c-type` :> c-type - \ } parse-until :> attributes - accum { - \ struct-slot-spec new - name >>name - c-type [ >>c-type ] [ struct-slot-class >>class ] bi - attributes [ dup empty? ] [ peel-off-attributes ] until drop - over push - } over push-all ; +: parse-struct-slot` ( accum -- accum ) + scan-string-param scan-c-type` \ } parse-until + [ ] 3curry over push-all ; : parse-struct-slots` ( accum -- accum more? ) scan {