Commit e593d773 authored by david_v's avatar david_v
Browse files

from Valentin David <valentin@lrde.epita.fr>

	* src/genfilters/genfilters.str: New. Generate convertion programs.
	* src/genfilters/Makefile.am: New.

	* src/lib/Makefile.am, src/lib/det-lib.str: New.

	* src/Makefile.am (SUBDIRS): Update.

	* src/detgen/Makefile.am (STRINCLUDES): Update.

	* src/detgen/detgen.str: Move reusable parts into det-lib.

	* src/xtc/gen-filters.str: New.
	* src/xtc/Makefile.am: Update.

	* test/gen.sdf.ref, test/genfilters.test, test/detgen.test,
	* test/d.str.ref, test/f.str.ref, test/Makefile.am, test/Test.ppdef:
	New.

	* Makefile.am (SUBDIRS): Update.
	* configure.ac: Update.
parent e55ea90e
2004-03-19 Valentin David <valentin@lrde.epita.fr>
* src/genfilters/genfilters.str: New. Generate convertion programs.
* src/genfilters/Makefile.am: New.
* src/lib/Makefile.am, src/lib/det-lib.str: New.
* src/Makefile.am (SUBDIRS): Update.
* src/detgen/Makefile.am (STRINCLUDES): Update.
* src/detgen/detgen.str: Move reusable parts into det-lib.
* src/xtc/gen-filters.str: New.
* src/xtc/Makefile.am: Update.
* test/gen.sdf.ref, test/genfilters.test, test/detgen.test,
* test/d.str.ref, test/f.str.ref, test/Makefile.am, test/Test.ppdef:
New.
* Makefile.am (SUBDIRS): Update.
* configure.ac: Update.
2004-03-11 Valentin David <valentin@lrde.epita.fr>
* TODO: New.
......
include $(top_srcdir)/config/Makefile.xt
ACLOCAL_AMFLAGS = -I config
SUBDIRS = config lib src
SUBDIRS = config lib src test
BOOTCLEAN_SUBDIRS = $(SUBDIRS)
EXTRA_DIST = bootstrap ChangeLog
XTC_IMPORT = $(BOXEDSDF)/share/boxedsdf/XTC
......@@ -51,7 +51,10 @@ AC_CONFIG_FILES([Makefile
src/Makefile
src/syn/Makefile
src/pp/Makefile
src/lib/Makefile
src/detgen/Makefile
src/genfilters/Makefile
src/det2sdf/Makefile
src/xtc/Makefile])
src/xtc/Makefile
test/Makefile])
AC_OUTPUT
......@@ -3,7 +3,9 @@ include $(top_srcdir)/config/Makefile.xt
SUBDIRS = \
syn \
pp \
lib \
detgen \
genfilters \
det2sdf \
xtc
......
......@@ -5,7 +5,8 @@ bin_PROGRAMS = detgen
SCFLAGS = --main $* --verbose 0
STRINCLUDES = -I $(top_builddir)/src/syn \
-I $(ASFIX_TOOLS)/share/asfix-tools \
-I $(top_srcdir)/lib/ppgen
-I $(top_srcdir)/lib/ppgen \
-I $(top_srcdir)/src/lib
BOOTCLEANFILES = detgen.c
CLEANFILES = detgen.c.dep
EXTRA_DIST = detgen.str
/**
* DetGen
* Copyright (C) 2003 LRDE
* Copyright (C) 2003, 2004 LRDE
*
* 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
......@@ -22,93 +22,34 @@
* Author: Valentin David <valentin@lrde.epita.fr>
*/
module gendet
imports lib DetBoxedSdf sdf-2-pp-lib
imports lib DetBoxedSdf sdf-2-pp-lib det-lib
signature
constructors
Import : String -> Option
Begin : String -> Option
End : String -> Option
strategies
/**
* -c/--cxx grammar
* to specify the pp table
*/
import-option =
ArgOption("-m" + "--import"
, where(<set-config> ("-m",<id>)); !Import(<id>)
, !"-m n|--import n Generated module will import n"
)
begin-option =
ArgOption("-b" + "--begin"
, where(<set-config> ("-b",<id>)); !Begin(<id>)
, !"-b s|--begin s Use s as begin markup"
)
end-option =
ArgOption("-e" + "--end"
, where(<set-config> ("-e",<id>)); !End(<id>)
, !"-e s|--end s Use s as end markup"
)
rules
MyNZip2 : (n, [y|ys]) -> ((n, y), (<add> (n, 1), ys))
where <sort(id)> y
MyNZip2 : (n, [y|ys]) -> ((n, y), (n, ys))
where <lit(id)> y
strategies
mynzip0(s) = NZip00; genzip(NZip1, MyNZip2, NZip3, s)
mytake(isn) = mynzip0(id); take-until((isn,id)); map(Snd)
mydrop(isn) = nzip0(id); drop-until((isn,id)); map(Snd)
at-pp(s) = oncetd(BoxedAttr(pplist(s)))
at-cons(s) = oncetd(cons(s))
at-dettag(s1,s2) = oncetd(dettag2(s1,s2))
at-dettag(s) = oncetd(dettag(s))
rules
/**
* :: String -> String
*
* This rule generates a begin tag.
*/
ToBegin : lit -> lit'
where <Beginize> lit
; ToLayout
; double-quote => lit'
/**
* :: String -> String
*
* This rule generates a end tag.
*/
ToEnd : lit -> lit'
where <Endize> lit
; ToLayout
; double-quote => lit'
/**
* :: String -> String
*
* Transform a production to a the coresponding deterministic
* productions.
*/
ToDetProds : prod(a,b,c) -> [prod(a', b, c''),
prod(lit(btag),layout,attrs(reject)),
prod(lit(etag),layout,attrs(reject))]
where <attrs(at-dettag(un-double-quote; ?tag))> c
; <ToBegin> tag => btag
; <ToEnd> tag => etag
where <attrs(one(dettag(id)))> c
; <get-tags> c => (btag, etag)
; <concat> [[lit(btag)], a, [lit(etag)]] => a'
; <attrs(filter(not(dettag(id))))> c => c'
// Try to get the current pp-entry and add the tags.
......@@ -136,20 +77,12 @@ rules
ToDetProds : prod(a,b,c) -> [prod(a', b, c''),
prod(lit(btag),layout,attrs(reject)),
prod(lit(etag),layout,attrs(reject))]
where <attrs(at-dettag(un-double-quote; ?tag,
string-to-int; ?i; dec; ?j; <add> (<id>, 2); ?k))> c
; <ToBegin> tag => btag
; <ToEnd> tag => etag
; <mytake(?j)> a => h
; <mydrop(?j)> a
; take-while(lit(id)) => hl
; <mydrop(?k)> a => t
; <mydrop(?j)> a
; drop-while(lit(id))
; take(!1) => e
; <concat> [h, hl,[lit(btag)], e, [lit(etag)], t] => a'
where <attrs(one(dettag2(id,string-to-int; ?i)))> c
; <get-tags> c => (btag, etag)
; <explode-rule> prod(a, b, c) => (begin, elt, end)
; <concat> [begin, [lit(btag)], elt, [lit(etag)], end] => a'
; <attrs(filter(not(dettag2(id, id))))> c => c'
; ((<prod(id,id,at-pp(?pl))> prod(a, b, c')
; ((<at-pp(?pl)> c'
; !pl
; rec x([Pathed(None,id)|id]; Hd <+ \ [_|l] -> l \; x)
)
......@@ -169,56 +102,18 @@ rules
strategies
/**
* This strategy try to find how to write comments.
*/
find-layout = where(
collect(prod([lit(un-double-quote),id,lit(un-double-quote)],layout,id))
; (Hd <+ !"No good comments in this grammar"; debug; giving-up)
; ?prod([lit(begin),_,lit(end)],_,_)
; rules(ToLayout : lit -> lit'
where <concat-strings> [begin, lit, end] => lit'))
/**
* Get all the production to generate corresponding deterministic
* production.
*/
det-gen-prods = find-layout
; collect(prod(id,id,attrs(at-dettag(id) <+ at-dettag(id,id))))
det-gen-prods =
collect(prod(id,id,attrs(at-dettag(id) <+ at-dettag(id,id))))
; map(ToDetProds)
; concat
; !Module("Det",[],[Exports(context-free-syntax(<id>))])
cut-string =
explode-string
; ?s
; drop-until(37)
; Tl
; ?s2
; !s
; take-until(37)
; !(<implode-string>, <implode-string> s2)
detgen = iowrap(
(option-defined(Begin(?b))
; where(
!b
; cut-string => (bb,eb)
; rules(Beginize : l -> <concat-strings> [bb, l, eb])
)
<+
rules(Beginize : l -> <concat-strings> ["[", l, "]"])
,id)
; (option-defined(End(?e))
; where(
!e
; cut-string => (be,ee)
; rules(Endize : l -> <concat-strings> [be, l, ee])
)
<+ rules(Endize : l -> <concat-strings> ["[", l, "]"])
,id)
; (id, det-gen-prods)
; try((option-defined(Import(?imp)), id)
; (id,Module(?name; <concat-strings> [name, imp]
,![Imports([imp])],id)))
, import-option + begin-option + end-option)
detgen = det-iowrap((id, det-gen-prods)
; try((option-defined(Import(?imp)), id)
; (id,Module(?name; <concat-strings> [name, imp]
,![Imports([imp])],id))), import-option)
include $(top_srcdir)/config/Makefile.xt
-include genfilters.c.dep
bin_PROGRAMS = genfilters
SCFLAGS = --main $* --verbose 0
STRINCLUDES = -I $(top_builddir)/src/syn \
-I $(ASFIX_TOOLS)/share/asfix-tools \
-I $(top_srcdir)/src/lib
BOOTCLEANFILES = genfilters.c
CLEANFILES = genfilters.c.dep
EXTRA_DIST = genfilters.str
/**
* DetGen
* Copyright (C) 2004 LRDE
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Valentin David <valentin@lrde.epita.fr>
*/
module genfilters
imports lib det-lib Stratego asfix xtc-lib
signature
constructors
Det2NDet : Term
NDet2Det : Term
Ast : Term
Name : String -> Term
rules
Strategoize : [] -> List([])
Strategoize : l@[_|_] -> List(<map(strategoizerec)> l)
Strategoize : s -> Str(s)
where <is-string> s
Strategoize : i -> Int(<int-to-string> i)
where <is-int> i
Strategoize : v@Var(_) -> v
Strategoize : Wld -> Wld
StrategoizeElse : n#(p) -> Op(n, <map(strategoizerec)> p)
strategies
way-option =
Option("-f" + "--fromdet"
, where(<set-config> ("-f", ())); !Det2NDet
, !"-f|--fromdet Rules will remove deterministic markups."
)
+ Option("-d" + "--todet"
, where(<set-config> ("-t", ())); !NDet2Det
, !"-d|--todet Rules will add deterministic markups."
)
name-option =
ArgOption("-m" + "--name"
, where(<set-config> ("-m",<id>)); !Name(<id>)
, !"-m n|--name n Generated module with name n"
)
cfize = try((sort(id) <+ opt(id) <+ iter(id) <+ iter-sep(id, id)
<+ iter-star(id) <+ iter-star-sep(id, id))
; !cf(<id>))
strategoizerec = Strategoize <+ StrategoizeElse
strategoize = topdown(try(prod(map(cfize), cfize, id)))
; strategoizerec
add-layout = prod(rec x([] <+ [id] <+ [id|![opt(layout)|<x>]]), id, id)
empty-layout = !appl(prod([], cf(opt(layout)), no-attrs), [])
build-tag = !appl(prod(<explode-string; map(!char-class([<id>]))>,
lit(<id>), no-attrs), <explode-string>)
make-ndet2det =
?prod(a, b, c)
; <get-tags> c => (btag, etag)
; <map(!Var(<new>))> a => vars
; !Var(<new>) => Attr
; !appl(prod(a, b, Attr), vars) => from
; !appl(prod(<concat> [[lit(btag)], [opt(layout)], a,
[opt(layout)], [lit(etag)]],
b, Attr),
<concat> [[<build-tag> etag], [<empty-layout>], vars,
[<empty-layout>], [<build-tag> etag]]) => to
; !(from, to)
make-ndet2det =
?(prod(a, b, c), begin, elt, end)
; <get-tags> c => (btag, etag)
; <map(!Var(<new>))> begin => bvars
; <map(!Var(<new>))> end => evars
; !Var(<new>) => eltvar
; !Var(<new>) => Attr
; !appl(prod(a, b, Attr),
<concat> [bvars, [eltvar], evars]) => from
; !appl(prod(<concat> [begin, [lit(btag)], [opt(layout)], [elt],
[opt(layout)], [lit(etag)], end],
b, Attr),
<concat> [bvars,
[<build-tag> etag], [<empty-layout>],
[eltvar],
[<empty-layout>], [<build-tag> etag],
evars]) => to
; !(from, to)
make-det2ndet =
?prod(a, b, c)
; <get-tags> c => (btag, etag)
; <map(!Var(<new>))> a => vars
; !Var(<new>) => Attr
; !appl(prod(a, b, Attr), vars) => to
; !appl(prod(<concat> [[lit(btag)], [opt(layout)], a,
[opt(layout)], [lit(etag)]],
b, Attr),
<concat> [[Wld], [Wld], vars, [Wld], [Wld]]) => from
; !(from, to)
make-det2ndet =
?(prod(a, b, c), begin, elt, end)
; <get-tags> c => (btag, etag)
; <map(!Var(<new>))> begin => bvars
; <map(!Var(<new>))> end => evars
; !Var(<new>) => eltvar
; !Var(<new>) => Attr
; !appl(prod(a, b, Attr),
<concat> [bvars, [eltvar], evars]) => to
; !appl(prod(<concat> [begin, [lit(btag)], [opt(layout)], [elt],
[opt(layout)], [lit(etag)], end],
b, Attr),
<concat> [bvars, [Wld], [Wld],
[eltvar], [Wld], [Wld], evars]) => from
; !(from, to)
torule(make-rules) =
prod(id,id, at-dettag(id))
; add-layout
; ?prod(a, b, c)
; make-rules => (from, to)
; !RDefNoArgs("Tr",RuleNoCond(<strategoize> from,
<strategoize> to))
torule(make-rules) =
prod(id,id, at-dettag(id,id))
; add-layout
; where(explode-rule => (begin, elt, end))
; !(<id>, begin, elt, end)
; make-rules => (from, to)
; !RDefNoArgs("Tr",RuleNoCond(<strategoize> from,
<strategoize> to))
module-name = <get-config> "-m" <+ !"Convert"
gen(make-rules) =
collect(prod(id,id,attrs(at-dettag(id) <+ at-dettag(id,id))))
; map(torule(make-rules))
; !Module(<module-name>,
[Imports(["lib","asfix"]),
Rules(<id>),
Strategies([SDefNoArgs(<module-name>,
Call(SVar("iowrap"),
[Call(SVar("topdown"),
[Call(SVar("try"),
[CallNoArgs(SVar("Tr"))])
])
]
)
)])
])
genfilters = det-iowrap(
(not(option-defined(Det2NDet) <+ option-defined(NDet2Det))
, id)
<
<debug> "You must pass a -d or a -f option"
; fail
+ ( (option-defined(Det2NDet), gen(make-det2ndet))
<+ (option-defined(NDet2Det), gen(make-ndet2det)))
, way-option + name-option)
include $(top_srcdir)/config/Makefile.xt
EXTRA_DIST = det-lib.str
/**
* DetGen
* Copyright (C) 2004 LRDE
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Valentin David <valentin@lrde.epita.fr>
*/
module det-lib
imports lib DetBoxedSdf asfix
signature
constructors
Begin : String -> Option
End : String -> Option
strategies
begin-option =
ArgOption("-b" + "--begin"
, where(<set-config> ("-b",<id>)); !Begin(<id>)
, !"-b s|--begin s Use s as begin markup"
)
end-option =
ArgOption("-e" + "--end"
, where(<set-config> ("-e",<id>)); !End(<id>)
, !"-e s|--end s Use s as end markup"
)
rules
MyNZip2 : (n, [y|ys]) -> ((n, y), (<add> (n, 1), ys))
where <sort(id)> y
<+ <opt(not(layout))> y
<+ <iter(id)> y
<+ <iter-sep(id, id)> y
<+ <iter-star(id)> y
<+ <iter-star-sep(id, id)> y
MyNZip2 : (n, [y|ys]) -> ((n, y), (n, ys))
where <lit(id)> y
<+ <opt(layout)> y
strategies
mynzip0(s) = NZip00; genzip(NZip1, MyNZip2, NZip3, s)
mytake(isn) = mynzip0(id); take-until((isn,id)); map(Snd)
mydrop(isn) = mynzip0(id); drop-until((isn,id)); map(Snd)
at-pp(s) = oncetd(BoxedAttr(pplist(s)))
at-cons(s) = oncetd(cons(s))
at-dettag(s1,s2) = oncetd(dettag2(s1,s2))
at-dettag(s) = oncetd(dettag(s))
rules
/**
* :: String -> String
*
* This rule generates a begin tag.
*/
ToBegin : lit -> lit'
where <Beginize> lit
; ToLayout
; double-quote => lit'
/**
* :: String -> String
*
* This rule generates a end tag.
*/
ToEnd : lit -> lit'
where <Endize> lit
; ToLayout
; double-quote => lit'
strategies
explode-rule = ?prod(a, b, c)
; <attrs(at-dettag(id, string-to-int; ?num))> c
; <dec> num => skip
; <inc> num => tail
; <mytake(?skip)> a
; take-until(lit(id) <+ opt(layout)) => h
; <mydrop(?skip)> a
; take-while(lit(id) <+ opt(layout)) => h'
; <mydrop(?skip)> a
; drop-while(lit(id) <+ opt(layout))
; take(!1) => elt
; <mydrop(?num)> a => end
; !(<concat> [h, h'], elt, end)
get-tags = attrs(at-dettag(un-double-quote; ?tag))
; !tag
; !(<ToBegin>, <ToEnd>)
get-tags = attrs(at-dettag(un-double-quote; ?tag, id))
; !tag
; !(<ToBegin>, <ToEnd>)
/**
* This strategy try to find how to write comments.
*/
find-layout = where(
collect(prod([lit(un-double-quote),id,lit(un-double-quote)],
layout,id))
; (Hd <+ !"No good comments in this grammar"; debug; giving-up)
; ?prod([lit(begin),_,lit(end)],_,_)
; rules(ToLayout : lit -> lit'
where <concat-strings> [begin, lit, end] => lit'))
cut-string =
explode-string
; ?s
; drop-until(37)
; Tl
; ?s2
; !s
; take-until(37)
; !(<implode-string>, <implode-string> s2)
det-iowrap(process, options)
= iowrap(
(option-defined(Begin(?b))
; where(
!b
; cut-string => (bb,eb)
; rules(Beginize : l -> <concat-strings> [bb, l, eb])
)
<+
rules(Beginize : l -> <concat-strings> ["[", l, "]"])
,id)
; (option-defined(End(?e))
; where(
!e
; cut-string => (be,ee)
; rules(Endize : l -> <concat-strings> [be, l, ee])
)
<+ rules(Endize : l -> <concat-strings> ["[", l, "]"])
,id)
; (id, find-layout)
; process
, options + begin-option + end-option)
......@@ -3,14 +3,19 @@ include $(top_srcdir)/config/Makefile.xt
-include parse-detboxedsdf-module.c.dep
-include parse-detboxedsdf-definition.c.dep
-include pp-detboxedsdf.c.dep
-include gen-filters.c.dep
bin_PROGRAMS = det-gen parse-detboxedsdf-module \
parse-detboxedsdf-definition pp-detboxedsdf
parse-detboxedsdf-definition pp-detboxedsdf \
gen-filters
SCFLAGS = --main $* --verbose 0
STRINCLUDES = -I $(XTC)/share/xtc
BOOTCLEANFILES = det-gen.c parse-detboxedsdf-module.c \
parse-detboxedsdf-definition.c pp-detboxedsdf.c
parse-detboxedsdf-definition.c pp-detboxedsdf.c \
gen-filters.c
CLEANFILES = det-gen.c.dep parse-detboxedsdf-module.c.dep \
parse-detboxedsdf-definition.c.dep pp-detboxedsdf.c.dep
parse-detboxedsdf-definition.c.dep pp-detboxedsdf.c.dep \
gen-filters.c.dep
EXTRA_DIST = det-gen.str parse-detboxedsdf-module.str \