URL:
https://svn.lrde.epita.fr/svn/scool/branches/scool-ng
ChangeLog:
2008-09-24 Maxime van Noppen <yabo(a)lrde.epita.fr>
Work on classes
* concrete-syn/concrete-syn.sdf: Add concrete syntax for classes.
* scl-syn/Class.sdf: Fix typo in grammar
* scoolt/Declaration.str: Handle the ClassDefinition constructor.
* scoolt/Function.str: Cleanup and document code.
concrete-syn/concrete-syn.sdf | 1 +
scl-syn/Class.sdf | 2 +-
scoolt/Declaration.str | 20 ++++++++++++++++----
scoolt/Function.str | 16 +++++++++++++---
4 files changed, 31 insertions(+), 8 deletions(-)
Index: branches/scool-ng/src/scoolt/Declaration.str
===================================================================
--- branches/scool-ng/src/scoolt/Declaration.str (revision 98)
+++ branches/scool-ng/src/scoolt/Declaration.str (revision 99)
@@ -1,6 +1,6 @@
module Declaration
-imports libstratego-lib Cxx Scool Type Expression Function
+imports libstratego-lib Cxx Scool Type Expression Function Class
rules
@@ -56,6 +56,18 @@
; <TypeToCxx> <GetReturnType> fun_type => cxx_ret_type
; <ParametersToCxx> <GetParameters> fun_type => cxx_params
; <ArgumentsToCxx> <GetArguments> fun_type => cxx_args
- // body can either be a list of declarations and/or function statements,
- // or be a single expression (because of the one-line function sugar)
- ; <map (DeclarationToCxx <+ FunctionStatementToCxx) <+
FunctionStatementToCxx> body => cxx_body
+ ; <FunctionBodyToCxx> body => cxx_body
+
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // Class //
+ ////////////////////////////////////////////////////////////////////////////////
+
+ DeclarationToCxx:
+ ClassDefinition(None, idf, wclause, ClassBlock(body)) -> CxxClassDecl(cxx_params,
cxx_idf, [], cxx_body)
+ where
+ !(CxxType("typename"), "T") => cxx_params
+ ; <IdentifierToCxx> idf => cxx_idf
+ ; <?None> wclause
+ ; <ClassBodyToCxx> body => cxx_body
+
Index: branches/scool-ng/src/scoolt/Function.str
===================================================================
--- branches/scool-ng/src/scoolt/Function.str (revision 98)
+++ branches/scool-ng/src/scoolt/Function.str (revision 99)
@@ -21,7 +21,7 @@
- // Convert parameters (templates)
+ // Translate parameters (templates)
// Parameters in function declarations
ParametersToCxx:
@@ -46,7 +46,7 @@
- // Convert arguments
+ // Translate arguments
// Arguments in function declarations
ArgumentsToCxx:
@@ -64,8 +64,17 @@
Arguments(args) -> <map (ExpressionToCxx)> args
+ // Translate function body
+
+ FunctionBodyToCxx:
+ body -> cxx_body
+ where
+ // body can either be a list of declarations and/or function statements,
+ // or be a single expression (because of the one-line function sugar)
+ <map (DeclarationToCxx <+ FunctionStatementToCxx) <+
FunctionStatementToCxx> body => cxx_body
- // Convert function statements
+
+ // Translate function statements
FunctionStatementToCxx:
ReturnStatement(exp) -> CxxExpStm(CxxKeyword("return", cxx_exp))
@@ -81,3 +90,4 @@
exp -> [CxxExpStm(CxxKeyword("return", cxx_exp))]
where
<ExpressionToCxx> exp => cxx_exp
+
Index: branches/scool-ng/src/scl-syn/Class.sdf
===================================================================
--- branches/scool-ng/src/scl-syn/Class.sdf (revision 98)
+++ branches/scool-ng/src/scl-syn/Class.sdf (revision 99)
@@ -9,7 +9,7 @@
context-free syntax
"{" AccessBlock* "}" -> ClassBlock
{cons("ClassBlock")}
- AccessModifier "{" Declaration* "}" -> AccessBlock
{cons("Accessblock")}
+ AccessModifier "{" Declaration* "}" -> AccessBlock
{cons("AccessBlock")}
"public" -> AccessModifier {cons("Public")}
"protected" -> AccessModifier {cons("Protected")}
Index: branches/scool-ng/src/concrete-syn/concrete-syn.sdf
===================================================================
--- branches/scool-ng/src/concrete-syn/concrete-syn.sdf (revision 98)
+++ branches/scool-ng/src/concrete-syn/concrete-syn.sdf (revision 99)
@@ -15,6 +15,7 @@
"~" StrategoTerm -> SimpleType {cons("FromTerm"), prefer}
"~ftype:" StrategoTerm -> FunctionType {cons("FromTerm"),
prefer}
"~fbody:" StrategoTerm -> FunctionStatement* {cons("FromTerm"),
prefer}
+ "~cbody:" StrategoTerm -> AccessStatement* {cons("FromTerm"),
prefer}
"~exp:" StrategoTerm -> Expression {cons("FromTerm"), prefer}
--
\__/ \__/
(00) Maxime `yabo` van Noppen (00)
___) \ Epita 2009 / (___
(_____/ \_____)