--- a/testing/geckodriver/Cargo.lock
+++ b/testing/geckodriver/Cargo.lock
@@ -125,17 +125,17 @@ dependencies = [
name = "geckodriver"
version = "0.19.1"
dependencies = [
"chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "mozprofile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mozprofile 0.3.0",
"mozrunner 0.5.0",
"mozversion 0.1.2",
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
"slog 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slog-atomic 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"slog-stdlog 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"slog-stream 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -267,27 +267,26 @@ source = "registry+https://github.com/ru
dependencies = [
"cc 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "mozprofile"
version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "mozrunner"
version = "0.5.0"
dependencies = [
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "mozprofile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mozprofile 0.3.0",
"winreg 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "mozversion"
version = "0.1.2"
dependencies = [
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -679,17 +678,16 @@ dependencies = [
"checksum lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417"
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
"checksum libc 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "5ba3df4dcb460b9dfbd070d41c94c19209620c191b0340b929ce748a2bcd42d2"
"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b"
"checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376"
"checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a"
"checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0"
"checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4"
-"checksum mozprofile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a17b8bbde1dc0fbf1c8b073192d7c6f89baa932173ece7c1447de5e9cc7cd7e"
"checksum msdos_time 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "65ba9d75bcea84e07812618fedf284a64776c2f2ea0cad6bca7f69739695a958"
"checksum num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "a311b77ebdc5dd4cf6449d81e4135d9f0e3b153839ac90e648a8ef538f923525"
"checksum num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "d1452e8b06e448a07f0e6ebb0bb1d92b8890eea63288c0b627331d53514d0fba"
"checksum num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "7485fcc84f85b4ecd0ea527b14189281cf27d60e583ae65ebc9c088b13dffe01"
"checksum num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070"
"checksum num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "514f0d73e64be53ff320680ca671b64fe3fb91da01e1ae2ddc99eb51d453b20d"
"checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356"
"checksum podio 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e5422a1ee1bc57cc47ae717b0137314258138f38fd5f3cea083f43a9725383a0"
--- a/testing/geckodriver/Cargo.toml
+++ b/testing/geckodriver/Cargo.toml
@@ -10,17 +10,17 @@ license = "MPL-2.0"
publish = false
[dependencies]
chrono = "^0.2"
clap = { version = "^2.19", default-features = false, features = ["suggestions", "wrap_help"] }
hyper = "0.10"
lazy_static = "0.1"
log = "0.3"
-mozprofile = "0.3.0"
+mozprofile = { path = "../mozbase/rust/mozprofile" }
mozrunner = { path = "../mozbase/rust/mozrunner" }
mozversion = { path = "../mozbase/rust/mozversion" }
regex = "0.2"
rustc-serialize = "0.3"
slog = "1"
slog-atomic = "0.4"
slog-stdlog = "1"
slog-stream = "1"
--- a/testing/mozbase/rust/mozrunner/Cargo.toml
+++ b/testing/mozbase/rust/mozrunner/Cargo.toml
@@ -3,15 +3,15 @@ name = "mozrunner"
version = "0.5.0"
authors = ["Mozilla Tools and Automation <auto-tools@mozilla.com>"]
description = "Library for starting Firefox binaries."
repository = "https://hg.mozilla.org/mozilla-central/file/tip/testing/mozbase/rust/mozrunner"
license = "MPL-2.0"
[dependencies]
log = "0.3"
-mozprofile = "0.3"
+mozprofile = { path = "../mozprofile" }
[target.'cfg(target_os = "windows")'.dependencies]
winreg = "0.3.5"
[[bin]]
name = "firefox-default-path"
deleted file mode 100644
--- a/third_party/rust/mozprofile/.cargo-checksum.json
+++ /dev/null
@@ -1,1 +0,0 @@
-{"files":{"Cargo.toml":"9efdea9a6a5a92ba613ed754bbd4c7c1737e02f6eb1eee55b1e2a42c07265c18","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","src/lib.rs":"737568246693facce8c453a250b2bd93863364344bc155a7cea858ee5de5958a","src/preferences.rs":"96e6fd609c48f3dcf1c945c7c095d5f33a13fc39f0d7c56a30924a59bd8f54f6","src/prefreader.rs":"84e357411164ebd8b11ab95962a1a5474bc7e79b8f1461f674a2b19868c39ddd","src/profile.rs":"0686a64b55afa928477a72ff1135939e68903305e26f47ddfb65e62409b2ea12"},"package":"1a17b8bbde1dc0fbf1c8b073192d7c6f89baa932173ece7c1447de5e9cc7cd7e"}
\ No newline at end of file
deleted file mode 100644
--- a/third_party/rust/mozprofile/Cargo.toml
+++ /dev/null
@@ -1,10 +0,0 @@
-[package]
-name = "mozprofile"
-version = "0.3.0"
-authors = ["Mozilla Tools and Automation <auto-tools@mozilla.com>"]
-description = "Library for working with Mozilla profiles."
-repository = "https://github.com/jgraham/rust_mozprofile"
-license = "MPL-2.0"
-
-[dependencies]
-tempdir = "0.3.4"
deleted file mode 100644
--- a/third_party/rust/mozprofile/LICENSE
+++ /dev/null
@@ -1,373 +0,0 @@
-Mozilla Public License Version 2.0
-==================================
-
-1. Definitions
---------------
-
-1.1. "Contributor"
- means each individual or legal entity that creates, contributes to
- the creation of, or owns Covered Software.
-
-1.2. "Contributor Version"
- means the combination of the Contributions of others (if any) used
- by a Contributor and that particular Contributor's Contribution.
-
-1.3. "Contribution"
- means Covered Software of a particular Contributor.
-
-1.4. "Covered Software"
- means Source Code Form to which the initial Contributor has attached
- the notice in Exhibit A, the Executable Form of such Source Code
- Form, and Modifications of such Source Code Form, in each case
- including portions thereof.
-
-1.5. "Incompatible With Secondary Licenses"
- means
-
- (a) that the initial Contributor has attached the notice described
- in Exhibit B to the Covered Software; or
-
- (b) that the Covered Software was made available under the terms of
- version 1.1 or earlier of the License, but not also under the
- terms of a Secondary License.
-
-1.6. "Executable Form"
- means any form of the work other than Source Code Form.
-
-1.7. "Larger Work"
- means a work that combines Covered Software with other material, in
- a separate file or files, that is not Covered Software.
-
-1.8. "License"
- means this document.
-
-1.9. "Licensable"
- means having the right to grant, to the maximum extent possible,
- whether at the time of the initial grant or subsequently, any and
- all of the rights conveyed by this License.
-
-1.10. "Modifications"
- means any of the following:
-
- (a) any file in Source Code Form that results from an addition to,
- deletion from, or modification of the contents of Covered
- Software; or
-
- (b) any new file in Source Code Form that contains any Covered
- Software.
-
-1.11. "Patent Claims" of a Contributor
- means any patent claim(s), including without limitation, method,
- process, and apparatus claims, in any patent Licensable by such
- Contributor that would be infringed, but for the grant of the
- License, by the making, using, selling, offering for sale, having
- made, import, or transfer of either its Contributions or its
- Contributor Version.
-
-1.12. "Secondary License"
- means either the GNU General Public License, Version 2.0, the GNU
- Lesser General Public License, Version 2.1, the GNU Affero General
- Public License, Version 3.0, or any later versions of those
- licenses.
-
-1.13. "Source Code Form"
- means the form of the work preferred for making modifications.
-
-1.14. "You" (or "Your")
- means an individual or a legal entity exercising rights under this
- License. For legal entities, "You" includes any entity that
- controls, is controlled by, or is under common control with You. For
- purposes of this definition, "control" means (a) the power, direct
- or indirect, to cause the direction or management of such entity,
- whether by contract or otherwise, or (b) ownership of more than
- fifty percent (50%) of the outstanding shares or beneficial
- ownership of such entity.
-
-2. License Grants and Conditions
---------------------------------
-
-2.1. Grants
-
-Each Contributor hereby grants You a world-wide, royalty-free,
-non-exclusive license:
-
-(a) under intellectual property rights (other than patent or trademark)
- Licensable by such Contributor to use, reproduce, make available,
- modify, display, perform, distribute, and otherwise exploit its
- Contributions, either on an unmodified basis, with Modifications, or
- as part of a Larger Work; and
-
-(b) under Patent Claims of such Contributor to make, use, sell, offer
- for sale, have made, import, and otherwise transfer either its
- Contributions or its Contributor Version.
-
-2.2. Effective Date
-
-The licenses granted in Section 2.1 with respect to any Contribution
-become effective for each Contribution on the date the Contributor first
-distributes such Contribution.
-
-2.3. Limitations on Grant Scope
-
-The licenses granted in this Section 2 are the only rights granted under
-this License. No additional rights or licenses will be implied from the
-distribution or licensing of Covered Software under this License.
-Notwithstanding Section 2.1(b) above, no patent license is granted by a
-Contributor:
-
-(a) for any code that a Contributor has removed from Covered Software;
- or
-
-(b) for infringements caused by: (i) Your and any other third party's
- modifications of Covered Software, or (ii) the combination of its
- Contributions with other software (except as part of its Contributor
- Version); or
-
-(c) under Patent Claims infringed by Covered Software in the absence of
- its Contributions.
-
-This License does not grant any rights in the trademarks, service marks,
-or logos of any Contributor (except as may be necessary to comply with
-the notice requirements in Section 3.4).
-
-2.4. Subsequent Licenses
-
-No Contributor makes additional grants as a result of Your choice to
-distribute the Covered Software under a subsequent version of this
-License (see Section 10.2) or under the terms of a Secondary License (if
-permitted under the terms of Section 3.3).
-
-2.5. Representation
-
-Each Contributor represents that the Contributor believes its
-Contributions are its original creation(s) or it has sufficient rights
-to grant the rights to its Contributions conveyed by this License.
-
-2.6. Fair Use
-
-This License is not intended to limit any rights You have under
-applicable copyright doctrines of fair use, fair dealing, or other
-equivalents.
-
-2.7. Conditions
-
-Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
-in Section 2.1.
-
-3. Responsibilities
--------------------
-
-3.1. Distribution of Source Form
-
-All distribution of Covered Software in Source Code Form, including any
-Modifications that You create or to which You contribute, must be under
-the terms of this License. You must inform recipients that the Source
-Code Form of the Covered Software is governed by the terms of this
-License, and how they can obtain a copy of this License. You may not
-attempt to alter or restrict the recipients' rights in the Source Code
-Form.
-
-3.2. Distribution of Executable Form
-
-If You distribute Covered Software in Executable Form then:
-
-(a) such Covered Software must also be made available in Source Code
- Form, as described in Section 3.1, and You must inform recipients of
- the Executable Form how they can obtain a copy of such Source Code
- Form by reasonable means in a timely manner, at a charge no more
- than the cost of distribution to the recipient; and
-
-(b) You may distribute such Executable Form under the terms of this
- License, or sublicense it under different terms, provided that the
- license for the Executable Form does not attempt to limit or alter
- the recipients' rights in the Source Code Form under this License.
-
-3.3. Distribution of a Larger Work
-
-You may create and distribute a Larger Work under terms of Your choice,
-provided that You also comply with the requirements of this License for
-the Covered Software. If the Larger Work is a combination of Covered
-Software with a work governed by one or more Secondary Licenses, and the
-Covered Software is not Incompatible With Secondary Licenses, this
-License permits You to additionally distribute such Covered Software
-under the terms of such Secondary License(s), so that the recipient of
-the Larger Work may, at their option, further distribute the Covered
-Software under the terms of either this License or such Secondary
-License(s).
-
-3.4. Notices
-
-You may not remove or alter the substance of any license notices
-(including copyright notices, patent notices, disclaimers of warranty,
-or limitations of liability) contained within the Source Code Form of
-the Covered Software, except that You may alter any license notices to
-the extent required to remedy known factual inaccuracies.
-
-3.5. Application of Additional Terms
-
-You may choose to offer, and to charge a fee for, warranty, support,
-indemnity or liability obligations to one or more recipients of Covered
-Software. However, You may do so only on Your own behalf, and not on
-behalf of any Contributor. You must make it absolutely clear that any
-such warranty, support, indemnity, or liability obligation is offered by
-You alone, and You hereby agree to indemnify every Contributor for any
-liability incurred by such Contributor as a result of warranty, support,
-indemnity or liability terms You offer. You may include additional
-disclaimers of warranty and limitations of liability specific to any
-jurisdiction.
-
-4. Inability to Comply Due to Statute or Regulation
----------------------------------------------------
-
-If it is impossible for You to comply with any of the terms of this
-License with respect to some or all of the Covered Software due to
-statute, judicial order, or regulation then You must: (a) comply with
-the terms of this License to the maximum extent possible; and (b)
-describe the limitations and the code they affect. Such description must
-be placed in a text file included with all distributions of the Covered
-Software under this License. Except to the extent prohibited by statute
-or regulation, such description must be sufficiently detailed for a
-recipient of ordinary skill to be able to understand it.
-
-5. Termination
---------------
-
-5.1. The rights granted under this License will terminate automatically
-if You fail to comply with any of its terms. However, if You become
-compliant, then the rights granted under this License from a particular
-Contributor are reinstated (a) provisionally, unless and until such
-Contributor explicitly and finally terminates Your grants, and (b) on an
-ongoing basis, if such Contributor fails to notify You of the
-non-compliance by some reasonable means prior to 60 days after You have
-come back into compliance. Moreover, Your grants from a particular
-Contributor are reinstated on an ongoing basis if such Contributor
-notifies You of the non-compliance by some reasonable means, this is the
-first time You have received notice of non-compliance with this License
-from such Contributor, and You become compliant prior to 30 days after
-Your receipt of the notice.
-
-5.2. If You initiate litigation against any entity by asserting a patent
-infringement claim (excluding declaratory judgment actions,
-counter-claims, and cross-claims) alleging that a Contributor Version
-directly or indirectly infringes any patent, then the rights granted to
-You by any and all Contributors for the Covered Software under Section
-2.1 of this License shall terminate.
-
-5.3. In the event of termination under Sections 5.1 or 5.2 above, all
-end user license agreements (excluding distributors and resellers) which
-have been validly granted by You or Your distributors under this License
-prior to termination shall survive termination.
-
-************************************************************************
-* *
-* 6. Disclaimer of Warranty *
-* ------------------------- *
-* *
-* Covered Software is provided under this License on an "as is" *
-* basis, without warranty of any kind, either expressed, implied, or *
-* statutory, including, without limitation, warranties that the *
-* Covered Software is free of defects, merchantable, fit for a *
-* particular purpose or non-infringing. The entire risk as to the *
-* quality and performance of the Covered Software is with You. *
-* Should any Covered Software prove defective in any respect, You *
-* (not any Contributor) assume the cost of any necessary servicing, *
-* repair, or correction. This disclaimer of warranty constitutes an *
-* essential part of this License. No use of any Covered Software is *
-* authorized under this License except under this disclaimer. *
-* *
-************************************************************************
-
-************************************************************************
-* *
-* 7. Limitation of Liability *
-* -------------------------- *
-* *
-* Under no circumstances and under no legal theory, whether tort *
-* (including negligence), contract, or otherwise, shall any *
-* Contributor, or anyone who distributes Covered Software as *
-* permitted above, be liable to You for any direct, indirect, *
-* special, incidental, or consequential damages of any character *
-* including, without limitation, damages for lost profits, loss of *
-* goodwill, work stoppage, computer failure or malfunction, or any *
-* and all other commercial damages or losses, even if such party *
-* shall have been informed of the possibility of such damages. This *
-* limitation of liability shall not apply to liability for death or *
-* personal injury resulting from such party's negligence to the *
-* extent applicable law prohibits such limitation. Some *
-* jurisdictions do not allow the exclusion or limitation of *
-* incidental or consequential damages, so this exclusion and *
-* limitation may not apply to You. *
-* *
-************************************************************************
-
-8. Litigation
--------------
-
-Any litigation relating to this License may be brought only in the
-courts of a jurisdiction where the defendant maintains its principal
-place of business and such litigation shall be governed by laws of that
-jurisdiction, without reference to its conflict-of-law provisions.
-Nothing in this Section shall prevent a party's ability to bring
-cross-claims or counter-claims.
-
-9. Miscellaneous
-----------------
-
-This License represents the complete agreement concerning the subject
-matter hereof. If any provision of this License is held to be
-unenforceable, such provision shall be reformed only to the extent
-necessary to make it enforceable. Any law or regulation which provides
-that the language of a contract shall be construed against the drafter
-shall not be used to construe this License against a Contributor.
-
-10. Versions of the License
----------------------------
-
-10.1. New Versions
-
-Mozilla Foundation is the license steward. Except as provided in Section
-10.3, no one other than the license steward has the right to modify or
-publish new versions of this License. Each version will be given a
-distinguishing version number.
-
-10.2. Effect of New Versions
-
-You may distribute the Covered Software under the terms of the version
-of the License under which You originally received the Covered Software,
-or under the terms of any subsequent version published by the license
-steward.
-
-10.3. Modified Versions
-
-If you create software not governed by this License, and you want to
-create a new license for such software, you may create and use a
-modified version of this License if you rename the license and remove
-any references to the name of the license steward (except to note that
-such modified license differs from this License).
-
-10.4. Distributing Source Code Form that is Incompatible With Secondary
-Licenses
-
-If You choose to distribute Source Code Form that is Incompatible With
-Secondary Licenses under the terms of this version of the License, the
-notice described in Exhibit B of this License must be attached.
-
-Exhibit A - Source Code Form License Notice
--------------------------------------------
-
- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-If it is not possible or desirable to put the notice in a particular
-file, then You may include the notice in a location (such as a LICENSE
-file in a relevant directory) where a recipient would be likely to look
-for such a notice.
-
-You may add additional accurate notices of copyright ownership.
-
-Exhibit B - "Incompatible With Secondary Licenses" Notice
----------------------------------------------------------
-
- This Source Code Form is "Incompatible With Secondary Licenses", as
- defined by the Mozilla Public License, v. 2.0.
deleted file mode 100644
--- a/third_party/rust/mozprofile/src/lib.rs
+++ /dev/null
@@ -1,210 +0,0 @@
-extern crate tempdir;
-
-pub mod profile;
-pub mod preferences;
-pub mod prefreader;
-
-
-#[cfg(test)]
-mod test {
-// use std::fs::File;
-// use profile::Profile;
- use prefreader::{parse, tokenize, serialize};
- use prefreader::{PrefToken, Position};
- use preferences::Pref;
- use std::collections::BTreeMap;
- use std::error::Error;
- use std::io::Cursor;
- use std::str;
-
- #[test]
- fn tokenize_simple() {
- let prefs = " user_pref ( 'example.pref.string', 'value' ) ;\n pref(\"example.pref.int\", -123); sticky_pref('example.pref.bool',false);";
-
- let p = Position::new();
-
- let expected = vec![PrefToken::UserPrefFunction(p),
- PrefToken::Paren('(', p),
- PrefToken::String("example.pref.string".into(), p),
- PrefToken::Comma(p),
- PrefToken::String("value".into(), p),
- PrefToken::Paren(')', p),
- PrefToken::Semicolon(p),
- PrefToken::PrefFunction(p),
- PrefToken::Paren('(', p),
- PrefToken::String("example.pref.int".into(), p),
- PrefToken::Comma(p),
- PrefToken::Int(-123, p),
- PrefToken::Paren(')', p),
- PrefToken::Semicolon(p),
- PrefToken::StickyPrefFunction(p),
- PrefToken::Paren('(', p),
- PrefToken::String("example.pref.bool".into(), p),
- PrefToken::Comma(p),
- PrefToken::Bool(false, p),
- PrefToken::Paren(')', p),
- PrefToken::Semicolon(p)];
-
- tokenize_test(prefs, &expected);
- }
-
- #[test]
- fn tokenize_comments() {
- let prefs = "# bash style comment\n /*block comment*/ user_pref/*block comment*/(/*block comment*/ 'example.pref.string' /*block comment*/,/*block comment*/ 'value'/*block comment*/ )// line comment";
-
- let p = Position::new();
-
- let expected = vec![PrefToken::CommentBashLine(" bash style comment".into(), p),
- PrefToken::CommentBlock("block comment".into(), p),
- PrefToken::UserPrefFunction(p),
- PrefToken::CommentBlock("block comment".into(), p),
- PrefToken::Paren('(', p),
- PrefToken::CommentBlock("block comment".into(), p),
- PrefToken::String("example.pref.string".into(), p),
- PrefToken::CommentBlock("block comment".into(), p),
- PrefToken::Comma(p),
- PrefToken::CommentBlock("block comment".into(), p),
- PrefToken::String("value".into(), p),
- PrefToken::CommentBlock("block comment".into(), p),
- PrefToken::Paren(')', p),
- PrefToken::CommentLine(" line comment".into(), p)];
-
- tokenize_test(prefs, &expected);
- }
-
- #[test]
- fn tokenize_escapes() {
- let prefs = r#"user_pref('example\x20pref', "\u0020\u2603\uD800\uDC96\"\'\n\r\\\w)"#;
-
- let p = Position::new();
-
- let expected = vec![PrefToken::UserPrefFunction(p),
- PrefToken::Paren('(', p),
- PrefToken::String("example pref".into(), p),
- PrefToken::Comma(p),
- PrefToken::String(" ☃𐂖\"'\n\r\\\\w".into(), p),
- PrefToken::Paren(')', p)];
-
- tokenize_test(prefs, &expected);
- }
-
- fn tokenize_test(prefs: &str, expected: &[PrefToken]) {
- println!("{}\n", prefs);
-
- for (e, a) in expected.iter().zip(tokenize(prefs.as_bytes())) {
- let success = match (e, &a) {
- (&PrefToken::PrefFunction(_),
- &PrefToken::PrefFunction(_)) => true,
- (&PrefToken::UserPrefFunction(_),
- &PrefToken::UserPrefFunction(_)) => true,
- (&PrefToken::StickyPrefFunction(_),
- &PrefToken::StickyPrefFunction(_)) => true,
- (&PrefToken::CommentBlock(ref data_e, _),
- &PrefToken::CommentBlock(ref data_a, _)) => {
- data_e == data_a
- },
- (&PrefToken::CommentLine(ref data_e, _),
- &PrefToken::CommentLine(ref data_a, _)) => {
- data_e == data_a
- },
- (&PrefToken::CommentBashLine(ref data_e, _),
- &PrefToken::CommentBashLine(ref data_a, _)) => {
- data_e == data_a
- },
- (&PrefToken::Paren(data_e, _),
- &PrefToken::Paren(data_a, _)) => {
- data_e == data_a
- },
- (&PrefToken::Semicolon(_),
- &PrefToken::Semicolon(_)) => true,
- (&PrefToken::Comma(_),
- &PrefToken::Comma(_)) => true,
- (&PrefToken::String(ref data_e, _),
- &PrefToken::String(ref data_a, _)) => {
- data_e == data_a
- },
- (&PrefToken::Int(data_e, _),
- &PrefToken::Int(data_a, _)) => {
- data_e == data_a
- },
- (&PrefToken::Bool(data_e, _),
- &PrefToken::Bool(data_a, _)) => {
- data_e == data_a
- },
- (&PrefToken::Error(data_e, _),
- &PrefToken::Error(data_a, _)) => {
- data_e == data_a
- },
- (_, _) => false
- };
- if !success {
- println!("Expected {:?}, got {:?}", e, a);
- }
- assert!(success);
- }
- }
-
- #[test]
- fn parse_simple() {
- let input = " user_pref /* block comment */ ( 'example.pref.string', 'value' ) ;\n pref(\"example.pref.int\", -123); sticky_pref('example.pref.bool',false)";
-
- let mut expected: BTreeMap<String, Pref> = BTreeMap::new();
- expected.insert("example.pref.string".into(), Pref::new("value"));
- expected.insert("example.pref.int".into(), Pref::new(-123));
- expected.insert("example.pref.bool".into(), Pref::new_sticky(false));
-
- parse_test(input, expected);
- }
-
- #[test]
- fn parse_escape() {
- let input = r#"user_pref('example\\pref\"string', 'val\x20ue' )"#;
-
- let mut expected: BTreeMap<String, Pref> = BTreeMap::new();
- expected.insert("example\\pref\"string".into(), Pref::new("val ue"));
-
- parse_test(input, expected);
- }
-
- fn parse_test(input: &str, expected: BTreeMap<String, Pref>) {
- match parse(input.as_bytes()) {
- Ok(ref actual) => {
- println!("Expected:\n{:?}\nActual\n{:?}", expected, actual);
- assert_eq!(actual, &expected);
- }
- Err(e) => {
- println!("{}", e.description());
- assert!(false)
- }
- }
- }
-
- #[test]
- fn serialize_simple() {
- let input = " user_pref /* block comment */ ( 'example.pref.string', 'value' ) ;\n pref(\"example.pref.int\", -123); sticky_pref('example.pref.bool',false)";
- let expected = "sticky_pref(\"example.pref.bool\", false);
-user_pref(\"example.pref.int\", -123);
-user_pref(\"example.pref.string\", \"value\");\n";
-
- serialize_test(input, expected);
- }
-
- #[test]
- fn serialize_quotes() {
- let input = r#"user_pref('example\\with"quotes"', '"Value"')"#;
- let expected = r#"user_pref("example\\with\"quotes\"", "\"Value\"");
-"#;
-
- serialize_test(input, expected);
- }
-
- fn serialize_test(input: &str, expected: &str) {
- let buf = Vec::with_capacity(expected.len());
- let mut out = Cursor::new(buf);
- serialize(&parse(input.as_bytes()).unwrap(), &mut out).unwrap();
- let data = out.into_inner();
- let actual = str::from_utf8(&*data).unwrap();
- println!("Expected:\n{:?}\nActual\n{:?}", expected, actual);
- assert_eq!(actual, expected);
- }
-}
deleted file mode 100644
--- a/third_party/rust/mozprofile/src/preferences.rs
+++ /dev/null
@@ -1,60 +0,0 @@
-use std::collections::BTreeMap;
-use std::string;
-use std::convert::From;
-
-pub type Preferences = BTreeMap<String, Pref>;
-
-#[derive(Debug, PartialEq, Clone)]
-pub enum PrefValue {
- Bool(bool),
- String(string::String),
- Int(i64),
-}
-
-impl From<bool> for PrefValue {
- fn from(value: bool) -> Self {
- PrefValue::Bool(value)
- }
-}
-
-impl From<String> for PrefValue {
- fn from(value: String) -> Self {
- PrefValue::String(value)
- }
-}
-
-impl From<&'static str> for PrefValue {
- fn from(value: &'static str) -> Self {
- PrefValue::String(value.into())
- }
-}
-
-impl From<i64> for PrefValue {
- fn from(value: i64) -> Self {
- PrefValue::Int(value)
- }
-}
-
-#[derive(Debug, PartialEq, Clone)]
-pub struct Pref {
- pub value: PrefValue,
- pub sticky: bool
-}
-
-impl Pref {
- pub fn new<T>(value: T) -> Pref
- where T: Into<PrefValue> {
- Pref {
- value: value.into(),
- sticky: false
- }
- }
-
- pub fn new_sticky<T>(value: T) -> Pref
- where T: Into<PrefValue> {
- Pref {
- value: value.into(),
- sticky: true
- }
- }
-}
deleted file mode 100644
--- a/third_party/rust/mozprofile/src/prefreader.rs
+++ /dev/null
@@ -1,1010 +0,0 @@
-use preferences::{Pref, PrefValue, Preferences};
-use std::borrow::Borrow;
-use std::borrow::Cow;
-use std::char;
-use std::error::Error;
-use std::fmt;
-use std::io::{self, Write};
-use std::iter::Iterator;
-use std::str;
-use std::mem;
-use std::ops::Deref;
-
-impl PrefReaderError {
- fn new(message: &'static str, position: Position, parent: Option<Box<Error>>) -> PrefReaderError {
- PrefReaderError {
- message: message,
- position: position,
- parent: parent
- }
- }
-}
-
-
-impl fmt::Display for PrefReaderError {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{} at line {}, column {}",
- self.message, self.position.line, self.position.column)
- }
-}
-
-
-impl Error for PrefReaderError {
- fn description(&self) -> &str {
- self.message
- }
-
- fn cause(&self) -> Option<&Error> {
- match self.parent {
- None => None,
- Some(ref cause) => Some(cause.deref())
- }
- }
-}
-
-impl From<io::Error> for PrefReaderError {
- fn from(err: io::Error) -> PrefReaderError {
- PrefReaderError::new("IOError",
- Position::new(),
- Some(err.into()))
- }
-}
-
-#[derive(Copy, Clone, Debug, PartialEq)]
-enum TokenizerState {
- Junk,
- CommentStart,
- CommentLine,
- CommentBlock,
- FunctionName,
- AfterFunctionName,
- FunctionArgs,
- FunctionArg,
- DoubleQuotedString,
- SingleQuotedString,
- Number,
- Bool,
- AfterFunctionArg,
- AfterFunction,
- Error,
-}
-
-#[derive(Copy, Clone, Debug, PartialEq)]
-pub struct Position {
- line: u32,
- column: u32
-}
-
-impl Position {
- pub fn new() -> Position {
- Position {
- line: 1,
- column: 0
- }
- }
-}
-
-#[derive(Copy, Clone, Debug, PartialEq)]
-pub enum TokenType {
- None,
- PrefFunction,
- UserPrefFunction,
- StickyPrefFunction,
- CommentBlock,
- CommentLine,
- CommentBashLine,
- Paren,
- Semicolon,
- Comma,
- String,
- Int,
- Bool,
- Error
-}
-
-#[derive(Debug, PartialEq)]
-pub enum PrefToken<'a> {
- PrefFunction(Position),
- UserPrefFunction(Position),
- StickyPrefFunction(Position),
- CommentBlock(Cow<'a, str>, Position),
- CommentLine(Cow<'a, str>, Position),
- CommentBashLine(Cow<'a, str>, Position),
- Paren(char, Position),
- Semicolon(Position),
- Comma(Position),
- String(Cow<'a, str>, Position),
- Int(i64, Position),
- Bool(bool, Position),
- Error(&'static str, Position)
-}
-
-impl<'a> PrefToken<'a> {
- fn position(&self) -> Position {
- match *self {
- PrefToken::PrefFunction(position) => position,
- PrefToken::UserPrefFunction(position) => position,
- PrefToken::StickyPrefFunction(position) => position,
- PrefToken::CommentBlock(_, position) => position,
- PrefToken::CommentLine(_, position) => position,
- PrefToken::CommentBashLine(_, position) => position,
- PrefToken::Paren(_, position) => position,
- PrefToken::Semicolon(position) => position,
- PrefToken::Comma(position) => position,
- PrefToken::String(_, position) => position,
- PrefToken::Int(_, position) => position,
- PrefToken::Bool(_, position) => position,
- PrefToken::Error(_, position) => position
- }
- }
-}
-
-#[derive(Debug)]
-pub struct PrefReaderError {
- message: &'static str,
- position: Position,
- parent: Option<Box<Error>>
-}
-
-struct TokenData<'a> {
- token_type: TokenType,
- complete: bool,
- position: Position,
- data: Cow<'a, str>,
- start_pos: usize,
-}
-
-impl<'a> TokenData<'a> {
- fn new(token_type: TokenType, position: Position, start_pos: usize) -> TokenData<'a> {
- TokenData {
- token_type: token_type,
- complete: false,
- position: position,
- data: Cow::Borrowed(""),
- start_pos: start_pos,
- }
- }
-
- fn start(&mut self, tokenizer: &PrefTokenizer, token_type: TokenType) {
- self.token_type = token_type;
- self.position = tokenizer.position;
- self.start_pos = tokenizer.pos;
- }
-
- fn end(&mut self, buf: &'a [u8], end_pos: usize) -> Result<(), PrefReaderError> {
- self.complete = true;
- self.add_slice_to_token(buf, end_pos)
- }
-
- fn add_slice_to_token(&mut self, buf: &'a [u8], end_pos: usize) -> Result<(), PrefReaderError> {
- let data = match str::from_utf8(&buf[self.start_pos..end_pos]) {
- Ok(x) => x,
- Err(_) => {
- return Err(PrefReaderError::new("Could not convert string to utf8",
- self.position, None));
- }
- };
- if self.data != "" {
- self.data.to_mut().push_str(&data)
- } else {
- self.data = Cow::Borrowed(&data)
- };
- Ok(())
- }
-
- fn push_char(&mut self, tokenizer: &PrefTokenizer, data: char) {
- self.data.to_mut().push(data);
- self.start_pos = tokenizer.pos + 1;
- }
-}
-
-pub struct PrefTokenizer<'a> {
- data: &'a [u8],
- pos: usize,
- cur: Option<char>,
- position: Position,
- state: TokenizerState,
- next_state: Option<TokenizerState>,
-}
-
-impl<'a> PrefTokenizer<'a> {
- pub fn new(data: &'a [u8]) -> PrefTokenizer<'a> {
- PrefTokenizer {
- data: data,
- pos: 0,
- cur: None,
- position: Position::new(),
- state: TokenizerState::Junk,
- next_state: Some(TokenizerState::FunctionName),
- }
- }
-
- fn make_token(&mut self, token_data: TokenData<'a>) -> PrefToken<'a> {
- let buf = token_data.data;
- let position = token_data.position;
- match token_data.token_type {
- TokenType::None => panic!("Got a token without a type"),
- TokenType::PrefFunction => PrefToken::PrefFunction(position),
- TokenType::UserPrefFunction => PrefToken::UserPrefFunction(position),
- TokenType::StickyPrefFunction => PrefToken::StickyPrefFunction(position),
- TokenType::CommentBlock => PrefToken::CommentBlock(buf, position),
- TokenType::CommentLine => PrefToken::CommentLine(buf, position),
- TokenType::CommentBashLine => PrefToken::CommentBashLine(buf, position),
- TokenType::Paren => {
- if buf.len() != 1 {
- panic!("Expected a buffer of length one");
- }
- PrefToken::Paren(buf.chars().next().unwrap(), position)
- },
- TokenType::Semicolon => PrefToken::Semicolon(position),
- TokenType::Comma => PrefToken::Comma(position),
- TokenType::String => PrefToken::String(buf, position),
- TokenType::Int => {
- let value = i64::from_str_radix(buf.borrow(), 10)
- .expect("Integer wasn't parsed as an i64");
- PrefToken::Int(value, position)
- },
- TokenType::Bool => {
- let value = match buf.borrow() {
- "true" => true,
- "false" => false,
- x => panic!(format!("Boolean wasn't 'true' or 'false' (was {})", x))
- };
- PrefToken::Bool(value, position)
- },
- TokenType::Error => panic!("make_token can't construct errors")
- }
- }
-
- fn get_char(&mut self) -> Option<char> {
- if self.pos >= self.data.len() - 1 {
- self.cur = None;
- return None
- };
- if self.cur.is_some() {
- self.pos += 1;
- }
- let c = self.data[self.pos] as char;
- if self.cur == Some('\n') {
- self.position.line += 1;
- self.position.column = 0;
- } else if self.cur.is_some() {
- self.position.column += 1;
- };
- self.cur = Some(c);
- self.cur
- }
-
- fn unget_char(&mut self) -> Option<char> {
- if self.pos == 0 {
- self.position.column = 0;
- self.cur = None
- } else {
- self.pos -= 1;
- let c = self.data[self.pos] as char;
- if c == '\n' {
- self.position.line -= 1;
- let mut col_pos = self.pos - 1;
- while col_pos > 0 && self.data[col_pos] as char != '\n' {
- col_pos -= 1;
- }
- self.position.column = (self.pos - col_pos as usize - 1) as u32;
- } else {
- self.position.column -= 1;
- }
- self.cur = Some(c);
- }
- self.cur
- }
-
- fn is_space(c: char) -> bool {
- match c {
- ' ' | '\t' | '\r' | '\n' => true,
- _ => false
- }
- }
-
- fn skip_whitespace(&mut self) -> Option<char> {
- while let Some(c) = self.cur {
- if PrefTokenizer::is_space(c) {
- self.get_char();
- } else {
- break
- };
- }
- self.cur
- }
-
- fn consume_escape(&mut self, token_data: &mut TokenData<'a>) -> Result<(), PrefReaderError> {
- let pos = self.pos;
- let escaped = try!(self.read_escape());
- if let Some(escape_char) = escaped {
- try!(token_data.add_slice_to_token(&self.data, pos));
- token_data.push_char(&self, escape_char);
- };
- Ok(())
- }
-
- fn read_escape(&mut self) -> Result<Option<char>, PrefReaderError> {
- let escape_char = match self.get_char() {
- Some('u') => try!(self.read_hex_escape(4, true)),
- Some('x') => try!(self.read_hex_escape(2, true)),
- Some('\\') => '\\' as u32,
- Some('"') => '"' as u32,
- Some('\'') => '\'' as u32,
- Some('r') => '\r' as u32,
- Some('n') => '\n' as u32,
- Some(_) => return Ok(None),
- None => return Err(PrefReaderError::new("EOF in character escape",
- self.position, None))
- };
- Ok(Some(try!(char::from_u32(escape_char)
- .ok_or(PrefReaderError::new("Invalid codepoint decoded from escape",
- self.position, None)))))
- }
-
- fn read_hex_escape(&mut self, hex_chars: isize, first: bool) -> Result<u32, PrefReaderError> {
- let mut value = 0;
- for _ in 0..hex_chars {
- match self.get_char() {
- Some(x) => {
- value = value << 4;
- match x {
- '0'...'9' => value += x as u32 - '0' as u32,
- 'a'...'f' => value += x as u32 - 'a' as u32,
- 'A'...'F' => value += x as u32 - 'A' as u32,
- _ => return Err(PrefReaderError::new(
- "Unexpected character in escape", self.position, None))
- }
- },
- None => return Err(PrefReaderError::new(
- "Unexpected EOF in escape", self.position, None))
- }
- }
- if first && value >= 0xD800 && value <= 0xDBFF {
- // First part of a surrogate pair
- if self.get_char() != Some('\\') || self.get_char() != Some('u') {
- return Err(PrefReaderError::new("Lone high surrogate in surrogate pair",
- self.position, None))
- }
- self.unget_char();
- let high_surrogate = value;
- let low_surrogate = try!(self.read_hex_escape(4, false));
- let high_value = (high_surrogate - 0xD800) << 10;
- let low_value = low_surrogate - 0xDC00;
- value = high_value + low_value + 0x10000;
- } else if first && value >= 0xDC00 && value <= 0xDFFF {
- return Err(PrefReaderError::new("Lone low surrogate",
- self.position,
- None))
- } else if !first && (value < 0xDC00 || value > 0xDFFF) {
- return Err(PrefReaderError::new("Invalid low surrogate in surrogate pair",
- self.position,
- None));
- }
- Ok(value)
- }
-
- fn get_match(&mut self, target: &str, separators: &str) -> bool {
- let initial_pos = self.pos;
- let mut matched = true;
- for c in target.chars() {
- if self.cur == Some(c) {
- self.get_char();
- } else {
- matched = false;
- break;
- }
- }
-
- if !matched {
- for _ in 0..(self.pos - initial_pos) {
- self.unget_char();
- }
- } else {
- // Check that the next character is whitespace or a separator
- if let Some(c) = self.cur {
- if !(PrefTokenizer::is_space(c) || separators.contains(c) || c == '/') {
- matched = false;
- }
- }
- self.unget_char();
- }
-
- matched
- }
-
- fn next_token(&mut self) -> Result<Option<TokenData<'a>>, PrefReaderError> {
- let mut token_data = TokenData::new(TokenType::None, Position::new(), 0);
-
- loop {
- let mut c = match self.get_char() {
- Some(x) => x,
- None => return Ok(None)
- };
-
- self.state = match self.state {
- TokenizerState::Junk => {
- c = match self.skip_whitespace() {
- Some(x) => x,
- None => return Ok(None)
- };
- match c {
- '/' => TokenizerState::CommentStart,
- '#' => {
- token_data.start(&self, TokenType::CommentBashLine);
- token_data.start_pos = self.pos + 1;
- TokenizerState::CommentLine
- },
- _ => {
- self.unget_char();
- let next = match self.next_state {
- Some(x) => x,
- None => {
- return Err(PrefReaderError::new(
- "In Junk state without a next state defined",
- self.position,
- None))
- }
- };
- self.next_state = None;
- next
- }
- }
- },
- TokenizerState::CommentStart => {
- match c {
- '*' => {
- token_data.start(&self, TokenType::CommentBlock);
- token_data.start_pos = self.pos + 1;
- TokenizerState::CommentBlock
- },
- '/' => {
- token_data.start(&self, TokenType::CommentLine);
- token_data.start_pos = self.pos + 1;
- TokenizerState::CommentLine
- },
- _ => {
- return Err(PrefReaderError::new(
- "Invalid character after /", self.position, None))
- }
- }
-
- },
- TokenizerState::CommentLine => {
- match c {
- '\n' => {
- try!(token_data.end(&self.data, self.pos));
- TokenizerState::Junk
- },
- _ => {
- TokenizerState::CommentLine
- }
- }
- },
- TokenizerState::CommentBlock => {
- match c {
- '*' => {
- if self.get_char() == Some('/') {
- try!(token_data.end(&self.data, self.pos - 1));
- TokenizerState::Junk
- } else {
- TokenizerState::CommentBlock
- }
- },
- _ => TokenizerState::CommentBlock
- }
- },
- TokenizerState::FunctionName => {
- let position = self.position;
- let start_pos = self.pos;
- match c {
- 'u' => {
- if self.get_match("user_pref", "(") {
- token_data.start(&self, TokenType::UserPrefFunction);
- }
- },
- 's' => {
- if self.get_match("sticky_pref", "(") {
- token_data.start(&self, TokenType::StickyPrefFunction);
- }
- }
- 'p' => {
- if self.get_match("pref", "(") {
- token_data.start(&self, TokenType::PrefFunction);
- }
- },
- _ => {}
- };
- if token_data.token_type == TokenType::None {
- // We didn't match anything
- return Err(PrefReaderError::new(
- "Expected a pref function name", position, None))
- } else {
- token_data.start_pos = start_pos;
- token_data.position = position;
- try!(token_data.end(&self.data, self.pos + 1));
- self.next_state = Some(TokenizerState::AfterFunctionName);
- TokenizerState::Junk
- }
- },
- TokenizerState::AfterFunctionName => {
- match c {
- '(' => {
- self.next_state = Some(TokenizerState::FunctionArgs);
- token_data.start(&self, TokenType::Paren);
- try!(token_data.end(&self.data, self.pos + 1));
- self.next_state = Some(TokenizerState::FunctionArgs);
- TokenizerState::Junk
- },
- _ => {
- return Err(PrefReaderError::new(
- "Expected an opening paren", self.position, None))
- }
- }
- },
- TokenizerState::FunctionArgs => {
- match c {
- ')' => {
- token_data.start(&self, TokenType::Paren);
- try!(token_data.end(&self.data, self.pos + 1));
- self.next_state = Some(TokenizerState::AfterFunction);
- TokenizerState::Junk
- },
- _ => {
- self.unget_char();
- TokenizerState::FunctionArg
- }
- }
- },
- TokenizerState::FunctionArg => {
- match c {
- '"' => {
- token_data.start(&self, TokenType::String);
- token_data.start_pos = self.pos + 1;
- TokenizerState::DoubleQuotedString
- },
- '\'' => {
- token_data.start(&self, TokenType::String);
- token_data.start_pos = self.pos + 1;
- TokenizerState::SingleQuotedString
- },
- 't' | 'f' => {
- self.unget_char();
- TokenizerState::Bool
- },
- '0'...'9' | '-' |'+' => {
- token_data.start(&self, TokenType::Int);
- TokenizerState::Number
- },
- _ => {
- return Err(PrefReaderError::new(
- "Invalid character at start of function argument",
- self.position, None))
- }
- }
- },
- TokenizerState::DoubleQuotedString => {
- match c {
- '"' => {
- try!(token_data.end(&self.data, self.pos));
- self.next_state = Some(TokenizerState::AfterFunctionArg);
- TokenizerState::Junk
-
- },
- '\n' => {
- return Err(PrefReaderError::new(
- "EOL in double quoted string", self.position, None))
- },
- '\\' => {
- try!(self.consume_escape(&mut token_data));
- TokenizerState::DoubleQuotedString
- },
- _ => TokenizerState::DoubleQuotedString
- }
- },
- TokenizerState::SingleQuotedString => {
- match c {
- '\'' => {
- try!(token_data.end(&self.data, self.pos));
- self.next_state = Some(TokenizerState::AfterFunctionArg);
- TokenizerState::Junk
-
- },
- '\n' => {
- return Err(PrefReaderError::new(
- "EOL in single quoted string", self.position, None))
- },
- '\\' => {
- try!(self.consume_escape(&mut token_data));
- TokenizerState::SingleQuotedString
- }
- _ => TokenizerState::SingleQuotedString
- }
- },
- TokenizerState::Number => {
- match c {
- '0'...'9' => TokenizerState::Number,
- ')' | ',' => {
- try!(token_data.end(&self.data, self.pos));
- self.unget_char();
- self.next_state = Some(TokenizerState::AfterFunctionArg);
- TokenizerState::Junk
- },
- x if PrefTokenizer::is_space(x) => {
- try!(token_data.end(&self.data, self.pos));
- self.next_state = Some(TokenizerState::AfterFunctionArg);
- TokenizerState::Junk
- },
- _ => {
- return Err(PrefReaderError::new(
- "Invalid character in number literal", self.position, None))
- }
- }
- },
- TokenizerState::Bool => {
- let start_pos = self.pos;
- let position = self.position;
- match c {
- 't' => {
- if self.get_match("true", ",)") {
- token_data.start(&self, TokenType::Bool)
- }
- },
- 'f' => {
- if self.get_match("false", ",)") {
- token_data.start(&self, TokenType::Bool)
- }
- }
- _ => {}
- };
- if token_data.token_type == TokenType::None {
- return Err(PrefReaderError::new(
- "Unexpected characters in function argument",
- position, None));
- } else {
- token_data.start_pos = start_pos;
- token_data.position = position;
- try!(token_data.end(&self.data, self.pos + 1));
- self.next_state = Some(TokenizerState::AfterFunctionArg);
- TokenizerState::Junk
- }
- },
- TokenizerState::AfterFunctionArg => {
- match c {
- ',' => {
- token_data.start(&self, TokenType::Comma);
- try!(token_data.end(&self.data, self.pos + 1));
- self.next_state = Some(TokenizerState::FunctionArg);
- TokenizerState::Junk
- }
- ')' => {
- token_data.start(&self, TokenType::Paren);
- try!(token_data.end(&self.data, self.pos + 1));
- self.next_state = Some(TokenizerState::AfterFunction);
- TokenizerState::Junk
- }
- _ => return Err(PrefReaderError::new
- ("Unexpected character after function argument",
- self.position,
- None))
- }
- },
- TokenizerState::AfterFunction => {
- match c {
- ';' => {
- token_data.start(&self, TokenType::Semicolon);
- try!(token_data.end(&self.data, self.pos));
- self.next_state = Some(TokenizerState::FunctionName);
- TokenizerState::Junk
- }
- _ => return Err(PrefReaderError::new(
- "Unexpected character after function",
- self.position, None))
- }
- },
- TokenizerState::Error => TokenizerState::Error
- };
- if token_data.complete {
- return Ok(Some(token_data));
- }
- }
- }
-}
-
-impl<'a> Iterator for PrefTokenizer<'a> {
- type Item = PrefToken<'a>;
-
- fn next(&mut self) -> Option<PrefToken<'a>> {
- if let TokenizerState::Error = self.state {
- return None;
- }
- let token_data = match self.next_token() {
- Err(e) => {
- self.state = TokenizerState::Error;
- return Some(PrefToken::Error(e.message,
- e.position))
-
- },
- Ok(Some(token_data)) => token_data,
- Ok(None) => return None,
- };
- let token = self.make_token(token_data);
- Some(token)
- }
-}
-
-pub fn tokenize<'a>(data: &'a [u8]) -> PrefTokenizer<'a> {
- PrefTokenizer::new(data)
-}
-
-pub fn serialize_token<T: Write>(token: &PrefToken, output: &mut T) -> Result<(), PrefReaderError> {
- let mut data_buf = String::new();
-
- let data = match token {
- &PrefToken::PrefFunction(_) => "pref",
- &PrefToken::UserPrefFunction(_) => "user_pref",
- &PrefToken::StickyPrefFunction(_) => "sticky_pref",
- &PrefToken::CommentBlock(ref data, _) => {
- data_buf.reserve(data.len() + 4);
- data_buf.push_str("/*");
- data_buf.push_str(data.borrow());
- data_buf.push_str("*");
- &*data_buf
- },
- &PrefToken::CommentLine(ref data, _) => {
- data_buf.reserve(data.len() + 2);
- data_buf.push_str("//");
- data_buf.push_str(data.borrow());
- &*data_buf
- },
- &PrefToken::CommentBashLine(ref data, _) => {
- data_buf.reserve(data.len() + 1);
- data_buf.push_str("#");
- data_buf.push_str(data.borrow());
- &*data_buf
- },
- &PrefToken::Paren(data, _) => {
- data_buf.push(data);
- &*data_buf
- },
- &PrefToken::Comma(_) => ",",
- &PrefToken::Semicolon(_) => ";\n",
- &PrefToken::String(ref data, _) => {
- data_buf.reserve(data.len() + 2);
- data_buf.push('"');
- data_buf.push_str(escape_quote(data.borrow()).borrow());
- data_buf.push('"');
- &*data_buf
- },
- &PrefToken::Int(data, _) => {
- data_buf.push_str(&*data.to_string());
- &*data_buf
- },
- &PrefToken::Bool(data, _) => {
- if data {"true"} else {"false"}
- },
- &PrefToken::Error(data, pos) => return Err(PrefReaderError::new(data, pos, None))
- };
- try!(output.write(data.as_bytes()));
- Ok(())
-}
-
-pub fn serialize_tokens<'a, I, W>(tokens: I, output: &mut W) -> Result<(), PrefReaderError>
- where I: Iterator<Item=&'a PrefToken<'a>>, W: Write {
- for token in tokens {
- try!(serialize_token(token, output));
- }
- Ok(())
-}
-
-fn escape_quote<'a>(data: &'a str) -> Cow<'a, str> {
- // Not very efficient…
- if data.contains("\"") || data.contains("\\") {
- let new_data = Cow::Owned(data
- .replace(r#"\"#, r#"\\"#)
- .replace(r#"""#, r#"\""#));
- new_data
- } else {
- Cow::Borrowed(data)
- }
-}
-
-#[derive(Debug, PartialEq)]
-enum ParserState {
- Function,
- Key,
- Value,
-}
-
-struct PrefBuilder {
- key: Option<String>,
- value: Option<PrefValue>,
- sticky: bool
-}
-
-impl PrefBuilder {
- fn new() -> PrefBuilder {
- PrefBuilder {
- key: None,
- value: None,
- sticky: false
- }
- }
-}
-
-
-fn skip_comments<'a>(tokenizer: &mut PrefTokenizer<'a>) -> Option<PrefToken<'a>> {
- loop {
- match tokenizer.next() {
- Some(PrefToken::CommentBashLine(_, _)) |
- Some(PrefToken::CommentBlock(_, _)) |
- Some(PrefToken::CommentLine(_, _)) => {},
- Some(x) => return Some(x),
- None => return None,
- }
- }
-}
-
-pub fn parse_tokens<'a>(tokenizer: &mut PrefTokenizer<'a>) -> Result<Preferences,
- PrefReaderError> {
-
- let mut state = ParserState::Function;
- let mut current_pref = PrefBuilder::new();
- let mut rv = Preferences::new();
-
- loop {
- // Not just using a for loop here seems strange, but this restricts the
- // scope of the borrow
- let token = {
- match tokenizer.next() {
- Some(x) => x,
- None => break
- }
- };
- // First deal with comments and errors
- match token {
- PrefToken::Error(msg, position) => {
- return Err(PrefReaderError::new(msg.into(), position, None));
- },
- PrefToken::CommentBashLine(_, _) |
- PrefToken::CommentLine(_, _) |
- PrefToken::CommentBlock(_, _) => {
- continue
- },
- _ => {}
- }
- state = match state {
- ParserState::Function => {
- match token {
- PrefToken::PrefFunction(_) => {
- current_pref.sticky = false;
- }
- PrefToken::UserPrefFunction(_) => {
- current_pref.sticky = false;
- },
- PrefToken::StickyPrefFunction(_) => {
- current_pref.sticky = true;
- },
- _ => {
- return Err(PrefReaderError::new("Expected pref function".into(),
- token.position(), None));
- }
- }
- let next = skip_comments(tokenizer);
- match next {
- Some(PrefToken::Paren('(', _)) => ParserState::Key,
- _ => return Err(PrefReaderError::new("Expected open paren".into(),
- next.map(|x| x.position())
- .unwrap_or(tokenizer.position),
- None))
- }
- },
- ParserState::Key => {
- match token {
- PrefToken::String(data, _) => current_pref.key = Some(data.into_owned()),
- _ => {
- return Err(PrefReaderError::new("Expected string", token.position(), None));
- }
- }
- let next = skip_comments(tokenizer);
- match next {
- Some(PrefToken::Comma(_)) => ParserState::Value,
- _ => return Err(PrefReaderError::new("Expected comma",
- next.map(|x| x.position())
- .unwrap_or(tokenizer.position),
- None))
- }
- },
- ParserState::Value => {
- match token {
- PrefToken::String(data, _) => {
- current_pref.value = Some(PrefValue::String(data.into_owned()))
- },
- PrefToken::Int(data, _) => {
- current_pref.value = Some(PrefValue::Int(data))
- }
- PrefToken::Bool(data, _) => {
- current_pref.value = Some(PrefValue::Bool(data))
- },
- _ => {
- return Err(PrefReaderError::new("Expected value", token.position(),
- None))
- }
- }
- let next = skip_comments(tokenizer);
- match next {
- Some(PrefToken::Paren(')', _)) => {}
- _ => return Err(PrefReaderError::new("Expected close paren",
- next.map(|x| x.position())
- .unwrap_or(tokenizer.position),
- None))
- }
- let next = skip_comments(tokenizer);
- match next {
- Some(PrefToken::Semicolon(_)) |
- None => {},
- _ => return Err(PrefReaderError::new("Expected semicolon",
- next.map(|x| x.position())
- .unwrap_or(tokenizer.position),
- None))
- }
- let key = mem::replace(&mut current_pref.key, None);
- let value = mem::replace(&mut current_pref.value, None);
- let pref = if current_pref.sticky {
- Pref::new_sticky(value.unwrap())
- } else {
- Pref::new(value.unwrap())
- };
- rv.insert(key.unwrap(), pref);
- current_pref.sticky = false;
- ParserState::Function
- },
- }
- }
- match state {
- ParserState::Key | ParserState::Value => {
- return Err(PrefReaderError::new("EOF in middle of function",
- tokenizer.position, None));
- },
- _ => {}
- }
- Ok(rv)
-}
-
-pub fn serialize<W: Write>(prefs: &Preferences, output: &mut W) -> io::Result<()> {
- let mut p: Vec<_> = prefs.iter().collect();
- p.sort_by(|a, b| a.0.cmp(&b.0));
- for &(key, pref) in p.iter() {
- let func = if pref.sticky {
- "sticky_pref("
- } else {
- "user_pref("
- }.as_bytes();
- try!(output.write(func));
- try!(output.write("\"".as_bytes()));
- try!(output.write(escape_quote(key).as_bytes()));
- try!(output.write("\"".as_bytes()));
- try!(output.write(", ".as_bytes()));
- match pref.value {
- PrefValue::Bool(x) => {
- try!(output.write((if x {"true"} else {"false"}).as_bytes()));
- },
- PrefValue::Int(x) => {
- try!(output.write(x.to_string().as_bytes()));
- },
- PrefValue::String(ref x) => {
- try!(output.write("\"".as_bytes()));
- try!(output.write(escape_quote(x).as_bytes()));
- try!(output.write("\"".as_bytes()));
- }
- };
- try!(output.write(");\n".as_bytes()));
- };
- Ok(())
-}
-
-pub fn parse<'a>(data: &'a [u8]) -> Result<Preferences, PrefReaderError> {
- let mut tokenizer = tokenize(data);
- parse_tokens(&mut tokenizer)
-}
deleted file mode 100644
--- a/third_party/rust/mozprofile/src/profile.rs
+++ /dev/null
@@ -1,115 +0,0 @@
-use preferences::{Preferences, Pref};
-use prefreader::{parse, serialize, PrefReaderError};
-use std::collections::btree_map::Iter;
-use std::fs::File;
-use std::io::Result as IoResult;
-use std::io::prelude::*;
-use std::path::{Path, PathBuf};
-use tempdir::TempDir;
-
-#[derive(Debug)]
-pub struct Profile {
- pub path: PathBuf,
- pub temp_dir: Option<TempDir>,
- prefs: Option<PrefFile>,
- user_prefs: Option<PrefFile>,
-}
-
-impl Profile {
- pub fn new(opt_path: Option<&Path>) -> IoResult<Profile> {
- let mut temp_dir = None;
- let path = match opt_path {
- Some(p) => p.to_path_buf(),
- None => {
- let dir = try!(TempDir::new("rust_mozprofile"));
- let temp_path = dir.path().to_path_buf();
- temp_dir = Some(dir);
- temp_path
- }
- };
-
- Ok(Profile {
- path: path,
- temp_dir: temp_dir,
- prefs: None,
- user_prefs: None
- })
- }
-
- pub fn prefs(&mut self) -> Result<&mut PrefFile, PrefReaderError> {
- if self.prefs.is_none() {
- let mut pref_path = PathBuf::from(&self.path);
- pref_path.push("prefs.js");
- self.prefs = Some(try!(PrefFile::new(pref_path)))
- };
- // This error handling doesn't make much sense
- Ok(self.prefs.as_mut().unwrap())
- }
-
- pub fn user_prefs(&mut self) -> Result<&mut PrefFile, PrefReaderError> {
- if self.user_prefs.is_none() {
- let mut pref_path = PathBuf::from(&self.path);
- pref_path.push("user.js");
- self.user_prefs = Some(try!(PrefFile::new(pref_path)))
- };
- // This error handling doesn't make much sense
- Ok(self.user_prefs.as_mut().unwrap())
- }
-}
-
-#[derive(Debug)]
-pub struct PrefFile {
- path: PathBuf,
- pub prefs: Preferences,
-}
-
-impl PrefFile {
- pub fn new(path: PathBuf) -> Result<PrefFile, PrefReaderError> {
- let prefs = if !path.exists() {
- Preferences::new()
- } else {
- let mut f = try!(File::open(&path));
- let mut buf = String::with_capacity(4096);
- try!(f.read_to_string(&mut buf));
- try!(parse(buf.as_bytes()))
- };
-
- Ok(PrefFile {
- path: path,
- prefs: prefs
- })
- }
-
- pub fn write(&self) -> IoResult<()> {
- let mut f = try!(File::create(&self.path));
- serialize(&self.prefs, &mut f)
- }
-
- pub fn insert_slice<K>(&mut self, preferences: &[(K, Pref)])
- where K: Into<String> + Clone {
- for &(ref name, ref value) in preferences.iter() {
- self.insert((*name).clone(), (*value).clone());
- }
- }
-
- pub fn insert<K>(&mut self, key: K, value: Pref)
- where K: Into<String> {
- self.prefs.insert(key.into(), value);
- }
-
- pub fn remove(&mut self, key: &str) -> Option<Pref> {
- self.prefs.remove(key)
- }
-
- pub fn get(&mut self, key: &str) -> Option<&Pref> {
- self.prefs.get(key)
- }
-
- pub fn contains_key(&self, key: &str) -> bool {
- self.prefs.contains_key(key)
- }
-
- pub fn iter(&self) -> Iter<String, Pref> {
- self.prefs.iter()
- }
-}