Skip to content

Commit

Permalink
Merge pull request apache#3642 from matthiasblaesing/css_ext
Browse files Browse the repository at this point in the history
Improve CSS Support
  • Loading branch information
matthiasblaesing authored Feb 26, 2022
2 parents 6538d5e + 7639dc8 commit b3d3266
Show file tree
Hide file tree
Showing 19 changed files with 12,223 additions and 12,026 deletions.
6 changes: 2 additions & 4 deletions ide/css.lib/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
<description>Builds, tests, and runs the project org.netbeans.modules.css.lib</description>
<import file="../../nbbuild/templates/projectized.xml"/>

<target name="generate-antlr-parser">
<fail unless="antlr.jar">You must set antlr.jar property pointing to the antlr-x.x-complete.jar</fail>

<target name="generate-antlr-parser" description="Regenerate the CSS parser from the ANTLR3 grammar">
<java classname="org.antlr.Tool" fork="true" failonerror="true">
<!-- use -debug option so the generated parser allows to register an DebugEventListener and hence allow to build a parse tree -->
<arg value="-debug"/>
Expand All @@ -35,7 +33,7 @@
<arg path="src/org/netbeans/modules/css/lib/Css3.g"/>
<classpath>
<pathelement path="${classpath}"/>
<pathelement location="${antlr.jar}"/>
<pathelement location="../../ide/libs.antlr3.runtime/external/antlr-complete-3.5.2.jar"/>
</classpath>
</java>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ public void setParent(Tree t) {
}

@Override
@SuppressWarnings(value="unchecked") //antlr 3.3 does not use generics
public List<Node> children() {
List<Node> ch = getChildren();
List<Node> ch = (List<Node>) (List<?>) getChildren();
return ch == null ? Collections.<Node>emptyList() : ch;
}

Expand Down
26 changes: 15 additions & 11 deletions ide/css.lib/src/org/netbeans/modules/css/lib/Css3.g
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// Rebuild the lexer and parser:
// 1. Update Css3.g
// 2. Update the lexer/parser sources by running
// ant -Dantlr.jar=<PATH_TO_ANTLR3_JAR> generate-antlr-parser
// ant generate-antlr-parser
// from the module directory (ide/css.lib)
// 3. Rerun unittests
// 4. Commit Css3.g together with generated Css3Lexer.java and Css3Parser.java
Expand All @@ -44,7 +44,7 @@ grammar Css3;
//}
@header {
/**
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand Down Expand Up @@ -120,7 +120,7 @@ package org.netbeans.modules.css.lib;
&& input.LT(1).getText().startsWith(prefix);
}
/**
/**
* Use the current stacked followset to work out the valid tokens that
* can follow on from the current point in the parse, then recover by
* eating tokens that are not a member of the follow set we compute.
Expand Down Expand Up @@ -197,7 +197,7 @@ package org.netbeans.modules.css.lib;
}
}

/**
/**
* synces to next RBRACE "}" taking nesting into account
*/
protected void syncToRBRACE(int nest)
Expand Down Expand Up @@ -250,7 +250,7 @@ package org.netbeans.modules.css.lib;
}

@lexer::header {
/**
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand Down Expand Up @@ -596,11 +596,16 @@ webkitKeyframeSelectors
;

page
@init {
boolean semiRequired = false;
}
: PAGE_SYM ws? ( IDENT ws? )? (pseudoPage ws?)?
LBRACE ws?
LBRACE
//the grammar in the http://www.w3.org/TR/css3-page/ says the declaration/margins should be delimited by the semicolon,
//but there's no such char in the examples => making it arbitrary
((propertyDeclaration|margin) ws?)? (SEMI ws? ((propertyDeclaration|margin) ws?)?)*
( ws? ({semiRequired}? (SEMI ws?) | (SEMI ws?)?) (propertyDeclaration{semiRequired=true;}|margin{semiRequired=false;}))*
SEMI?
ws?
RBRACE
;
Expand Down Expand Up @@ -889,10 +894,9 @@ pseudo
)?
)
| {isScssSource()}? sass_interpolation_expression_var
|
( NOT ws? LPAREN ws? (simpleSelectorSequence ws?)? RPAREN )
|
({isLessSource()}? {tokenNameEquals("extend")}? IDENT ws? LPAREN ws? selectorsGroup? RPAREN)
| ( NOT ws? LPAREN ws? ( selectorsGroup ws?)? RPAREN )
| {tokenNameEquals("is") || tokenNameEquals("where")}? ( IDENT ws? LPAREN ws? ( selectorsGroup ws?)? RPAREN )
| ({isLessSource()}? {tokenNameEquals("extend")}? IDENT ws? LPAREN ws? selectorsGroup? RPAREN)
)
;
Expand Down
2,956 changes: 1,478 additions & 1,478 deletions ide/css.lib/src/org/netbeans/modules/css/lib/Css3Lexer.java

Large diffs are not rendered by default.

17,939 changes: 9,080 additions & 8,859 deletions ide/css.lib/src/org/netbeans/modules/css/lib/Css3Parser.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void consumeToken(Token token) {

RuleNode ruleNode = callStack.peek();
TokenNode elementNode = new TokenNode(source, (CommonToken) token);
elementNode.hiddenTokens = this.hiddenTokens;
elementNode.hiddenTokens = (List<Token>) (List<?>) this.hiddenTokens;
hiddenTokens.clear();
ruleNode.addChild(elementNode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1593,4 +1593,31 @@ public void testParseVariable() {
+ "margin: var(--demoVar, 3ex 2em);"
+ "}");
}

public void testParseSelectorListCSS4() {
assertParses("h1:not(.dummy) {}");
assertParses("h1:not( .h2:visible ) {}");
assertParses("h1:not( .h2, .h3:visible ) {}");
assertParses("h1:not(.h2,:visible,h2) {}");
assertParses("h1:not(.h2,:visible, h1 > h2) {}");
assertParses("html|*:not(:link):not(:visited) {}");
assertParses("html|*:not(:link, :visited) {}");
assertParses("*|*:is(:hover, :focus) {}");
assertParses("*|*:is(*:hover, *:focus) {}");
assertParses("a:where(:valid, :unsupported) {}");
assertParses("a:where(:not(:hover)) {text-decoration: none;}");
}

public void testParsePage() {
assertParses("@page { @top-left { content: attr(test) }; color: red; @bottom-center { content: attr(test2) } }");
assertParses("@page { @top-left { content: attr(test) } }");
assertParses("@page { @top-left { content: attr(test); }; }");
assertParses("@page { ; @top-left { content: attr(test) } }");
assertParses("@page { @top-left { content: attr(test) } ; text-align: right }");
assertParses("@page { @top-left { content: attr(test) } text-align: right }");
assertParses("@page { @top-left { content: attr(test) } text-align: right; background-color: green }");
assertParses("@page { @top-center { content: attr(test) } @bottom-center { content: attr(test2) } background-color: red; }");
assertParses("@page { background-color: red; @top-center { content: attr(test) } @bottom-center { content: attr(test2) } }");
assertParses("@page{@top-left{content: attr(test)}}");
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
Name: Antlr
Description: ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions.
Version: 3.4
Version: 3.5.2
License: BSD-antlr-runtime3
Origin: Antlr
URL: http://www.antlr.org

Use of Antlr version 3.4 is governed by the terms of the license below:
URL: http://www.antlr3.org
Files: antlr-runtime-3.5.2.jar, antlr-complete-3.5.2.jar

[The "BSD license"]
Copyright (c) 2010 Terence Parr
Expand Down Expand Up @@ -34,7 +33,3 @@ Use of Antlr version 3.4 is governed by the terms of the license below:
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.




3 changes: 2 additions & 1 deletion ide/libs.antlr3.runtime/external/binaries-list
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
8F011408269A8E42B8548687E137D8EEB56DF4B4 org.antlr:antlr-runtime:3.4
CD9CD41361C155F3AF0F653009DCECB08D8B4AFD org.antlr:antlr-runtime:3.5.2
7ABF224F627594A3F4AE37FCFFF296730F3F4EDD org.antlr:antlr-complete:3.5.2
4 changes: 2 additions & 2 deletions ide/libs.antlr3.runtime/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

is.autoload=true
javac.source=1.6
release.external/antlr-runtime-3.4.jar=modules/ext/antlr-runtime-3.4.jar
release.external/antlr-runtime-3.5.2.jar=modules/ext/antlr-runtime-3.5.2.jar

license.file=../external/antlr-3.4-license.txt
license.file=../external/antlr-3.5.2-license.txt
nbm.homepage=http://www.antlr.org/
sigtest.gen.fail.on.error=false
spec.version.base=1.37.0
4 changes: 2 additions & 2 deletions ide/libs.antlr3.runtime/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<package>org.antlr.runtime.tree</package>
</public-packages>
<class-path-extension>
<runtime-relative-path>ext/antlr-runtime-3.4.jar</runtime-relative-path>
<binary-origin>external/antlr-runtime-3.4.jar</binary-origin>
<runtime-relative-path>ext/antlr-runtime-3.5.2.jar</runtime-relative-path>
<binary-origin>external/antlr-runtime-3.5.2.jar</binary-origin>
</class-path-extension>
</data>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.


OpenIDE-Module-Name=Antlr 3.3 Runtime
OpenIDE-Module-Name=Antlr 3 Runtime
OpenIDE-Module-Short-Description=Antlr Runtime Libraries
OpenIDE-Module-Long-Description=Contains Antlr 3.3 runtime libraries
OpenIDE-Module-Display-Category=Libraries
Expand Down
16 changes: 16 additions & 0 deletions java/java.api.common/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,21 @@
-->
<project basedir="." default="build" name="java/java.api.common">
<import file="../../nbbuild/templates/projectized.xml"/>

<target name="generate-antlr-parser" description="Regenerate the CSS parser from the ANTLR3 grammar">
<java classname="org.antlr.Tool" fork="true" failonerror="true">
<arg value="-verbose"/>
<arg value="-o"/>
<arg path="src/org/netbeans/modules/java/api/common/project/ui/customizer/vmo/gen/"/>
<arg path="src/org/netbeans/modules/java/api/common/project/ui/customizer/vmo/gen/CommandLine.g"/>
<classpath>
<pathelement path="${classpath}"/>
<pathelement location="../../ide/libs.antlr3.runtime/external/antlr-complete-3.5.2.jar"/>
</classpath>
</java>

<!-- delete the not necessary generated file -->
<delete verbose="false" file="src/org/netbeans/modules/java/api/common/project/ui/customizer/vmo/gen/CommandLine.tokens" failonerror="false"/>
</target>
</project>

Loading

0 comments on commit b3d3266

Please sign in to comment.