$rules = []
def rule *args
  keywords = args.slice!(-1)
  args.each do |pattern|
    $rules << [pattern, keywords[:code], keywords[:weight]]
  end
end

rule %r{Using <code>windows-1252</code> instead of the declared encoding},
     :code => :encoding_warning, :weight => 0

rule %r{Changing character encoding <code>utf-8</code> and reparsing},
     :code => :encoding_warning, :weight => 0

rule %r{Bad value <code>\d+\.\d+</code> for attribute <code>content</code> on element .*<code>meta</code>},
     %r{Bad value <code>\d+;url=.*</code> for attribute <code>content</code> on element .*<code>meta</code>},
     :code => :meta_refresh, :weight => 10

rule %r{Obsolete doctype\.},
     %r{Legacy doctype\.},
     %r{Quirky doctype\.},
     %r{skipping entity: \[dtd\]},
     %r{Almost standards mode doctype\.},
     :code => :versioned_doctype, :weight => 15

rule %r{Self-closing syntax \(<code>/\&gt;</code>\) used on a non-void HTML element},
     :code => :self_closing_where_closing_is_optional, :weight => 16

rule %r{Start tag seen without seeing a doctype first\.},
     :code => :missing_doctype, :weight => 19

rule %r{not allowed as child of element .*<span},
     :code => :span_semantics, :weight => 20

rule %r{End of file seen and there were open elements},
     :code => :optional, :weight => 25

rule %r{[Cc]onsecutive hyphens},
     %r{trailing hyphen in a comment},
     :code => :consecutive_hyphens, :weight => 28

rule %r{<code>=</code> in an unquoted attribute value},
     %r{No space between the doctype public and system identifiers},
     :code => :unquoted_equals, :weight => 28

rule %r{No space between attributes},
     :code => :no_space, :weight => 29

rule %r{Attribute <code>y-},
     %r{Attribute <code>_sp},
     :code => :extensibility_prefix, :weight=>35

rule %r{Attribute <code>xmlns:.*</code> not allowed here},
     %r{local name <code>xmlns:.*</code> is not serializable as XML 1.0},
     %r{Attribute <code>xmlns</code> is not serializable as XML 1.0},
     :code => :extensibility_xmlns, :weight=>36

rule %r{Bad value <code>.*</code> for attribute <code>http-equiv</code>},
     :code => :extensibility_meta, :weight=>38

rule %r{Element .*<code>script<.* not allowed as child of element <},
     %r{Stray <code>script</code> start tag},
     :code => :script_anywhere, :weight=>39

rule %r{unnamed script},
     :code => :unnamed_script, :weight=>40

rule %r{Presentational_elements_and_attributes},
     :code => :css, :weight => 45

rule %r{Required attributes missing on element .*<code>link},
     %r{Required attributes missing on element .*<code>area},
     %r{Required attributes missing on element .*<code>style},
     %r{Required attributes missing on element .*<code>script},
     :code => :optional_attrs, :weight => 46

rule %r{<code>center</code>},
     :code => :css, :weight => 45

rule %r{attribute on the .* element is obsolete},
     %r{The <code>Content-Language</code> state is obsolete},
     %r{The .* attribute is obsolete},
     %r{The .* element is obsolete},
     :code => :versioned, :weight => 45

# http://www.aptana.com/reference/html/api/HTML.field.vspace.html
rule %r{Attribute <code>border</code> not allowed on element},
     %r{Attribute <code>color</code> not allowed on element .*<code>hr<},
     %r{Attribute <code>background</code> not allowed on element},
     %r{Attribute <code>hspace</code> not allowed on element},
     %r{Attribute <code>vspace</code> not allowed on element},
     %r{Attribute <code>height</code> not allowed on element},
     :code => :versioned, :weight => 45

# http://www.aptana.com/reference/html/api/HTML.field.allowtransparency.html
rule %r{Attribute <code>allowtransparency</code> not allowed on element},
     :code => :browser_specific_markup, :weight => 45

rule %r{Attribute <code>marginheight</code> not allowed on element},
     %r{Attribute <code>leftmargin</code> not allowed on element},
     %r{Attribute <code>marginwidth</code> not allowed on element},
     %r{Attribute <code>width</code> not allowed on element},
     %r{Attribute <code>topmargin</code> not allowed on element},
     %r{Attribute <code>onpropertychange</code> not allowed on element},
     :code => :nonstd_attribute, :weight => 46

# http://msdn.microsoft.com/en-us/library/ms533486(VS.85).aspx
# https://developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion
rule %r{Attribute <code>autocomplete</code> not allowed on element},
     :code => :nonnstd_element, :weight=>49

rule %r{<code>nobr</code>},
     :code => :nonstd_element, :weight => 49

rule %r{<code>&amp;</code> did not start a character reference},
     :code => :escape, :weight => 55

rule %r{No .* element in list scope but a .* end tag seen},
     %r{Stray end tag <code>},
     %r{No element <code>font</code> to close},
     %r{No element <code>a</code> to close},
     %r{violates nesting rules},
     %r{End tag <code>.*</code> seen but there were unclosed elements},
     %r{End tag for <code>.*</code> seen, but there were unclosed elements},
     :code => :unmatched_close, :weight => 65

rule %r{A table row was \d+ columns wide, which is less than the column count established by the first row},
     %r{A table row was \d+ columns wide and exceeded the column count established by the first row},
     %r{Table column \d+ .* has no cells beginning in it},
     :code => :table_width, :weight => 71

rule %r{COMPATIBILITY_CHARACTER in PATH\.},
     :code => :compat_char, :weight => 74

rule %r{The character encoding <code>.*</code> is not widely supported},
     %r{Using <code>gbk</code> instead of the declared encoding},
     :code => :char_encoding, :weight => 73
     
rule %r{Bad value <code> +http:.*? for attribute <code>href},
     %r{Bad value <code> +http:.*? for attribute <code>src},
     %r{<code>href</code> on element .*<code>a<.*: DOUBLE_WHITESPACE},
     %r{<code>href</code> on element .*<code>area<.*: DOUBLE_WHITESPACE},
     %r{<code>src</code> on element .*<code>img<.*: DOUBLE_WHITESPACE},
     %r{<code>href</code> on element .*<code>a<.*: CONTROL_CHARACTER},
     %r{<code>href</code> on element .*<code>a<.*: WHITESPACE in QUERY},
     %r{<code>src</code> on element .*<code>img<.*: WHITESPACE in PATH},
     :code => :urispace, :weight => 75

rule %r{Zero is not a positive integer},
     :code => :nonpositive, :weight => 79

rule %r{An ID must not be the empty string},
     :code => :empty_id, :weight => 81

rule %r{Duplicate ID <code>.*</code>},
     %r{The first occurrence of ID <code>.*</code> was here},
     :code => :dup_id, :weight => 82

rule %r{Browsing context name must be at least one character long},
     :code => :empty_target, :weight => 83

rule %r{An ID must not contain whitespace},
     :code => :id_whitespace, :weight => 83

rule %r{Attribute <code>modid},
     %r{Attribute <code>data},
     %r{Attribute <code>image</code> not allowed on element .*<code>img<},
     %r{Attribute <code>defaulturl</code> not allowed on element .*<code>form<},
     %r{Attribute <code>url</code> not allowed on element .*<code>img<},
     %r{Attribute <code>pos</code> not allowed on element .*<code>a<},
     %r{Attribute <code>qlicon</code> not allowed on element .*<code>img<},
     %r{Attribute <code>thumb</code> not allowed on element .*<code>img<},
     %r{Attribute <code>ql</code> not allowed on element .*<code>button<},
     %r{Attribute <code>smartpid</code> not allowed on element .*<code>input<},
     %r{Attribute <code>articleid</code> not allowed on element .*<code>span<},
     %r{Attribute <code>overflowurl</code> not allowed on element .*<code>span<},
     %r{Attribute <code>src</code> not allowed on element .*<code>span<},
     %r{Attribute <code>alt</code> not allowed on element .*<code>span<},
     %r{Attribute <code>jotid</code> not allowed on element},
     %r{Bad character .* Probable cause: Unescaped},
     :code => :private_extension, :weight => 84

rule %r{An <code>object</code> element must have a <code>data</code> attribute or a <code>type</code> attribute},
     :code => :nonstd_object, :weight => 84

rule %r{Element .*<code>div<.* not allowed as child of element <},
     %r{Element .*<code>n<.* not allowed as child of element <},
     %r{Element .*<code>p<.* not allowed as child of element <},
     %r{Element .*<code>form<.* not allowed as child of element <},
     %r{Element .*<code>style<.* not allowed as child of element <},
     %r{Required children missing from element .*<dl},
     %r{Start tag <code>p</code> seen in <code>table</code>},
     %r{Start tag <code>div</code> seen in <code>table</code>},
     %r{</code> must not appear as a descendant of the <code>},
     %r{An <code>a</code> start tag seen with already an active <code>a</code> element},
     %r{must have an ID value that matches that <code>for</code> attribute},
     %r{The <code>for</code> attribute of the <code>label</code> element must refer to a form control},
     %r{there is no <code>map</code> element with a <code>name</code> attribute with that value},
     :code => :schema, :weight => 85

rule %r{Bad value <code>true</code> for attribute <code>defer</code>},
     %r{Bad value .* for attribute <code>dir</code> on element},
     :code => :bad_attr_value, :weight => 85

rule %r{Bad value <code>.*</code> for the attribute <code>xmlns</code>},
     :code => :bad_xmlns, :weight => 89

# rule %r{Required attributes missing on element},
rule %r{An <code>img</code> element must have a <code>src</code> attribute},
     :code => :required_attrs, :weight => 86

rule %r{Attribute <code>name</code> not allowed on element .*<code>},
     :code => :name_attr, :weight => 87

rule %r{Attribute <code>widh</code> not allowed on element},
     :code => :nonstd_attribute_mispelled, :weight => 88

rule %r{Attribute <code>\w+:[^<]*;[^<]*</code>},
     :code => :style_as_attribute, :weight => 90

rule %r{Attribute <code>;</code>},
     :code => :stray_semicolon, :weight => 91

rule %r{Stray doctype},
     :code => :stray_doctype, :weight => 91

rule %r{Bogus comment},
     :code => :bogus_comment, :weight => 92

rule %r{Forbidden code point},
     :code => :forbidden_code_point, :weight => 93

rule %r{<code>src</code> on element .*<code>img<.*: CONTROL_CHARACTER in PATH},
     :code => :space_in_uri_path, :weight => 94

rule %r{Attribute <code>http:<},
     %r{<code>"</code> in an unquoted attribute value},
     %r{Attribute <code>www\.},
     %r{A slash was not immediate followed by <code>&gt;<},
     :code => :syntax_attr, :weight => 95
      
rule %r{Internal encoding declaration .* disagrees with the actual encoding of the document},
     :code => :encoding_error, :weight=>98
