forked from antlr/grammars-v4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
grammar css3; | ||
|
||
stylesheet | ||
: importRule* (nested | ruleset)+ | ||
; | ||
|
||
importRule | ||
: ('@import' | '@include') STRING | ||
; | ||
|
||
nested | ||
: '@' nest '{' properties? nested* '}' | ||
; | ||
|
||
nest | ||
: IDENT IDENT* pseudo* | ||
; | ||
|
||
ruleset | ||
: selectors '{' properties? '}' | ||
; | ||
|
||
selectors | ||
: selector (',' selector)* | ||
; | ||
|
||
selector | ||
: elem selectorOperation* attrib* pseudo? | ||
; | ||
|
||
selectorOperation | ||
: selectop? elem | ||
; | ||
|
||
selectop | ||
: '>' | ||
| '+' | ||
; | ||
|
||
properties | ||
: declaration (';' declaration?)* | ||
; | ||
|
||
elem | ||
: IDENT | ||
| '#' IDENT | ||
| '.' IDENT | ||
; | ||
|
||
pseudo | ||
: (':'|'::') IDENT | ||
| (':'|'::') function | ||
; | ||
|
||
attrib | ||
: '[' IDENT (attribRelate (STRING | IDENT))? ']' | ||
; | ||
|
||
attribRelate | ||
: '=' | ||
| '~=' | ||
| '|=' | ||
; | ||
|
||
declaration | ||
: IDENT ':' args | ||
; | ||
|
||
args | ||
: expr (','? expr)* | ||
; | ||
|
||
expr | ||
: (NUM unit?) | ||
| IDENT | ||
| COLOR | ||
| STRING | ||
| function | ||
; | ||
|
||
unit | ||
: ('%'|'px'|'cm'|'mm'|'in'|'pt'|'pc'|'em'|'ex'|'deg'|'rad'|'grad'|'ms'|'s'|'hz'|'khz') | ||
; | ||
|
||
function | ||
: IDENT '(' args? ')' | ||
; | ||
|
||
IDENT | ||
: ('_' | 'a'..'z'| 'A'..'Z' | '\u0100'..'\ufffe' ) | ||
('_' | '-' | 'a'..'z'| 'A'..'Z' | '\u0100'..'\ufffe' | '0'..'9')* | ||
| '-' ('_' | 'a'..'z'| 'A'..'Z' | '\u0100'..'\ufffe' ) | ||
('_' | '-' | 'a'..'z'| 'A'..'Z' | '\u0100'..'\ufffe' | '0'..'9')* | ||
; | ||
|
||
STRING | ||
: '"' (~('"'|'\n'|'\r'))* '"' | ||
| '\'' (~('\''|'\n'|'\r'))* '\'' | ||
; | ||
|
||
NUM | ||
: '-' (('0'..'9')* '.')? ('0'..'9')+ | ||
| (('0'..'9')* '.')? ('0'..'9')+ | ||
; | ||
|
||
COLOR | ||
: '#' ('0'..'9'|'a'..'f'|'A'..'F')+ | ||
; | ||
|
||
SL_COMMENT | ||
: '//' (~('\n'|'\r'))* ('\n'|'\r'('\n')?) ->skip | ||
; | ||
|
||
COMMENT | ||
: '/*' .* '*/' ->skip | ||
; | ||
|
||
WS : ( ' ' | '\t' | '\r' | '\n' | '\f' )+ ->skip | ||
; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
body { | ||
color: #000000; | ||
} | ||
h1 { | ||
color: #ff0000; | ||
} | ||
p { | ||
color: #00ff00; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
body { | ||
font-family: Arial, Helvetica, sans-serif; | ||
} | ||
h1 { | ||
font-family: "Times New Roman", Times, serif; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>CSS3</artifactId> | ||
<packaging>jar</packaging> | ||
<name>CSS3 grammar</name> | ||
<parent> | ||
<groupId>com.antlr.grammarsv4</groupId> | ||
<artifactId>grammarsv4</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.antlr</groupId> | ||
<artifactId>antlr4-maven-plugin</artifactId> | ||
<version>${antlr.version}</version> | ||
<configuration> | ||
<sourceDirectory>${basedir}</sourceDirectory> | ||
<grammars>css3.g4</grammars> | ||
<visitor>true</visitor> | ||
<listener>true</listener> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>antlr4</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.khubla.antlr</groupId> | ||
<artifactId>antlr4test-maven-plugin</artifactId> | ||
<version>${antlr4test-maven-plugin.version}</version> | ||
<configuration> | ||
<verbose>false</verbose> | ||
<showTree>false</showTree> | ||
<entryPoint>stylesheet</entryPoint> | ||
<grammarName>css3</grammarName> | ||
<packageName></packageName> | ||
<exampleFiles>examples/</exampleFiles> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
trihus Tue Jul 1, 2008 13:43 | ||
This CSS parser handles valid CSS syntax. It will also accept property values not defined by CSS without giving an error. It has been debugged with ANTLRWorks and tested on a number of CSS files. (You must comment out language=CSharp for it to work with ANTLRWorks). I don't think it handles the full syntax of @import or @include. | ||
|
||
Forward ported from Antlr3 to Antlr4 by Tom Everett. April 2017. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters