• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  Copyright (C) Vladimir Prus 2002-2005.
2
3#  Use, modification and distribution is subject to the Boost Software
4#  License Version 1.0. (See accompanying file LICENSE_1_0.txt or
5#  http://www.boost.org/LICENSE_1_0.txt)
6
7#  This module implements support for Whale/Dolphin/WD parser/lexer tools.
8#  See http://www.cs.queensu.ca/home/okhotin/whale/ for details.
9#
10#  There are three interesting target types:
11#  - WHL (the parser sources), that are converted to CPP and H
12#  - DLP (the lexer sources), that are converted to CPP and H
13#  - WD (combined parser/lexer sources), that are converted to WHL + DLP
14
15import type ;
16import generators ;
17import path ;
18import "class" : new ;
19import errors ;
20
21rule init ( path # path the Whale/Dolphin/WD binaries
22          )
23{
24    if $(.configured) && $(.path) != $(path)
25    {
26        errors.user-error "Attempt to reconfigure Whale support" :
27          "Previously configured with path \"$(.path:E=<empty>)\"" :
28          "Now configuring with path \"$(path:E=<empty>)\"" ;
29
30    }
31    .configured = true ;
32    .path = $(path) ;
33
34    .whale = [ path.join $(path) whale ] ;
35    .dolphin = [ path.join $(path) dolphin ] ;
36    .wd = [ path.join $(path) wd ] ;
37}
38
39
40# Declare the types.
41type.register WHL : whl ;
42type.register DLP : dlp ;
43type.register WHL_LR0 : lr0 ;
44type.register WD : wd ;
45
46# Declare standard generators.
47generators.register-standard whale.whale : WHL : CPP H H(%_symbols) ;
48generators.register-standard whale.dolphin : DLP : CPP H ;
49generators.register-standard whale.wd : WD : WHL(%_parser) DLP(%_lexer) ;
50
51# The conversions defines above a ambiguious when we generated CPP from WD.
52# We can either go via WHL type, or via DLP type.
53# The following custom generator handles this by running both conversions.
54
55class wd-to-cpp : generator
56{
57    rule __init__ ( * : * : * )
58    {
59        generator.__init__ $(1) : $(2) : $(3) ;
60    }
61
62    rule run ( project name ? : property-set : source * )
63    {
64        if ! $(source[2])
65        {
66            local new-sources ;
67            if ! [ $(source).type ] in WHL DLP
68            {
69                local r1 = [ generators.construct $(project) $(name)
70                  : WHL : $(property-set) : $(source) ] ;
71                local r2 = [ generators.construct $(project) $(name)
72                  : DLP : $(property-set) : $(source) ] ;
73
74                new-sources = [ sequence.unique $(r1[2-]) $(r2[2-]) ] ;
75            }
76            else
77            {
78                new-sources = $(source) ;
79            }
80
81            local result ;
82            for local i in $(new-sources)
83            {
84                local t = [ generators.construct $(project) $(name) : CPP
85                  : $(property-set) : $(i) ] ;
86                result += $(t[2-]) ;
87            }
88            return $(result) ;
89        }
90    }
91
92}
93
94
95generators.override whale.wd-to-cpp : whale.whale ;
96generators.override whale.wd-to-cpp : whale.dolphin ;
97
98
99generators.register [ new wd-to-cpp whale.wd-to-cpp : : CPP ] ;
100
101
102actions whale
103{
104    $(.whale) -d $(<[1]:D) $(>)
105}
106
107actions dolphin
108{
109    $(.dolphin) -d $(<[1]:D) $(>)
110}
111
112actions wd
113{
114    $(.wd) -d $(<[1]:D) -g $(>)
115}
116
117