summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2009-02-26 00:55:21 +0000
committerAdrian Thurston <thurston@complang.org>2009-02-26 00:55:21 +0000
commit6d1fbb18b8aa01a8cca22b460d087aff8faa65d8 (patch)
tree01cd6f5738aea6421a854ff10390717e96034bd7
parente544db3aa8d2cd36ebbeb5ad2e71c17b6ec7de29 (diff)
downloadcolm-6d1fbb18b8aa01a8cca22b460d087aff8faa65d8.tar.gz
The print_xml function now omits attributes and comments. Now use print_xml_ac
to get those in the printout.
-rw-r--r--colm/bytecode.cpp14
-rw-r--r--colm/bytecode.h7
-rw-r--r--colm/compile.cpp7
-rw-r--r--colm/lmparse.kh2
-rw-r--r--colm/lmparse.kl4
-rw-r--r--colm/lmscan.rl3
-rw-r--r--colm/parsetree.h1
-rw-r--r--colm/tree.cpp22
8 files changed, 44 insertions, 16 deletions
diff --git a/colm/bytecode.cpp b/colm/bytecode.cpp
index 58db7499..08a1ac98 100644
--- a/colm/bytecode.cpp
+++ b/colm/bytecode.cpp
@@ -871,6 +871,18 @@ again:
tree_downref( prg, sp, tree );
break;
}
+ case IN_PRINT_XML_AC: {
+ #ifdef COLM_LOG_BYTECODE
+ if ( colm_log_bytecode ) {
+ cerr << "IN_PRINT_XML_AC" << endl;
+ }
+ #endif
+
+ Tree *tree = pop();
+ print_xml_tree( sp, prg, tree, true );
+ tree_downref( prg, sp, tree );
+ break;
+ }
case IN_PRINT_XML: {
#ifdef COLM_LOG_BYTECODE
if ( colm_log_bytecode ) {
@@ -879,7 +891,7 @@ again:
#endif
Tree *tree = pop();
- print_xml_tree( sp, prg, tree );
+ print_xml_tree( sp, prg, tree, false );
tree_downref( prg, sp, tree );
break;
}
diff --git a/colm/bytecode.h b/colm/bytecode.h
index c13578a7..1b3eb02a 100644
--- a/colm/bytecode.h
+++ b/colm/bytecode.h
@@ -183,7 +183,8 @@ typedef unsigned char uchar;
#define IN_VECTOR_INSERT_BKT 0x84
#define IN_PRINT 0x87
-#define IN_PRINT_XML 0x88
+#define IN_PRINT_XML_AC 0x88
+#define IN_PRINT_XML 0xab
#define IN_HALT 0x8a
@@ -486,8 +487,8 @@ Tree *prep_parse_tree( Program *prg, Tree **sp, Tree *tree );
void print_tree( Tree **&sp, Program *prg, Tree *tree );
void print_tree( ostream &out, Tree **&sp, Program *prg, Tree *tree );
void print_str( Head *str );
-void print_xml_tree( Tree **&sp, Program *prg, Tree *tree );
-void print_xml_kid( Tree **&sp, Program *prg, Kid *kid, int depth );
+void print_xml_tree( Tree **&sp, Program *prg, Tree *tree, bool commAttr );
+void print_xml_kid( Tree **&sp, Program *prg, Kid *kid, bool commAttr, int depth );
long list_length( List *list );
void list_append( Program *prg, List *list, Tree *val );
diff --git a/colm/compile.cpp b/colm/compile.cpp
index 918b9712..2a9b810e 100644
--- a/colm/compile.cpp
+++ b/colm/compile.cpp
@@ -1704,6 +1704,7 @@ void LangStmt::compile( ParseData *pd, CodeVect &code ) const
{
switch ( type ) {
case PrintType:
+ case PrintXMLACType:
case PrintXMLType: {
UniqueType **types = new UniqueType*[exprPtrVect->length()];
@@ -1716,7 +1717,11 @@ void LangStmt::compile( ParseData *pd, CodeVect &code ) const
for ( ExprVect::Iter pex = *exprPtrVect; pex.lte(); pex++ )
code.append( IN_PRINT );
}
- else {
+ else if ( type == PrintXMLACType ) {
+ for ( ExprVect::Iter pex = *exprPtrVect; pex.lte(); pex++ )
+ code.append( IN_PRINT_XML_AC );
+ }
+ else if ( type == PrintXMLType ) {
for ( ExprVect::Iter pex = *exprPtrVect; pex.lte(); pex++ )
code.append( IN_PRINT_XML );
}
diff --git a/colm/lmparse.kh b/colm/lmparse.kh
index 0184a76d..b51d0e3d 100644
--- a/colm/lmparse.kh
+++ b/colm/lmparse.kh
@@ -52,7 +52,7 @@ struct Parser
# Language.
token KW_If, KW_While, KW_Else, KW_Elsif, KW_For, KW_Return, KW_Yield, KW_In,
- KW_Break, KW_PrintXML, KW_Print, KW_Require;
+ KW_Break, KW_PrintXMLAC, KW_PrintXML, KW_Print, KW_Require;
# Patterns.
token KW_Match, KW_Construct, KW_Parse, KW_ParseStop, KW_New, KW_MakeToken,
diff --git a/colm/lmparse.kl b/colm/lmparse.kl
index beb70bc8..ed9102cc 100644
--- a/colm/lmparse.kl
+++ b/colm/lmparse.kl
@@ -984,6 +984,10 @@ statement: KW_Print '(' code_expr_list ')'
final {
$$->stmt = new LangStmt( $1->loc, LangStmt::PrintType, $3->exprVect );
};
+statement: KW_PrintXMLAC '(' code_expr_list ')'
+ final {
+ $$->stmt = new LangStmt( $1->loc, LangStmt::PrintXMLACType, $3->exprVect );
+ };
statement: KW_PrintXML '(' code_expr_list ')'
final {
$$->stmt = new LangStmt( $1->loc, LangStmt::PrintXMLType, $3->exprVect );
diff --git a/colm/lmscan.rl b/colm/lmscan.rl
index 8d42f274..d5e5f0f8 100644
--- a/colm/lmscan.rl
+++ b/colm/lmscan.rl
@@ -355,7 +355,6 @@ void Scanner::endSection( )
'ignore' => { token( KW_Ignore ); };
'construct' => { token( KW_Construct ); };
'new' => { token( KW_New ); };
- 'print' => { token( KW_Print ); };
'if' => { token( KW_If ); };
'reject' => { token( KW_Reject ); };
'while' => { token( KW_While ); };
@@ -364,6 +363,8 @@ void Scanner::endSection( )
'match' => { token( KW_Match ); };
'for' => { token( KW_For ); };
'iter' => { token( KW_Iter ); };
+ 'print' => { token( KW_Print ); };
+ 'print_xml_ac' => { token( KW_PrintXMLAC ); };
'print_xml' => { token( KW_PrintXML ); };
'namespace' => { token( KW_Namespace ); };
'lex' => { token( KW_Lex ); };
diff --git a/colm/parsetree.h b/colm/parsetree.h
index e4ef5e38..6de45be6 100644
--- a/colm/parsetree.h
+++ b/colm/parsetree.h
@@ -1497,6 +1497,7 @@ struct LangStmt
enum Type {
AssignType,
PrintType,
+ PrintXMLACType,
PrintXMLType,
ExprType,
IfType,
diff --git a/colm/tree.cpp b/colm/tree.cpp
index fafef8b0..42bcec9b 100644
--- a/colm/tree.cpp
+++ b/colm/tree.cpp
@@ -500,13 +500,12 @@ void print_xml_ignore_list( Tree **sp, Program *prg, Tree *tree, long depth )
{
Kid *ignore = tree_ignore( prg, tree );
while ( tree_is_ignore( prg, ignore ) ) {
- print_xml_kid( sp, prg, ignore, depth );
+ print_xml_kid( sp, prg, ignore, true, depth );
ignore = ignore->next;
}
}
-
-void print_xml_kid( Tree **&sp, Program *prg, Kid *kid, int depth )
+void print_xml_kid( Tree **&sp, Program *prg, Kid *kid, bool commAttr, int depth )
{
Kid *child;
Tree **root = vm_ptop();
@@ -525,7 +524,8 @@ rec_call:
}
else {
/* First print the ignore tokens. */
- print_xml_ignore_list( sp, prg, kid->tree, depth );
+ if ( commAttr )
+ print_xml_ignore_list( sp, prg, kid->tree, depth );
for ( i = 0; i < depth; i++ )
cout << " ";
@@ -534,8 +534,7 @@ rec_call:
* we will close it off immediately. */
cout << '<' << lelInfo[kid->tree->id].name;
- /* If the parent kid is a repeat then skip this node and go
- * right to the first child (repeated item). */
+ /* If this is an attribute then give the node an attribute number. */
if ( vm_ptop() != root ) {
objectLength = lelInfo[((Kid*)vm_top())->tree->id].objectLength;
if ( kidNum < objectLength )
@@ -544,13 +543,18 @@ rec_call:
objectLength = lelInfo[kid->tree->id].objectLength;
child = tree_child( prg, kid->tree );
- if ( objectLength > 0 || child != 0 ) {
+ if ( (commAttr && objectLength > 0) || child != 0 ) {
cout << '>' << endl;
vm_push( (SW) kidNum );
vm_push( (SW) kid );
kidNum = 0;
kid = kid->tree->child;
+
+ /* Skip over attributes if not printing comments and attributes. */
+ if ( ! commAttr )
+ kid = child;
+
while ( kid != 0 ) {
if ( kid->tree == 0 || !lelInfo[kid->tree->id].ignore ) {
depth++;
@@ -620,12 +624,12 @@ rec_call:
goto rec_return;
}
-void print_xml_tree( Tree **&sp, Program *prg, Tree *tree )
+void print_xml_tree( Tree **&sp, Program *prg, Tree *tree, bool commAttr )
{
Kid kid;
kid.tree = tree;
kid.next = 0;
- print_xml_kid( sp, prg, &kid, 0 );
+ print_xml_kid( sp, prg, &kid, commAttr, 0 );
}
void stream_free( Program *prg, Stream *s )