Skip to content
This repository

clean up regexes for accuracy and internal consistency #376

Closed
wants to merge 1 commit into from

3 participants

Dakota Schneider Neil Williams Max Goodman
Dakota Schneider
Dakta commented March 13, 2012

Not just a separate commit, there's some other changes and improvements to some of the regexes in here to make them better reflect possible acceptable property values.

Max Goodman chromakode commented on the diff March 15, 2012
r2/r2/lib/cssfilter.py
@@ -67,13 +67,13 @@
67 67
     'color': '{x11color}|{csscolor}',
68 68
 
69 69
     'bg-gradient': r'none|{color}|[a-z-]*-gradient\(.*\)',
70  
-    'bg-gradients': r'{bg-gradient}(?:,\s*{bg-gradient})*',
  70
+    'bg-gradients': r'({bg-gradient}{w},{w})*{bg-gradient}',
2
Max Goodman Owner
chromakode added a note March 15, 2012

Why move the optional/*'d portion to the beginning of the regex?

Dakota Schneider
Dakta added a note March 15, 2012

It's purely style-related change for internal consistency. It's done that way in other regexes in the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Max Goodman chromakode commented on the diff March 15, 2012
r2/r2/lib/cssfilter.py
((6 lines not shown))
71 71
 
72  
-    'border-radius': r'(({length}|{percentage}){w}){1,2}',
  72
+    'border-radius': r'(({length}|{percentage}){w}/?{w})?({length}|{percentage})',
1
Max Goodman Owner
chromakode added a note March 15, 2012

It looks like this adds the / radius-width / radius-height. Shorthand. Could you please put it in a separate commit after your cleanup?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Max Goodman chromakode commented on the diff March 15, 2012
r2/r2/lib/cssfilter.py
((9 lines not shown))
73 73
     
74 74
     'single-text-shadow': r'({color}\s+)?{length}\s+{length}(\s+{length})?|{length}\s+{length}(\s+{length})?(\s+{color})?',
75 75
 
76  
-    'box-shadow-pos': r'{length}\s+{length}(\s+{length})?(\s+{length})?',
  76
+    'box-shadow-pos': r'{length}{w}{length}({w}{length})?',
1
Max Goodman Owner
chromakode added a note March 15, 2012

This changes the semantics from required whitespace to optional whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Max Goodman chromakode commented on the diff March 15, 2012
r2/r2/lib/cssfilter.py
@@ -88,7 +88,7 @@
88 88
     'background': r'{bg-gradients}',
89 89
     'background-image': r'{bg-gradients}',
90 90
     'background-color': r'{color}',
91  
-    'background-position': r'(({percentage}|{length}){0,3})?\s*(top|center|left)?\s*(left|center|right)?',
  91
+    'background-position': r'(({percentage}|{length}){w}(left|top|center|right|bottom)?{w}){0,2}',
2
Max Goodman Owner
chromakode added a note March 15, 2012

This makes the ({percentage}|{length}) clause non-optional. This regex matches lengths and sides, whereas I believe the spec requires a length or a side.

http://www.w3.org/TR/CSS21/colors.html#propdef-background-position

Dakota Schneider
Dakta added a note March 15, 2012

Indeed it does, my mistake, forgot a ? in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Neil Williams
Owner

Much of this will be changing around as we upgrade the filter and fix things up. I'm going to close it. Thanks for trying to clean things up!

Neil Williams spladug closed this November 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 13, 2012
Dakota Schneider clean up regexes for accuracy and internal consistency c96cbdf
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 4 additions and 4 deletions. Show diff stats Hide diff stats

  1. 8  r2/r2/lib/cssfilter.py
8  r2/r2/lib/cssfilter.py
@@ -67,13 +67,13 @@
67 67
     'color': '{x11color}|{csscolor}',
68 68
 
69 69
     'bg-gradient': r'none|{color}|[a-z-]*-gradient\(.*\)',
70  
-    'bg-gradients': r'{bg-gradient}(?:,\s*{bg-gradient})*',
  70
+    'bg-gradients': r'({bg-gradient}{w},{w})*{bg-gradient}',
71 71
 
72  
-    'border-radius': r'(({length}|{percentage}){w}){1,2}',
  72
+    'border-radius': r'(({length}|{percentage}){w}/?{w})?({length}|{percentage})',
73 73
     
74 74
     'single-text-shadow': r'({color}\s+)?{length}\s+{length}(\s+{length})?|{length}\s+{length}(\s+{length})?(\s+{color})?',
75 75
 
76  
-    'box-shadow-pos': r'{length}\s+{length}(\s+{length})?(\s+{length})?',
  76
+    'box-shadow-pos': r'{length}{w}{length}({w}{length})?',
77 77
 }
78 78
 
79 79
 custom_values = {
@@ -88,7 +88,7 @@
88 88
     'background': r'{bg-gradients}',
89 89
     'background-image': r'{bg-gradients}',
90 90
     'background-color': r'{color}',
91  
-    'background-position': r'(({percentage}|{length}){0,3})?\s*(top|center|left)?\s*(left|center|right)?',
  91
+    'background-position': r'(({percentage}|{length}){w}(left|top|center|right|bottom)?{w}){0,2}',
92 92
     
93 93
     # http://www.w3.org/TR/css3-background/#border-top-right-radius
94 94
     'border-radius': r'{border-radius}',
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.