summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2011-01-10 09:53:52 -0800
committerStig Thormodsrud <stig@vyatta.com>2011-01-11 16:39:32 -0800
commita0896d805699494a4d4fcb2d30fece2678ee0fbf (patch)
tree19893433428ab70d38e153a69f9d943791fdd038
parent08130814f16f30c634979a36ad228da555ce776a (diff)
downloadvyatta-cfg-a0896d805699494a4d4fcb2d30fece2678ee0fbf.tar.gz
vyatta-cfg-a0896d805699494a4d4fcb2d30fece2678ee0fbf.zip
tweak parser for top-level comment
(cherry picked from commit 7f436bd240d19bace94f102ce2f035399e48d612)
-rw-r--r--src/cparse/cparse.ypp31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/cparse/cparse.ypp b/src/cparse/cparse.ypp
index 23a63b2..66ddfd3 100644
--- a/src/cparse/cparse.ypp
+++ b/src/cparse/cparse.ypp
@@ -9,6 +9,14 @@
#include "cparse.hpp"
#include "cparse_def.h"
+/* to enable tracing, define ENABLE_PARSER_TRACE. may also want to invoke
+ * bison with "-v" (by changing Makefile.am).
+ */
+#undef ENABLE_PARSER_TRACE
+#ifdef ENABLE_PARSER_TRACE
+#define YYDEBUG 1
+#endif // ENABLE_PARSER_TRACE
+
using namespace std;
using namespace cnode;
@@ -129,18 +137,11 @@ go_up()
%%
-input: forest
- | forest comment
+input: forest comment
;
forest: /* empty */
- | forest {
- if (!cur_parent) {
- // root node
- cur_parent = new CfgNode(pcomps, nname, nval, ncomment,
- ndeact, cstore);
- }
- } tree
+ | forest tree
;
tree: node {
@@ -175,8 +176,8 @@ nodec: NODE {
}
;
-comment: COMMENT
- | comment COMMENT
+comment: /* empty */
+ | COMMENT comment
;
%%
@@ -184,8 +185,16 @@ comment: COMMENT
CfgNode *
cparse::parse_file(FILE *fin, Cstore& cs)
{
+ // for debug (see prologue)
+#ifdef ENABLE_PARSER_TRACE
+ cparse_debug = 1;
+#endif // ENABLE_PARSER_TRACE
+
cparse_set_in(fin);
cstore = &cs;
+
+ // root node
+ cur_parent = new CfgNode(pcomps, nname, nval, ncomment, ndeact, cstore);
if (cparse_parse() != 0) {
// parsing failed
return NULL;