This repository has been archived by the owner on Jun 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml.pir
130 lines (99 loc) · 2.6 KB
/
xml.pir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Copyright (C) 2009, Parrot Foundation.
=head1 TITLE
xml.pir - A Xml compiler.
=head2 Description
This is the base file for the Xml compiler.
This file includes the parsing and grammar rules from
the src/ directory, loads the relevant PGE libraries,
and registers the compiler under the name 'Xml'.
=head2 Functions
=over 4
=item onload()
Creates the Xml compiler using a C<PCT::HLLCompiler>
object.
=cut
.namespace [ 'Xml';'Sax';'Xml';'Compiler' ]
.sub 'onload' :anon :load :init
load_bytecode 'PCT.pbc'
new $P0, 'P6metaclass'
$P0.'new_class'('Xml::Sax::Xml::Compiler', 'attr'=>'comp')
$P0 = get_hll_global ['PCT'], 'HLLCompiler'
$P1 = $P0.'new'()
$P1.'language'('Xml')
$P1.'parsegrammar'('Xml::Sax::Xml::Grammar')
$P1.'parseactions'('Xml::Sax::Xml::Grammar::Actions')
$P1.'removestage'('evalpmc')
$P1.'removestage'('pir')
$P1.'removestage'('post')
.end
.sub 'init' :method :vtable
$P0 = compreg 'Xml'
self.'comp'($P0)
.end
.sub 'attr' :method
.param string attrname
.param pmc value
.param int has_value
if has_value goto set_value
value = getattribute self, attrname
unless null value goto end
value = new 'Undef'
goto end
set_value:
setattribute self, attrname, value
end:
.return (value)
.end
.sub 'comp' :method
.param pmc value :optional
.param int has_value :opt_flag
.tailcall self.'attr'('comp', value, has_value)
.end
.sub 'handler' :method
.param pmc value :optional
.param int has_value :opt_flag
if has_value goto set_value
value = get_hll_global [ 'Xml';'Sax';'Xml';'Compiler' ], 'Handler'
unless null value goto end
value = new 'Undef'
goto end
set_value:
set_hll_global [ 'Xml';'Sax';'Xml';'Compiler' ], 'Handler', value
end:
.return (value)
.end
.sub 'parse' :method
.param pmc source
$P0 = self.'comp'()
.tailcall $P0.'parse'(source)
.end
.sub 'parse_string' :method
.param pmc source
.tailcall self.'parse'(source)
.end
.sub 'parse_file' :method
.param pmc stream
$P0 = new 'FileHandle'
$S0 = $P0.'readall'(stream)
$P0.'close'()
.tailcall self.'parse'($S0)
.end
=item main(args :slurpy) :main
Start compilation by passing any command line C<args>
to the Xml compiler.
=cut
.sub 'main' :main
.param pmc args
$P0 = compreg 'Xml'
$P1 = $P0.'command_line'(args)
.end
.include 'sax/xml/gen_builtins.pir'
.include 'sax/xml/gen_grammar.pir'
.include 'sax/xml/gen_actions.pir'
=back
=cut
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: