parse_transform.lalrpop: Only make parse_Num and parse_TransformList public

We'll adjust the tests for individual transformations so that they use
the toplevel parse_TransformList().
parent 4583ec9e
......@@ -37,20 +37,20 @@ Transform: cairo::Matrix = {
SkewY
};
pub Matrix: cairo::Matrix = "matrix" "(" <Num> maybe_comma <Num> maybe_comma <Num> maybe_comma <Num> maybe_comma <Num> maybe_comma <Num> ")" =>
Matrix: cairo::Matrix = "matrix" "(" <Num> maybe_comma <Num> maybe_comma <Num> maybe_comma <Num> maybe_comma <Num> maybe_comma <Num> ")" =>
cairo::Matrix::new (<>);
pub Translate: cairo::Matrix = {
Translate: cairo::Matrix = {
"translate" "(" <Num> ")" => cairo::Matrix::new (1.0, 0.0, 0.0, 1.0, <>, 0.0),
"translate" "(" <Num> maybe_comma <Num> ")" => cairo::Matrix::new (1.0, 0.0, 0.0, 1.0, <>)
};
pub Scale: cairo::Matrix = {
Scale: cairo::Matrix = {
"scale" "(" <Num> ")" => cairo::Matrix::new (<>, 0.0, 0.0, <>, 0.0, 0.0),
"scale" "(" <sx: Num> maybe_comma <sy: Num> ")" => cairo::Matrix::new (sx, 0.0, 0.0, sy, 0.0, 0.0),
};
pub Rotate: cairo::Matrix = {
Rotate: cairo::Matrix = {
"rotate" "(" <angle: Num> ")" => {
let a = angle * PI / 180.0;
let (s, c) = a.sin_cos ();
......@@ -68,7 +68,7 @@ pub Rotate: cairo::Matrix = {
}
};
pub SkewX: cairo::Matrix = {
SkewX: cairo::Matrix = {
"skewX" "(" <angle: Num> ")" => {
let a = angle * PI / 180.0;
cairo::Matrix::new (1.0, 0.0,
......@@ -77,7 +77,7 @@ pub SkewX: cairo::Matrix = {
}
};
pub SkewY: cairo::Matrix = {
SkewY: cairo::Matrix = {
"skewY" "(" <angle: Num> ")" => {
let a = angle * PI / 180.0;
cairo::Matrix::new (1.0, a.tan (),
......
......@@ -133,45 +133,45 @@ mod parser_tests {
#[test]
fn parses_matrix () {
assert_eq! (parse_Matrix ("matrix (1 2 3 4 5 6)").unwrap (),
assert_eq! (parse_TransformList ("matrix (1 2 3 4 5 6)").unwrap (),
cairo::Matrix::new (1.0, 2.0, 3.0, 4.0, 5.0, 6.0));
assert_eq! (parse_Matrix ("matrix (1,2,3,4 5 6)").unwrap (),
assert_eq! (parse_TransformList ("matrix (1,2,3,4 5 6)").unwrap (),
cairo::Matrix::new (1.0, 2.0, 3.0, 4.0, 5.0, 6.0));
assert_eq! (parse_Matrix ("matrix (1,2.25,-3.25e2,4 5 6)").unwrap (),
assert_eq! (parse_TransformList ("matrix (1,2.25,-3.25e2,4 5 6)").unwrap (),
cairo::Matrix::new (1.0, 2.25, -325.0, 4.0, 5.0, 6.0));
}
#[test]
fn parses_translate () {
assert_eq! (parse_Translate ("translate(-1 -2)").unwrap (),
assert_eq! (parse_TransformList ("translate(-1 -2)").unwrap (),
cairo::Matrix::new (1.0, 0.0, 0.0, 1.0, -1.0, -2.0));
assert_eq! (parse_Translate ("translate(-1, -2)").unwrap (),
assert_eq! (parse_TransformList ("translate(-1, -2)").unwrap (),
cairo::Matrix::new (1.0, 0.0, 0.0, 1.0, -1.0, -2.0));
assert_eq! (parse_Translate ("translate(-1)").unwrap (),
assert_eq! (parse_TransformList ("translate(-1)").unwrap (),
cairo::Matrix::new (1.0, 0.0, 0.0, 1.0, -1.0, 0.0));
}
#[test]
fn parses_scale () {
assert_eq! (parse_Scale ("scale(-1 -2)").unwrap (),
assert_eq! (parse_TransformList ("scale(-1 -2)").unwrap (),
cairo::Matrix::new (-1.0, 0.0, 0.0, -2.0, 0.0, 0.0));
assert_eq! (parse_Scale ("scale(-1, -2)").unwrap (),
assert_eq! (parse_TransformList ("scale(-1, -2)").unwrap (),
cairo::Matrix::new (-1.0, 0.0, 0.0, -2.0, 0.0, 0.0));
assert_eq! (parse_Scale ("scale(-1)").unwrap (),
assert_eq! (parse_TransformList ("scale(-1)").unwrap (),
cairo::Matrix::new (-1.0, 0.0, 0.0, -1.0, 0.0, 0.0));
}
#[test]
fn parses_rotate () {
assert_eq! (parse_Rotate ("rotate (30)").unwrap (), make_rotation_matrix (30.0, 0.0, 0.0));
assert_eq! (parse_Rotate ("rotate (30,-1,-2)").unwrap (), make_rotation_matrix (30.0, -1.0, -2.0));
assert_eq! (parse_Rotate ("rotate (30, -1, -2)").unwrap (), make_rotation_matrix (30.0, -1.0, -2.0));
assert_eq! (parse_TransformList ("rotate (30)").unwrap (), make_rotation_matrix (30.0, 0.0, 0.0));
assert_eq! (parse_TransformList ("rotate (30,-1,-2)").unwrap (), make_rotation_matrix (30.0, -1.0, -2.0));
assert_eq! (parse_TransformList ("rotate (30, -1, -2)").unwrap (), make_rotation_matrix (30.0, -1.0, -2.0));
}
fn make_skew_x_matrix (angle_degrees: f64) -> cairo::Matrix {
......@@ -190,12 +190,12 @@ mod parser_tests {
#[test]
fn parses_skew_x () {
assert_eq! (parse_SkewX ("skewX (30)").unwrap (), make_skew_x_matrix (30.0));
assert_eq! (parse_TransformList ("skewX (30)").unwrap (), make_skew_x_matrix (30.0));
}
#[test]
fn parses_skew_y () {
assert_eq! (parse_SkewY ("skewY (30)").unwrap (), make_skew_y_matrix (30.0));
assert_eq! (parse_TransformList ("skewY (30)").unwrap (), make_skew_y_matrix (30.0));
}
#[test]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment