Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #98 from davidmorgan/update-from-g3
Browse files Browse the repository at this point in the history
Update from google3
  • Loading branch information
davidmorgan authored Apr 7, 2020
2 parents 8a5e883 + 843232e commit 7601677
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 54 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.17.10
* Update petitparser dependency.

## 0.17.9
* Fix pub complaint trying to precompile a library file in bin by moving that file to lib/src.

Expand Down
100 changes: 52 additions & 48 deletions lib/src/icu_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,68 +14,72 @@ import 'package:petitparser/petitparser.dart';
/// The "parse" method will return a Success or Failure object which responds
/// to "value".
class IcuParser {
get openCurly => char("{");

get closeCurly => char("}");
get quotedCurly => (string("'{'") | string("'}'")).map((x) => x[1]);

get icuEscapedText => quotedCurly | twoSingleQuotes;
get curly => (openCurly | closeCurly);
get notAllowedInIcuText => curly | char("<");
get icuText => notAllowedInIcuText.neg();
get notAllowedInNormalText => char("{");
get normalText => notAllowedInNormalText.neg();
get messageText => (icuEscapedText | icuText).plus().map((x) => x.join());
get nonIcuMessageText => normalText.plus().map((x) => x.join());
get twoSingleQuotes => string("''").map((x) => "'");
get number => digit().plus().flatten().trim().map(int.parse);
get id => (letter() & (word() | char("_")).star()).flatten().trim();
get comma => char(",").trim();
Parser get openCurly => char('{');

Parser get closeCurly => char('}');
Parser get quotedCurly => (string("'{'") | string("'}'")).map((x) => x[1]);

Parser get icuEscapedText => quotedCurly | twoSingleQuotes;
Parser get curly => (openCurly | closeCurly);
Parser get notAllowedInIcuText => curly | char('<');
Parser get icuText => notAllowedInIcuText.neg();
Parser get notAllowedInNormalText => char('{');
Parser get normalText => notAllowedInNormalText.neg();
Parser get messageText =>
(icuEscapedText | icuText).plus().map((x) => x.join());
Parser get nonIcuMessageText => normalText.plus().map((x) => x.join());
Parser get twoSingleQuotes => string("''").map((x) => "'");
Parser get number => digit().plus().flatten().trim().map(int.parse);
Parser get id => (letter() & (word() | char('_')).star()).flatten().trim();
Parser get comma => char(',').trim();

/// Given a list of possible keywords, return a rule that accepts any of them.
/// e.g., given ["male", "female", "other"], accept any of them.
asKeywords(list) => list.map(string).reduce((a, b) => a | b).flatten().trim();
Parser asKeywords(List<String> list) =>
list.map(string).cast<Parser>().reduce((a, b) => a | b).flatten().trim();

get pluralKeyword => asKeywords(
["=0", "=1", "=2", "zero", "one", "two", "few", "many", "other"]);
get genderKeyword => asKeywords(["female", "male", "other"]);
Parser get pluralKeyword => asKeywords(
['=0', '=1', '=2', 'zero', 'one', 'two', 'few', 'many', 'other']);
Parser get genderKeyword => asKeywords(['female', 'male', 'other']);

var interiorText = undefined();

get preface => (openCurly & id & comma).map((values) => values[1]);
Parser get preface => (openCurly & id & comma).map((values) => values[1]);

get pluralLiteral => string("plural");
get pluralClause => (pluralKeyword & openCurly & interiorText & closeCurly)
.trim()
.map((result) => [result[0], result[2]]);
get plural =>
Parser get pluralLiteral => string('plural');
Parser get pluralClause =>
(pluralKeyword & openCurly & interiorText & closeCurly)
.trim()
.map((result) => [result[0], result[2]]);
Parser get plural =>
preface & pluralLiteral & comma & pluralClause.plus() & closeCurly;
get intlPlural =>
plural.map((values) => new Plural.from(values.first, values[3], null));

get selectLiteral => string("select");
get genderClause => (genderKeyword & openCurly & interiorText & closeCurly)
.trim()
.map((result) => [result[0], result[2]]);
get gender =>
Parser get intlPlural =>
plural.map((values) => Plural.from(values.first, values[3], null));

Parser get selectLiteral => string('select');
Parser get genderClause =>
(genderKeyword & openCurly & interiorText & closeCurly)
.trim()
.map((result) => [result[0], result[2]]);
Parser get gender =>
preface & selectLiteral & comma & genderClause.plus() & closeCurly;
get intlGender =>
gender.map((values) => new Gender.from(values.first, values[3], null));
get selectClause =>
Parser get intlGender =>
gender.map((values) => Gender.from(values.first, values[3], null));
Parser get selectClause =>
(id & openCurly & interiorText & closeCurly).map((x) => [x.first, x[2]]);
get generalSelect =>
Parser get generalSelect =>
preface & selectLiteral & comma & selectClause.plus() & closeCurly;
get intlSelect => generalSelect
.map((values) => new Select.from(values.first, values[3], null));
Parser get intlSelect =>
generalSelect.map((values) => Select.from(values.first, values[3], null));

get pluralOrGenderOrSelect => intlPlural | intlGender | intlSelect;
Parser get pluralOrGenderOrSelect => intlPlural | intlGender | intlSelect;

get contents => pluralOrGenderOrSelect | parameter | messageText;
get simpleText => (nonIcuMessageText | parameter | openCurly).plus();
get empty => epsilon().map((_) => '');
Parser get contents => pluralOrGenderOrSelect | parameter | messageText;
Parser get simpleText => (nonIcuMessageText | parameter | openCurly).plus();
Parser get empty => epsilon().map((_) => '');

get parameter => (openCurly & id & closeCurly)
.map((param) => new VariableSubstitution.named(param[1], null));
Parser get parameter => (openCurly & id & closeCurly)
.map((param) => VariableSubstitution.named(param[1], null));

/// The primary entry point for parsing. Accepts a string and produces
/// a parsed representation of it as a Message.
Expand All @@ -87,7 +91,7 @@ class IcuParser {
Parser get nonIcuMessage =>
(simpleText | empty).map((chunk) => Message.from(chunk, null));

get stuff => (pluralOrGenderOrSelect | empty)
Parser get stuff => (pluralOrGenderOrSelect | empty)
.map((chunk) => Message.from(chunk, null));

IcuParser() {
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: intl_translation
version: 0.17.9
version: 0.17.10
author: Dart Team <misc@dartlang.org>
description: >-
Contains code to deal with internationalized/localized messages,
Expand All @@ -8,14 +8,14 @@ description: >-
homepage: https://github.com/dart-lang/intl_translation
environment:
sdk: '>=2.0.0 <3.0.0'
sdk: '>=2.7.0 <3.0.0'

dependencies:
analyzer: '>=0.36.0 <0.40.0'
args: '>=0.12.1 <2.0.0'
dart_style: ^1.0.0
intl: '>=0.15.3 <0.17.0'
path: '>=0.9.0 <2.0.0'
petitparser: '>=1.1.3 < 3.0.0'
petitparser: ^3.0.0
dev_dependencies:
test: ^1.2.0
2 changes: 2 additions & 0 deletions test/message_extraction/embedded_plural_text_after_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@Timeout(const Duration(seconds: 180))

library embedded_plural_text_after_test;

import "failed_extraction_test.dart";
Expand Down
2 changes: 2 additions & 0 deletions test/message_extraction/embedded_plural_text_before_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@Timeout(const Duration(seconds: 180))

library embedded_plural_text_before_test;

import "failed_extraction_test.dart";
Expand Down
2 changes: 2 additions & 0 deletions test/message_extraction/examples_parsing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@Timeout(const Duration(seconds: 180))

/// Test for parsing the examples argument from an Intl.message call. Very
/// minimal so far.
import 'package:test/test.dart';
Expand Down
3 changes: 3 additions & 0 deletions test/message_extraction/failed_extraction_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@Timeout(const Duration(seconds: 180))

library failed_extraction_test;

import "message_extraction_test.dart";
Expand Down
2 changes: 2 additions & 0 deletions test/message_extraction/find_messages_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@Timeout(const Duration(seconds: 180))

import 'package:intl_translation/extract_messages.dart';
import 'package:intl_translation/src/message_rewriter.dart';
import 'package:test/test.dart';
Expand Down
3 changes: 2 additions & 1 deletion test/message_extraction/message_extraction_json_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@Timeout(const Duration(seconds: 180))

/// A test for message extraction and code generation using generated
/// JSON rather than functions
@Timeout(const Duration(seconds: 60))
import 'package:test/test.dart';

import 'message_extraction_test.dart' as main_test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@Timeout(const Duration(seconds: 180))

/// A test for message extraction and code generation not using deferred
/// loading for the generated code.
@Timeout(const Duration(seconds: 60))
library message_extraction_no_deferred_test;

import 'package:test/test.dart';
Expand Down
3 changes: 2 additions & 1 deletion test/message_extraction/message_extraction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@Timeout(const Duration(seconds: 60))
@Timeout(const Duration(seconds: 180))

library message_extraction_test;

import 'package:test/test.dart';
Expand Down
2 changes: 2 additions & 0 deletions test/message_extraction/really_fail_extraction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@Timeout(const Duration(seconds: 180))

library really_fail_extraction_test;

import "failed_extraction_test.dart";
Expand Down

0 comments on commit 7601677

Please sign in to comment.