[Aurelia-svn] SF.net SVN: aurelia:[147] trunk
Status: Alpha
Brought to you by:
valentindavid
|
From: <val...@us...> - 2010-12-06 17:19:10
|
Revision: 147
http://aurelia.svn.sourceforge.net/aurelia/?rev=147&view=rev
Author: valentindavid
Date: 2010-12-06 17:19:03 +0000 (Mon, 06 Dec 2010)
Log Message:
-----------
2010-12-06 Valentin David <val...@ii...>
Handle sugar for layout parsing in parser generator.
* src/patterns/term_pattern.hh:
Set a non-template function as inline to avoid linking errors.
* src/strategies/generic/fail.hh,
* src/strategies/generic/id.hh:
Set globals as extern to avoid linking errors.
* src/parser_generator/syntax.csf: Add extension as sugar.
* src/parser_generator/syntax.cc: Include and define
necessary environment for the parser.
* src/parser_generator/tests/parser.cc: New.
* src/parser_generator/tests/gamma_2.cc: Remove.
* src/parser_generator/tests/input.txt: Rename as...
* src/parser_generator/tests/input_gamma_2.txt: ... this.
* src/parser_generator/tests/layout.csf,
* src/parser_generator/tests/input_layout.txt: New.
* src/parser_generator/tests/Makefile.am: Update.
* src/strategies/patterns/scope.hh:
Allow void strategies to be used in a scope.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/parser_generator/syntax.cc
trunk/src/parser_generator/syntax.csf
trunk/src/parser_generator/tests/Makefile.am
trunk/src/patterns/term_pattern.hh
trunk/src/strategies/generic/fail.hh
trunk/src/strategies/generic/id.hh
trunk/src/strategies/patterns/scope.hh
Added Paths:
-----------
trunk/src/parser_generator/tests/input_gamma_2.txt
trunk/src/parser_generator/tests/input_layout.txt
trunk/src/parser_generator/tests/layout.csf
trunk/src/parser_generator/tests/parser.cc
Removed Paths:
-------------
trunk/src/parser_generator/tests/gamma_2.cc
trunk/src/parser_generator/tests/input.txt
Property Changed:
----------------
trunk/src/parser_generator/tests/
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/ChangeLog 2010-12-06 17:19:03 UTC (rev 147)
@@ -1,3 +1,32 @@
+2010-12-06 Valentin David <val...@ii...>
+
+ Handle sugar for layout parsing in parser generator.
+
+ * src/patterns/term_pattern.hh:
+ Set a non-template function as inline to avoid linking errors.
+
+ * src/strategies/generic/fail.hh,
+ * src/strategies/generic/id.hh:
+ Set globals as extern to avoid linking errors.
+
+ * src/parser_generator/syntax.csf: Add extension as sugar.
+
+ * src/parser_generator/syntax.cc: Include and define
+ necessary environment for the parser.
+
+ * src/parser_generator/tests/parser.cc: New.
+ * src/parser_generator/tests/gamma_2.cc: Remove.
+ * src/parser_generator/tests/input.txt: Rename as...
+ * src/parser_generator/tests/input_gamma_2.txt: ... this.
+
+ * src/parser_generator/tests/layout.csf,
+ * src/parser_generator/tests/input_layout.txt: New.
+
+ * src/parser_generator/tests/Makefile.am: Update.
+
+ * src/strategies/patterns/scope.hh:
+ Allow void strategies to be used in a scope.
+
2010-11-15 Valentin David <val...@ii...>
Add terms for pretty printing.
Modified: trunk/src/parser_generator/syntax.cc
===================================================================
--- trunk/src/parser_generator/syntax.cc 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/parser_generator/syntax.cc 2010-12-06 17:19:03 UTC (rev 147)
@@ -18,18 +18,23 @@
#include <sstream>
#include <iostream>
#include <fstream>
+#include <stack>
#include "llstack/queue.hh"
#include "llstack/node.hh"
#include "streams/buf_stream.hh"
#include "llstack/label.hh"
#include "llstack/node.hpp"
#include "terms/term.hh"
+#include "patterns/term_pattern.hh"
+#include "strategies/patterns/scope.hh"
+#include "strategies/lists/const_map.hh"
using namespace aurelia;
using namespace llstack;
struct Main {};
typedef untyped_term<Main> T;
typedef untyped_constructor<Main> C;
+typedef variable<T> V;
frame pop_void(const frame& f) {
return f.as<ret_frame<void_return> >().parent;
Modified: trunk/src/parser_generator/syntax.csf
===================================================================
--- trunk/src/parser_generator/syntax.csf 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/parser_generator/syntax.csf 2010-12-06 17:19:03 UTC (rev 147)
@@ -97,13 +97,13 @@
Rule ::=
Symbol //rf3
- LAYOUT? $ frame next_frame(f); $
+ LAYOUT?
ParameterList //rf2
- LAYOUT? $ frame next_frame(f); $
+ LAYOUT?
RetType //rf1
- LAYOUT? $ frame next_frame(f); $
- "::=" $ frame next_frame(f); $
- LAYOUT? $ frame next_frame(f); $
+ LAYOUT?
+ "::="
+ LAYOUT?
ListOfChains //rf0
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
@@ -112,6 +112,51 @@
ret_frame<T> rf3 = rf2.parent.as<ret_frame<T> >();
T ret(C("Rule", 4), (rf3.t, rf2.t, rf1.t, rf0.t));
$
+ |
+ "<" LAYOUT? AttrChainElt LAYOUT? ">" LAYOUT?
+ Symbol //rf3
+ LAYOUT?
+ ParameterList //rf2
+ LAYOUT?
+ RetType //rf1
+ LAYOUT?
+ "::="
+ LAYOUT?
+ ListOfChains //rf0
+ $
+ ret_frame<T> rf0 = f.as<ret_frame<T> >();
+ ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
+ ret_frame<T> rf2 = rf1.parent.as<ret_frame<T> >();
+ ret_frame<T> rf3 = rf2.parent.as<ret_frame<T> >();
+ ret_frame<T> rf4 = rf3.parent.as<ret_frame<T> >();
+ static C Chain("Chain", 2);
+ V chain, attr;
+ std::stack<T> chains;
+ T list = rf0.t;
+ const_map(scope(attr, scope(chain, ~Chain[chain, attr] < !chain <
+ [&chains, &attr, &rf4](const T& c) {
+ std::stack<T> syms;
+ const_map([&syms, &rf4](const T& u) {
+ syms.push(u);
+ syms.push(rf4.t);
+ })(c);
+ if (!syms.empty())
+ syms.pop();
+ T newl = T(C::AS_EMPTY_LIST);
+ while (!syms.empty()) {
+ newl = T(C::AS_LIST, (syms.top(), newl));
+ syms.pop();
+ }
+ chains.push((T(Chain,
+ (newl, *attr))));
+ })))(rf0.t);
+ T newchains = T(C::AS_EMPTY_LIST);
+ while (!chains.empty()) {
+ newchains = T(C::AS_LIST, (chains.top(), newchains));
+ chains.pop();
+ }
+ T ret(C("Rule", 4), (rf3.t, rf2.t, rf1.t, newchains));
+ $
S ::= LAYOUT? SS LAYOUT? $
ret_frame<T> rf0 = f.as<ret_frame<T> >();
@@ -166,14 +211,19 @@
| $ T ret(C::AS_EMPTY_LIST); $
NonEmptyChain ::=
- AttrRule? LAYOUT? ChainElt LAYOUT? Chain
+ AttrChainElt LAYOUT? Chain
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
- ret_frame<T> rf2 = rf1.parent.as<ret_frame<T> >();
- T ret(C::AS_LIST, (T(C("AttrChainElt", 2), (rf2.t, rf1.t)), rf0.t));
+ T ret(C::AS_LIST, (rf1.t, rf0.t));
$
+ AttrChainElt ::= AttrRule? LAYOUT? ChainElt
+ $
+ ret_frame<T> rf0 = f.as<ret_frame<T> >();
+ ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
+ T ret(C("AttrChainElt", 2), (rf1.t, rf0.t));
+ $
AttrRule ::=
LocalParameters LAYOUT? "$" $ ret_frame<stream> next_frame(f, s); $ CxxCode $ ret_frame<stream> next_frame(f, s); $ "$"
$
Property changes on: trunk/src/parser_generator/tests
___________________________________________________________________
Modified: svn:ignore
- Makefile
Makefile.in
gamma_2.tree
gamma_2
gamma_2.hh
.deps
gamma_2.log
test-suite.log
+ Makefile
Makefile.in
gamma_2.tree
gamma_2
gamma_2.hh
.deps
gamma_2.log
test-suite.log
layout.hh
layout
gamma_2.dir
layout.dir
layout.log
gamma_2.log
Modified: trunk/src/parser_generator/tests/Makefile.am
===================================================================
--- trunk/src/parser_generator/tests/Makefile.am 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/parser_generator/tests/Makefile.am 2010-12-06 17:19:03 UTC (rev 147)
@@ -17,14 +17,26 @@
include $(top_srcdir)/config/local_parser_gen.mk
-gamma_2_CPPFLAGS=-DSRCDIR=\"$(srcdir)\" $(AM_CPPFLAGS)
+gamma_2_CPPFLAGS=-DSRCDIR=\"$(srcdir)\" $(AM_CPPFLAGS) -DMOD=\"gamma_2\" -Igamma_2.dir
+layout_CPPFLAGS=-DSRCDIR=\"$(srcdir)\" $(AM_CPPFLAGS) -DMOD=\"layout\" -Ilayout.dir
-check_PROGRAMS=gamma_2
-TESTS=gamma_2
+check_PROGRAMS=gamma_2 layout
+TESTS=gamma_2 layout
gamma_2.hh: $(CSF)
+layout.hh: $(CSF)
-gamma_2_SOURCES=gamma_2.cc gamma_2.csf
+parser.cc: gamma_2.dir/grammar.hh gamma_2.hh
+parser.cc: layout.dir/grammar.hh layout.hh
-CLEANFILES=gamma_2.hh
-EXTRA_DIST=input.txt
+%.dir/grammar.hh:
+ dir=`dirname "$@"`; \
+ base=`basename "$$dir" .dir`; \
+ $(MKDIR_P) "$$dir"; \
+ echo "#include \"$$base.hh\"" >"$@"
+
+gamma_2_SOURCES=parser.cc gamma_2.csf
+layout_SOURCES=parser.cc layout.csf
+
+CLEANFILES=gamma_2.hh layout.hh gamma_2.dir/grammar.hh layout.dir/grammar.hh
+EXTRA_DIST=input_gamma_2.txt input_layout.txt
Deleted: trunk/src/parser_generator/tests/gamma_2.cc
===================================================================
--- trunk/src/parser_generator/tests/gamma_2.cc 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/parser_generator/tests/gamma_2.cc 2010-12-06 17:19:03 UTC (rev 147)
@@ -1,91 +0,0 @@
-// This file is a part of Aurelia.
-// Copyright (C) 2010 Valentin David
-// Copyright (C) 2010 University of Bergen
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#include <sstream>
-#include <iostream>
-#include <fstream>
-#include "llstack/queue.hh"
-#include "llstack/node.hh"
-#include "streams/buf_stream.hh"
-#include "llstack/label.hh"
-#include "llstack/node.hpp"
-
-using namespace aurelia;
-using namespace llstack;
-#include "gamma_2.hh"
-
-bool found;
-
-struct start_label {
- void operator()(r_t&, const frame&, stream& s, const node&) const {
- if (s.eof()) {
- std::cerr << s.get_pos() << " " << "Found!" << std::endl;
- found = true;
- }
- }
-};
-
-struct end_label {
- void operator()(r_t&, const frame&, stream&, const node&) const {
- }
-};
-
-struct error {};
-
-bool main_loop(stream& s, const stream& end) {
- found = false;
- r_t R;
- if (s.eof()) {
- if (!is_empty_first(S_0_0))
- { throw error(); }
- }
- else if (!is_first(s, S_0_0)) {
- { throw error(); }
- }
- node u1 = node::boundary(start_label(), end);
- node u0 = node::boundary(end_label(), end);
- u1.parents().insert(u0);
- S start;
- start(R, empty_frame(), s, u1);
- int lastpos = -1;
- try {
- while (true) {
- descriptor d = R.pop();
- s = d.s;
- if (lastpos < s.get_pos()) {
- lastpos = s.get_pos();
- /* std::stringstream ss;
- ss << "graph." << s.get_pos();
- std::ofstream out(ss.str());*/
- std::cerr << lastpos << std::endl;
- //node::printnodes(out);
- }
- d.L.call(R, d.f, d.s, d.n);
- }
- } catch (r_t::eof) {
- }
-
- node::clear();
- return found;
-}
-
-int main() {
- std::ifstream in(SRCDIR"/input.txt");
- buf_stream bs(in);
- stream s = bs.begin();
- return !main_loop(s, bs.end());
-}
Deleted: trunk/src/parser_generator/tests/input.txt
===================================================================
--- trunk/src/parser_generator/tests/input.txt 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/parser_generator/tests/input.txt 2010-12-06 17:19:03 UTC (rev 147)
@@ -1 +0,0 @@
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
\ No newline at end of file
Copied: trunk/src/parser_generator/tests/input_gamma_2.txt (from rev 146, trunk/src/parser_generator/tests/input.txt)
===================================================================
--- trunk/src/parser_generator/tests/input_gamma_2.txt (rev 0)
+++ trunk/src/parser_generator/tests/input_gamma_2.txt 2010-12-06 17:19:03 UTC (rev 147)
@@ -0,0 +1 @@
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
\ No newline at end of file
Added: trunk/src/parser_generator/tests/input_layout.txt
===================================================================
--- trunk/src/parser_generator/tests/input_layout.txt (rev 0)
+++ trunk/src/parser_generator/tests/input_layout.txt 2010-12-06 17:19:03 UTC (rev 147)
@@ -0,0 +1,2 @@
+foo
+bar baz
Added: trunk/src/parser_generator/tests/layout.csf
===================================================================
--- trunk/src/parser_generator/tests/layout.csf (rev 0)
+++ trunk/src/parser_generator/tests/layout.csf 2010-12-06 17:19:03 UTC (rev 147)
@@ -0,0 +1,71 @@
+ LAYOUT? ::= LAYOUT+
+ $ if (!s.eof()) {
+ switch (*s) {
+ case ' ':
+ case '\r':
+ case '\n':
+ case '\t':
+ return ;
+ case '/':
+ {
+ buf_stream_iterator next = s;
+ ++next;
+ if (!next.eof()) {
+ if (*next == '/')
+ return ;
+ }
+ }
+ }
+ }
+ void_return ret;
+ $ |
+ $ if (!s.eof()) {
+ switch (*s) {
+ case ' ':
+ case '\r':
+ case '\n':
+ case '\t':
+ return ;
+ case '/':
+ {
+ buf_stream_iterator next = s;
+ ++next;
+ if (!next.eof()) {
+ if (*next == '/')
+ return ;
+ }
+ }
+ }
+ }
+ void_return ret;
+ $
+
+ LAYOUT+ ::= LAYOUT LAYOUT?
+ LAYOUT ::=
+ " " | "\n" | "\r" | "\t"
+ | "//" Line
+ Line ::= "\n" | [^\n-\n] Line
+
+ IdChar ::= [A-Z] | [a-z] | "_"
+ IdChar+ ::= IdChar IdChar*
+ IdChar* ::= IdChar+ |
+ Id ::= IdChar+ $
+ if (!s.eof()) {
+ switch (*s) {
+ case '_':
+ return ;
+ }
+ if (((*s) >= 'A') && (*s) <= 'Z')
+ return ;
+ if (((*s) >= 'a') && (*s) <= 'z')
+ return ;
+ }
+ void_return ret;
+ $
+
+ S ::= LAYOUT? SS LAYOUT?
+ <LAYOUT?> SS ::= Id* SSS
+ SSS ::= SS |
+
+ Id+ ::= Id Id*
+ Id* ::= Id+ |
Copied: trunk/src/parser_generator/tests/parser.cc (from rev 146, trunk/src/parser_generator/tests/gamma_2.cc)
===================================================================
--- trunk/src/parser_generator/tests/parser.cc (rev 0)
+++ trunk/src/parser_generator/tests/parser.cc 2010-12-06 17:19:03 UTC (rev 147)
@@ -0,0 +1,91 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <sstream>
+#include <iostream>
+#include <fstream>
+#include "llstack/queue.hh"
+#include "llstack/node.hh"
+#include "streams/buf_stream.hh"
+#include "llstack/label.hh"
+#include "llstack/node.hpp"
+
+using namespace aurelia;
+using namespace llstack;
+#include "grammar.hh"
+
+bool found;
+
+struct start_label {
+ void operator()(r_t&, const frame&, stream& s, const node&) const {
+ if (s.eof()) {
+ std::cerr << s.get_pos() << " " << "Found!" << std::endl;
+ found = true;
+ }
+ }
+};
+
+struct end_label {
+ void operator()(r_t&, const frame&, stream&, const node&) const {
+ }
+};
+
+struct error {};
+
+bool main_loop(stream& s, const stream& end) {
+ found = false;
+ r_t R;
+ if (s.eof()) {
+ if (!is_empty_first(S_0_0))
+ { throw error(); }
+ }
+ else if (!is_first(s, S_0_0)) {
+ { throw error(); }
+ }
+ node u1 = node::boundary(start_label(), end);
+ node u0 = node::boundary(end_label(), end);
+ u1.parents().insert(u0);
+ S start;
+ start(R, empty_frame(), s, u1);
+ int lastpos = -1;
+ try {
+ while (true) {
+ descriptor d = R.pop();
+ s = d.s;
+ if (lastpos < s.get_pos()) {
+ lastpos = s.get_pos();
+ /* std::stringstream ss;
+ ss << "graph." << s.get_pos();
+ std::ofstream out(ss.str());*/
+ std::cerr << lastpos << std::endl;
+ //node::printnodes(out);
+ }
+ d.L.call(R, d.f, d.s, d.n);
+ }
+ } catch (r_t::eof) {
+ }
+
+ node::clear();
+ return found;
+}
+
+int main() {
+ std::ifstream in(SRCDIR"/input_"MOD".txt");
+ buf_stream bs(in);
+ stream s = bs.begin();
+ return !main_loop(s, bs.end());
+}
Modified: trunk/src/patterns/term_pattern.hh
===================================================================
--- trunk/src/patterns/term_pattern.hh 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/patterns/term_pattern.hh 2010-12-06 17:19:03 UTC (rev 147)
@@ -38,7 +38,7 @@
assign(tail(l), t);
}
- list_nil build(const list_nil&) {
+ inline list_nil build(const list_nil&) {
return list_nil();
}
Modified: trunk/src/strategies/generic/fail.hh
===================================================================
--- trunk/src/strategies/generic/fail.hh 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/strategies/generic/fail.hh 2010-12-06 17:19:03 UTC (rev 147)
@@ -32,7 +32,7 @@
/*! \brief A strategy that always fails for any given input type.
* \ingroup Generic
*/
- fail_strategy fail;
+ extern fail_strategy fail;
}
Modified: trunk/src/strategies/generic/id.hh
===================================================================
--- trunk/src/strategies/generic/id.hh 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/strategies/generic/id.hh 2010-12-06 17:19:03 UTC (rev 147)
@@ -33,8 +33,7 @@
/*! \brief A strategy that always succeeds for any given input type.
* \ingroup Generic
*/
- id_strategy id;
-
+ extern id_strategy id;
}
#endif
Modified: trunk/src/strategies/patterns/scope.hh
===================================================================
--- trunk/src/strategies/patterns/scope.hh 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/strategies/patterns/scope.hh 2010-12-06 17:19:03 UTC (rev 147)
@@ -39,15 +39,17 @@
<typename strategy_model<Strat, U>::model>::check
require;
- try {
- v.push();
- typename strategy_model<Strat, U>::model::output ret = s(t);
- v.pop();
- return ret;
- } catch (...) {
- v.pop();
- throw ;
- }
+ struct onexit {
+ const T& v;
+ onexit(const T& v): v(v) {
+ v.push();
+ }
+ ~onexit() {
+ v.pop();
+ }
+ };
+ onexit oe(v);
+ return s(t);
}
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|