]> gitweb.factorcode.org Git - factor.git/blob - basis/gobject-introspection/gobject-introspection.factor
3d380cb68b7c58462625685beee2f173ac3f744d
[factor.git] / basis / gobject-introspection / gobject-introspection.factor
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
7 vocabs.parser xml ;
8 IN: gobject-introspection
9
10 ERROR: gir-not-found name paths ;
11
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"
16     3append ;
17
18 <PRIVATE
19
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 ;
23
24 : custom-gir-dirs ( -- dirs )
25     "GIR_DIRS" os-env ":" split ;
26
27 : current-vocab-path ( -- path )
28     current-vocab vocab-name "." split "/" join vocab-path ;
29
30 : current-vocab-dirs ( -- dirs )
31     [
32         current-vocab-path
33         [ , ] [ "/ffi" ?tail [ , ] [ drop ] if ] bi
34     ] { } make ;
35
36 :: resolve-gir-path ( path -- path )
37     path exists?
38     [ path ] [
39         current-vocab-dirs custom-gir-dirs system-gir-dirs
40         3append sift :> paths
41         paths [ path append-path exists? ] find nip
42         [ path append-path ] [ path paths gir-not-found ] if*
43     ] if ;
44
45 : define-gir-vocab ( path -- )
46     resolve-gir-path dup "Loading " write print
47     file>xml xml>repository
48     {
49         [ namespace>> name>> current-namespace-name set-global ]
50         [ def-ffi-repository ]
51     } cleave
52     V{ } clone implement-structs set-global ;
53
54 PRIVATE>
55
56 SYNTAX: GIR: scan-token define-gir-vocab ;
57
58 SYNTAX: IMPLEMENT-STRUCTS:
59     ";" parse-tokens
60     implement-structs [ swap append! ] change-global ;
61
62 SYNTAX: FOREIGN-ATOMIC-TYPE:
63     scan-token scan-object swap register-atomic-type ;
64
65 SYNTAX: FOREIGN-ENUM-TYPE:
66     scan-token scan-object swap register-enum-type ;
67
68 SYNTAX: FOREIGN-RECORD-TYPE:
69     scan-token scan-object swap register-record-type ;