Skip to content

Commit

Permalink
[CSS] Separate URL token and URL function (fixes antlr#3583)
Browse files Browse the repository at this point in the history
  • Loading branch information
ris58h committed Jul 4, 2023
1 parent 2da95a5 commit 0602643
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
9 changes: 4 additions & 5 deletions css3/css3Lexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ fragment Name
: Nmchar+
;
fragment Url
: ( [!#$%&*-~] | Nonascii | Escape )*
Url
: U R L '(' Whitespace ( [!#$%&*-~] | Nonascii | Escape )* Whitespace ')'
;
Space
Expand Down Expand Up @@ -374,9 +374,8 @@ Percentage
: Number '%'
;
Uri
: U R L '(' Whitespace String_ Whitespace ')'
| U R L '(' Whitespace Url Whitespace ')'
Url_
: 'url('
;
UnicodeRange
Expand Down
23 changes: 15 additions & 8 deletions css3/css3Parser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ charset
;

imports
: Import ws ( String_ | Uri ) ws mediaQueryList ';' ws # goodImport
| Import ws ( String_ | Uri ) ws ';' ws # goodImport
| Import ws ( String_ | Uri ) ws mediaQueryList # badImport
| Import ws ( String_ | Uri ) ws # badImport
: Import ws ( String_ | url ) ws mediaQueryList ';' ws # goodImport
| Import ws ( String_ | url ) ws ';' ws # goodImport
| Import ws ( String_ | url ) ws mediaQueryList # badImport
| Import ws ( String_ | url ) ws # badImport
;

// Namespaces
// https://www.w3.org/TR/css-namespaces-3/
namespace_
: Namespace ws (namespacePrefix ws)? ( String_ | Uri ) ws ';' ws # goodNamespace
| Namespace ws (namespacePrefix ws)? ( String_ | Uri ) ws # badNamespace
: Namespace ws (namespacePrefix ws)? ( String_ | url ) ws ';' ws # goodNamespace
| Namespace ws (namespacePrefix ws)? ( String_ | url ) ws # badNamespace
;

namespacePrefix
Expand Down Expand Up @@ -193,7 +193,7 @@ term
| UnicodeRange ws # knownTerm
| ident ws # knownTerm
| var_ # knownTerm
| Uri ws # knownTerm
| url ws # knownTerm
| hexcolor # knownTerm
| calc # knownTerm
| function_ # knownTerm
Expand Down Expand Up @@ -238,7 +238,7 @@ any_
| unknownDimension ws
| String_ ws
//| Delim ws // Not implemented yet
| Uri ws
| url ws
| Hash ws
| UnicodeRange ws
| Includes ws
Expand Down Expand Up @@ -325,6 +325,13 @@ generalEnclosed
: ( Function_ | '(' ) ( any_ | unused )* ')'
;

// Url
// https://www.w3.org/TR/css3-values/#urls
url
: Url_ ws String_ ws ')'
| Url
;

// Variable
// https://www.w3.org/TR/css-variables-1
var_
Expand Down

0 comments on commit 0602643

Please sign in to comment.