str-concrete.str 2.45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module str-concrete

imports
  lib
  xtc-lib
  Sdf2
  AsFix

rules

	Init: a -> a
            where rules(ToTerms: () -> [])
		; rules(Variables: () -> [])

	GetSorts: 'sorts(s) -> 'sorts(s)
	    where < map(GetSort) > s

	// fmt ex: "|$S$[ $T$ ]c++|" or "$S$|[ $T$ ]|" or "|$S${ $T$ }|"
	// var ex: "SPECS-$S$"

	GetSort: sort(s) -> sort(s)
  	    where
    		  < get-config > "--fmt"	 => fmt
		; < string-tokenize >([36], fmt) => tok-l
		; < map(try( (?"S"; !s) + (?"T"; !s) )) > tok-l => tok-l2
		; < concat-strings > tok-l2	 => t
		; !|[ ~t -> StrategoTerm { cons("\"ToTerm\""), prefer } ]| => prod1
		; < ToTerms > () => tt
		; rules(ToTerms: () -> [ prod1 | tt ])

31
    		; ((< get-config > "--var") <+ !"$S$") => var
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
		; < string-tokenize >([36], var)    => tok-l3
		; < map(try(?"S"; !s)) > tok-l3     => tok-l4
		; < concat-strings > tok-l4	    => t2
		; < concat-strings >["\"", s, "\""] => quoted-s
		; !|[ ~quoted-s [0-9]* [\']* -> ~t2 { prefer } ]| => prod2
		; < Variables > () => v
		; rules(Variables: () -> [ prod2 | v ])

strategies

  io-str-concrete =
       xtc-io-wrap (fmt-option + var-option + main-option + imports-option, read-from ;
	       // check that -f is given.
               {| ToTerms, Variables:
		  Init
		; bottomup (try (GetSorts))
		; < ToTerms > () => p1*
		; < Variables > () => p2*
    		; (< get-config > "--main" <+ !"Main") => M
    		; < get-config > "--imports" => i*
		; !|[ module M
			imports i*
			exports
			 context-free syntax
			   "\"~\"" StrategoTerm -> Expression {cons("\"FromTerm\""), prefer}
			   p1*
			exports
			 variables
			   p2*
		   ]|
		//; xtc-transform(!"sdf-desugar", pass-verbose)
		; write-to
		|})

    fmt-option =
       ArgOption
         ("-f" + "--fmt",
	  where( <set-config> ("--fmt", <id>) ),
	  !"-f str | --fmt str     Use this format string (ex : '\"|$S$[\" $T$ \"]c++|\"')")

    var-option =
       ArgOption
         ("-v" + "--var",
	  where( <set-config> ("--var", <id>) ),
	  !"-v str | --var str     Use this format string (ex : 'SPECS-$S$')")

    main-option =
       ArgOption
         ("-m" + "--main",
	  where( <set-config> ("--main", <id>) ),
	  !"-m mod | --main mod    Specify module name for output sdf definition [Main]")

    imports-option' = <get-config> "--imports" <+ ![]

    imports-option =
       ArgOption
         ("-p" + "--imports",
	  where( <set-config> ("--imports", [ <id> | <imports-option'> ])),
	  !"-p mod | --imports mod Specify a module to imports in the output sdf definition")