File: Parser.yp

package info (click to toggle)
libxml-xql-perl 0.66-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 612 kB
  • ctags: 535
  • sloc: perl: 5,841; xml: 4,007; makefile: 34
file content (199 lines) | stat: -rw-r--r-- 4,576 bytes parent folder | download | duplicates (5)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
%left SeqOp
%left 'or'
%left 'and'
%left 'not'
%left UnionOp
%left 'intersect'
%left COMPARE
%left MATCH
%left '/' '//'
%left '!'
%left '[' ']'
%left '(' ')'

%%

Query:		Sequence
		;

WildNCName:	NCName | '*'
		;

#?? not sure about NCName

WildQName:	WildNCName { [ Name => $_[1] ]; }
		| WildNCName ':' WildNCName { 
			[ NameSpace => $_[1], Name => $_[2]]; }
		;

Param:		Disjunction
		| INTEGER { new XML::XQL::Number ($_[1]); }
		| NUMBER { new XML::XQL::Number ($_[1]); }
		| TEXT { new XML::XQL::Text ($_[1]); }
		;

ElementName:	WildQName { new XML::XQL::Element (@{$_[1]}); }
		;

AttributeName:	'@' WildQName { new XML::XQL::Attribute (@{$_[2]}); }
		;

Invocation:	XQLName_Paren Invocation_2 {
			my ($func, $type) = $_[0]->{Query}->findFunctionOrMethod ($_[1], $_[2]);

			new XML::XQL::Invocation (Name => $_[1], 
						  Args => $_[2],
						  Func => $func,
						  Type => $type); }
		;

Invocation_2:	')' { [] }
		| Param Invocation_3 ')' { unshift @{$_[2]}, $_[1]; $_[2]; }
		;

Invocation_3:	/* empty */ { [] }
		| ',' Param Invocation_3 { unshift @{$_[3]}, $_[2]; $_[3]; }
		;

PathOp:		'/' | '//'
		;

Sequence:	Disjunction
		| Disjunction SeqOp Sequence {
		    new XML::XQL::Sequence (Left => $_[1], Oper => $_[2], 
					    Right => $_[3]); }
		;

Disjunction:	Conjunction 
		| Conjunction 'or' Disjunction { 
		    new XML::XQL::Or (Left => $_[1], Right => $_[3]); }
		;

Conjunction:	Negation
		| Negation 'and' Conjunction { 
		    new XML::XQL::And (Left => $_[1], Right => $_[3]); }
		;

Negation:	Union
		| 'not' Negation { new XML::XQL::Not (Left => $_[2]); }
		;

Union:		Intersection 
		| Intersection UnionOp Union { 
		    new XML::XQL::Union (Left => $_[1], Right => $_[3]); }
		;

Intersection:	Comparison 
		| Comparison 'intersect' Intersection { 
		    new XML::XQL::Intersect (Left => $_[1], Right => $_[3]); }
		;

ComparisonOp:	COMPARE {
		  [ $_[1], $_[0]->{Query}->findComparisonOperator ($_[1]) ]; }
		| MATCH {
		  [ $_[1], $_[0]->{Query}->findComparisonOperator ($_[1]) ]; }
		;

Comparison:	Path
		| LValue ComparisonOp RValue {
			new XML::XQL::Compare (All => 0, Left => $_[1], 
				Oper => $_[2]->[0], Func => $_[2]->[1], 
				Right => $_[3]); }
		| 'any' LValue ComparisonOp RValue {
			new XML::XQL::Compare (All => 0, Left => $_[2], 
				Oper => $_[3]->[0], Func => $_[3]->[1],
				Right => $_[4]); }
		| 'all' LValue ComparisonOp RValue {
			new XML::XQL::Compare (All => 1, Left => $_[2], 
				Oper => $_[3]->[0], Func => $_[3]->[1],
				Right => $_[4]); }
		;

LValue:		Path
		;

RValue:		Path
		| INTEGER { new XML::XQL::Number ($_[1]); }
		| NUMBER { new XML::XQL::Number ($_[1]); }
		| TEXT { new XML::XQL::Text ($_[1]); }
		;

Path:		AbsolutePath | RelativePath
		;

AbsolutePath:	'/' { new XML::Root; }
		| PathOp RelativePath { 
		    new XML::XQL::Path (PathOp => $_[1], Right => $_[2]); }
		;

RelativePath:	Bang 
		| Bang PathOp RelativePath { 
		    new XML::XQL::Path (Left => $_[1], PathOp => $_[2], 
				        Right => $_[3]); }
		;

Bang:		Subscript
		| Subscript '!' Invocation {
		    XML::XQL::parseError ("only methods (not functions) can be used after the Bang (near '!" . $_[3]->{Name} . "'")
			unless $_[3]->isMethod;

		    new XML::XQL::Bang (Left => $_[1], 
				        Right => $_[3]); }
		;

Subscript:	Filter Subscript_2 { 
		    defined($_[2]) ? 
			new XML::XQL::Subscript (Left => $_[1], 
					    IndexList => $_[2]) : $_[1]; }
		;

Subscript_2:	/* empty */
		| '[' IndexList ']' { $_[2]; }
#?? The following line *IS* part of the XQL spec, but it doesn't make sense
#??		| '[' ']'
		;

IndexList:	IndexArg IndexList_2 { push (@{$_[1]}, @{$_[2]}); $_[1]; }
		;

IndexList_2:	/* empty */ { [] } 
		| ',' IndexArg IndexList_2 { push (@{$_[2]}, @{$_[3]}); $_[2]; }
		;

IndexArg:	INTEGER { [ $_[1], $_[1] ]; }
		| Range
		;

Range:		INTEGER 'to' INTEGER {
		    # Syntactic Constraint 9:
		    # If both integers are positive or if both integers are 
		    # negative, the first integer must be less than or
          	    # equal to the second integer. 

		    XML::XQL::parseError (
			"$_[1] should be less than $_[3] in '$_[1] $_[2] $_[3]'")
				if ($_[1] > $_[3] && ($_[1] < 0) == ($_[3] < 0));
		    [ $_[1], $_[3] ]; }
		;

Filter:		Grouping 
		| Filter '[' Subquery ']' { 
			new XML::XQL::Filter (Left => $_[1], Right => $_[3]); }
		;

#?? Eliminate Subquery
Subquery:	Query
		;

Grouping:	RelativeTerm 
		| '(' Query ')'	 { $_[2]; }
		;

RelativeTerm:	'.' { new XML::XQL::Current; }
		| '..' { new XML::XQL::Parent; }
		| Invocation 
		| ElementName
		| AttributeName
		;

%%