Patch for XML pretty printer
Jann Röder <[email protected]> Thu, 3 Sep 2009 19:18:23 +0200
| Newsgroups | gmane.comp.lang.eiffel.gobo.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, I wrote a patch for the XML pretty printer to make it use the short form for tags that don't have content or children, i.e. <tag/> instead of <tag></tag> . See attachment. I also noticed, that the pretty printer does not output the XML descriptor (this: <?xml version="1.0" ?>). I'm not sure what's the best way to fix this. Simply adding code in the on_xml_descriptor feature doesn't work because it is never called, or I don't know what to do to have it called. Anyway in the meantime I'd be glad about some feedback regarding my patch. Jann ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ gobo-eiffel-develop mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop
tags.patch
(text/x-diff, 3.6 KB)
Index: xm_indent_pretty_print_filter.e
===================================================================
--- xm_indent_pretty_print_filter.e (revision 6665)
+++ xm_indent_pretty_print_filter.e (working copy)
@@ -70,6 +70,8 @@
do
check space_preserved_not_void: space_preserved /= Void end
+ flush_close_tag_buffer
+
if not has_content then
if is_root then
is_root := False
@@ -105,14 +107,18 @@
do
depth := depth - 1
- if not has_content then
- output_indent_new_line
- output_indent
+ if last_call_was_start_tag_finish then
+ Precursor (a_namespace, a_prefix, a_local_part)
+ else
+ if not has_content then
+ output_indent_new_line
+ output_indent
+ end
+
+ Precursor (a_namespace, a_prefix, a_local_part)
end
+
has_content := False
-
- Precursor (a_namespace, a_prefix, a_local_part)
-
space_preserved.remove
end
Index: xm_pretty_print_filter.e
===================================================================
--- xm_pretty_print_filter.e (revision 6665)
+++ xm_pretty_print_filter.e (working copy)
@@ -45,6 +45,8 @@
output_constant (Space_s)
output (a_content)
output_constant (Pi_end)
+
+ last_call_was_start_tag_finish := False
Precursor (a_name, a_content)
end
@@ -54,6 +56,8 @@
output_constant (Comment_start)
output (a_content)
output_constant (Comment_end)
+
+ last_call_was_start_tag_finish := False
Precursor (a_content)
end
@@ -62,36 +66,53 @@
on_start_tag (a_namespace: STRING; a_prefix: STRING; a_local_part: STRING) is
-- Print start of start tag.
do
+ flush_close_tag_buffer
+
output_constant (Stag_start)
output_name (a_prefix, a_local_part)
+
+ last_call_was_start_tag_finish := False
Precursor (a_namespace, a_prefix, a_local_part)
end
on_attribute (a_namespace: STRING; a_prefix: STRING; a_local_part: STRING; a_value: STRING) is
-- Print attribute.
do
+ flush_close_tag_buffer
+
output_constant (Space_s)
output_name (a_prefix, a_local_part)
output_constant (Eq_s)
output_constant (Quot_s)
output_quote_escaped (a_value)
output_constant (Quot_s)
+
+ last_call_was_start_tag_finish := False
Precursor (a_namespace, a_prefix, a_local_part, a_value)
end
on_start_tag_finish is
-- Print end of start tag.
do
- output_constant (Stag_end)
+ close_tag_buffered := True
+
+ last_call_was_start_tag_finish := True
Precursor
end
on_end_tag (a_namespace: STRING; a_prefix: STRING; a_local_part: STRING) is
-- Print end tag.
do
- output_constant (Etag_start)
- output_name (a_prefix, a_local_part)
- output_constant (Etag_end)
+ if last_call_was_start_tag_finish then
+ output_constant (emptytag_end)
+ close_tag_buffered := False
+ else
+ output_constant (Etag_start)
+ output_name (a_prefix, a_local_part)
+ output_constant (Etag_end)
+ end
+
+ last_call_was_start_tag_finish := False
Precursor (a_namespace, a_prefix, a_local_part)
end
@@ -102,10 +123,29 @@
-- NOT atomic: successive content may be different.
-- Default: forward event to 'next'.
do
+ flush_close_tag_buffer
+
output_escaped (a_content)
+
+ last_call_was_start_tag_finish := False
Precursor (a_content)
end
+feature {NONE} -- Implementation
+
+ last_call_was_start_tag_finish: BOOLEAN
+
+ close_tag_buffered: BOOLEAN
+
+ flush_close_tag_buffer is
+ -- Output the buffered close tag, if any
+ do
+ if close_tag_buffered then
+ output_constant (stag_end)
+ close_tag_buffered := False
+ end
+ end
+
feature {NONE} -- Escaped
is_escaped (a_char: INTEGER): BOOLEAN is