# Copyright 2017 Google Inc.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import 'util/byte.grm' as b;
import 'en/verbalizer/lexical_map.grm' as l;
import 'en/verbalizer/numbers.grm' as n;

card = n.CARDINAL_NUMBERS;

__currency__ = StringFile['en/verbalizer/money.tsv'];

d = b.kDigit;
D = d - "0";

cents = ((n.D["0"] | D) d) @ card;

# Only dollar for the verbalizer tests for English. Will need to add other
# currencies.
usd_maj = Project["usd_maj" @ __currency__, 'output'];
usd_min = Project["usd_min" @ __currency__, 'output'];
and = " @@MONEY_AND@@ " | " ";

dollar1 =
  n.D["$"] card n.I[" " usd_maj] n.I[and] n.D["."] cents n.I[" " usd_min]
;

dollar2 = n.D["$"] card n.I[" " usd_maj] n.D["."] n.D["00"];

dollar3 = n.D["$"] card n.I[" " usd_maj];

dollar = Optimize[dollar1 | dollar2 | dollar3];

export MONEY = Optimize[dollar @ l.LEXICAL_MAP];
