1 ! Copyright (C) 2010 Anton Gorenko.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs combinators environment gobject-introspection.common
4 gobject-introspection.ffi gobject-introspection.loader
5 gobject-introspection.types io io.files io.pathnames kernel lexer
6 locals make namespaces parser sequences splitting summary vocabs
8 IN: gobject-introspection
10 ERROR: gir-not-found name paths ;
12 M: gir-not-found summary
13 [ name>> "“" "” file not found on paths:\n" surround ]
14 [ paths>> "\n" join ] bi
15 "\n\nUse the existing path or declare GIR_DIRS environment variable"
20 : system-gir-dirs ( -- dirs )
21 "XDG_DATA_DIRS" os-env "/usr/local/share/:/usr/share/" or
22 ":" split [ "gir-1.0" append-path ] map ;
24 : custom-gir-dirs ( -- dirs )
25 "GIR_DIRS" os-env ":" split ;
27 : current-vocab-path ( -- path )
28 current-vocab vocab-name "." split "/" join vocab-path ;
30 : current-vocab-dirs ( -- dirs )
33 [ , ] [ "/ffi" ?tail [ , ] [ drop ] if ] bi
36 :: resolve-gir-path ( path -- path )
39 current-vocab-dirs custom-gir-dirs system-gir-dirs
41 paths [ path append-path exists? ] find nip
42 [ path append-path ] [ path paths throw-gir-not-found ] if*
45 : define-gir-vocab ( path -- )
46 resolve-gir-path dup "Loading " write print
47 file>xml xml>repository
49 [ namespace>> name>> current-namespace-name set-global ]
50 [ def-ffi-repository ]
52 V{ } clone implement-structs set-global ;
56 SYNTAX: GIR: scan-token define-gir-vocab ;
58 SYNTAX: IMPLEMENT-STRUCTS:
60 implement-structs [ swap append! ] change-global ;
62 SYNTAX: FOREIGN-ATOMIC-TYPE:
63 scan-token scan-object swap register-atomic-type ;
65 SYNTAX: FOREIGN-ENUM-TYPE:
66 scan-token scan-object swap register-enum-type ;
68 SYNTAX: FOREIGN-RECORD-TYPE:
69 scan-token scan-object swap register-record-type ;