0 | module Text.Molfile.Parser.Stack
2 | import Data.Array.Mutable
3 | import Data.SortedMap as SM
7 | import Text.ILex.Derive
9 | import public Text.ILex
10 | import public Text.Molfile.Types
13 | %language ElabReflection
19 | %runElab deriveParserState "CSz" "CST"
20 | [ "CErr", "H1", "H2", "H3", "Counts", "EndMol", "CDone"
21 | , "SData", "SDValue"
24 | , "Coords2", "Sym2", "Chrg2", "Bnd2", "Prop2"
27 | , "CountsV3", "ACount", "BCount", "CountEnd", "EmptyV3"
28 | , "Atom3", "Index3", "Coords3", "Sym3", "AAMap", "Prop3", "AtomEnd"
29 | , "BondBegin", "BondEnd", "Bnd3", "BndProp3"
30 | , "RestV3", "SGroup"
35 | record MGraph (q : Type) where
38 | atom : Ref q (Fin $
S atoms)
39 | indices : Ref q (SortedMap Nat $
Fin (S atoms))
40 | bond : Ref q (Maybe $
Edge (S atoms) MolBond)
41 | graph : MArray q (S atoms) (Adj (S atoms) MolBond MolAtom)
44 | mgraph : (atoms : Nat) -> F1 q (MGraph q)
45 | mgraph atoms = T1.do
47 | ixs <- ref1 SM.empty
49 | g <- marray1 (S atoms) (A (cast {from = Elem} C) empty)
50 | pure (MG atoms atm ixs bnd g)
53 | record CSTCK (q : Type) where
56 | prev_ : Ref q ByteString
57 | cur_ : Ref q ByteString
59 | relpos_ : Ref q Integer
61 | positions_ : Ref q (SnocList BytePos)
64 | h1,h2,h3 : Ref q MolLine
67 | mgraph : Ref q (MGraph q)
68 | stack_ : Ref q (SnocList Molfile)
69 | groups : Ref q (SortedMap Nat String)
71 | isEmpty : Ref q Bool
74 | sdhead : Ref q SDHeader
75 | sdvals : Ref q (SnocList StructureData)
78 | error_ : Ref q (Maybe $
BBErr MolErr)
79 | strings_ : Ref q (SnocList String)
82 | %runElab derive "CSTCK" [HasBBErr,HasBytes,HasStack,HasStringLits]
85 | init : F1 q (CSTCK q)
99 | grp <- ref1 SM.empty
104 | err <- ref1 Nothing
107 | pure (CK pr fl ro rr ll ps h1 h2 h3 gr gs grp cnt ie sdh sdd err str pos)
110 | setPos : (sk : CSTCK q) => Nat -> F1' q
111 | setPos n = write1 sk.pos n
114 | incPos : (sk : CSTCK q) => Nat -> F1 q Nat
117 | writeAs sk.pos (v+n) v