blob: 9335ff0c0c8447bfd97a65b2c66b04ddbda730a3 (
plain)
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
31
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# Copyright (C) Vladimir Prus 2002-2005.
# Use, modification and distribution is subject to the Boost Software
# License Version 1.0. (See accompanying file LICENSE_1_0.txt or
# http://www.boost.org/LICENSE_1_0.txt)
# This module implements support for Whale/Dolphin/WD parser/lexer tools.
# See http://www.cs.queensu.ca/home/okhotin/whale/ for details.
#
# There are three interesting target types:
# - WHL (the parser sources), that are converted to CPP and H
# - DLP (the lexer sources), that are converted to CPP and H
# - WD (combined parser/lexer sources), that are converted to WHL + DLP
import type ;
import generators ;
import path ;
import "class" : new ;
import errors ;
rule init ( path # path the Whale/Dolphin/WD binaries
)
{
if $(.configured) && $(.path) != $(path)
{
errors.user-error "Attempt to reconfigure Whale support" :
"Previously configured with path \"$(.path:E=<empty>)\"" :
"Now configuring with path \"$(path:E=<empty>)\"" ;
}
.configured = true ;
.path = $(path) ;
.whale = [ path.join $(path) whale ] ;
.dolphin = [ path.join $(path) dolphin ] ;
.wd = [ path.join $(path) wd ] ;
}
# Declare the types.
type.register WHL : whl ;
type.register DLP : dlp ;
type.register WHL_LR0 : lr0 ;
type.register WD : wd ;
# Declare standard generators.
generators.register-standard whale.whale : WHL : CPP H H(%_symbols) ;
generators.register-standard whale.dolphin : DLP : CPP H ;
generators.register-standard whale.wd : WD : WHL(%_parser) DLP(%_lexer) ;
# The conversions defines above a ambiguious when we generated CPP from WD.
# We can either go via WHL type, or via DLP type.
# The following custom generator handles this by running both conversions.
class wd-to-cpp : generator
{
rule __init__ ( * : * : * )
{
generator.__init__ $(1) : $(2) : $(3) ;
}
rule run ( project name ? : property-set : source * )
{
if ! $(source[2])
{
local new-sources ;
if ! [ $(source).type ] in WHL DLP
{
local r1 = [ generators.construct $(project) $(name)
: WHL : $(property-set) : $(source) ] ;
local r2 = [ generators.construct $(project) $(name)
: DLP : $(property-set) : $(source) ] ;
new-sources = [ sequence.unique $(r1[2-]) $(r2[2-]) ] ;
}
else
{
new-sources = $(source) ;
}
local result ;
for local i in $(new-sources)
{
local t = [ generators.construct $(project) $(name) : CPP
: $(property-set) : $(i) ] ;
result += $(t[2-]) ;
}
return $(result) ;
}
}
}
generators.override whale.wd-to-cpp : whale.whale ;
generators.override whale.wd-to-cpp : whale.dolphin ;
generators.register [ new wd-to-cpp whale.wd-to-cpp : : CPP ] ;
actions whale
{
$(.whale) -d $(<[1]:D) $(>)
}
actions dolphin
{
$(.dolphin) -d $(<[1]:D) $(>)
}
actions wd
{
$(.wd) -d $(<[1]:D) -g $(>)
}
|