Skip to content

Commit

Permalink
wip parser, lexer experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
haidubogdan committed Nov 7, 2024
1 parent 0abd2c1 commit 303c623
Show file tree
Hide file tree
Showing 85 changed files with 12,248 additions and 13,401 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CHANGELOG_PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

## What's changed

**syntax highlighting**
**Don't install this**

- fix issue #67 broken highlighting for `@continue, @break, ...` directives
checking compatiblity with older IDE versions
7 changes: 5 additions & 2 deletions .github/workflows/nbm_prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ name: netbeans-nbm-prerelease

on:
workflow_dispatch:

inputs:
tag-version:
required: true
type: string
jobs:
build:

Expand Down Expand Up @@ -58,7 +61,7 @@ jobs:
draft: false
prerelease: true
release_name: Netbeans Blade Php pre-release ${{ steps.nbm_version.outputs.version }}
tag_name: prenbpr1.0.9
tag_name: ${{ inputs.tag-version }}
body_path: .github/workflows/CHANGELOG_PRERELEASE.md
- name: upload nbm artifact
uses: actions/upload-release-asset@v1
Expand Down
14 changes: 5 additions & 9 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
- selection actions ??
- variable include completion

**mess detection**

- navigator
- if block

**code duplication**

- directive completion and brace matcher
Expand Down Expand Up @@ -46,10 +41,11 @@ laravel specific

- php storm block type doc

**lexer**
---

- avoid using php embedding for identifier Strings
erros to display

**tests**
```
@if() should notify error
```

- unit tests??
10 changes: 10 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<target name="generate-antlr-parser" description="Regenerate the ANTLRv4 parser" depends="init">
<property name="v10.outdir" location="${src.dir}/org/netbeans/modules/php/blade/syntax/antlr4/v10"/>
<property name="formatter.outdir" location="${src.dir}/org/netbeans/modules/php/blade/syntax/antlr4/formatter"/>
<property name="php.outdir" location="${src.dir}/org/netbeans/modules/php/blade/syntax/antlr4/php"/>

<java classname="org.antlr.v4.Tool" fork="true" dir="${v10.outdir}">
<arg value="-o"/>
Expand All @@ -27,9 +28,18 @@
<arg value="BladeAntlrFormatterLexer.g4"/>
<arg value="BladeAntlrFormatterParser.g4"/>
</java>

<java classname="org.antlr.v4.Tool" fork="true" dir="${php.outdir}">
<arg value="-o"/>
<arg value="${php.outdir}"/>
<arg value="BladePhpAntlrLexer.g4"/>
<arg value="BladePhpAntlrParser.g4"/>
</java>
<delete dir="${v10.outdir}" includes="*.tokens"/>
<delete dir="${v10.outdir}" includes="*.interp"/>
<delete dir="${formatter.outdir}" includes="*.tokens"/>
<delete dir="${formatter.outdir}" includes="*.interp"/>
<delete dir="${php.outdir}" includes="*.tokens"/>
<delete dir="${php.outdir}" includes="*.interp"/>
</target>
</project>
2 changes: 1 addition & 1 deletion manifest.mf
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ OpenIDE-Module: php.blade
OpenIDE-Module-Implementation-Version: 2
OpenIDE-Module-Layer: org/netbeans/modules/php/blade/resources/layer.xml
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/blade/resources/Bundle.properties
OpenIDE-Module-Specification-Version: 2.5.0.8
OpenIDE-Module-Specification-Version: 3.0.0.3

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.php.blade.csl.elements;

import java.util.HashSet;
import java.util.Set;
import org.netbeans.modules.csl.api.ElementHandle;
import org.netbeans.modules.csl.api.ElementKind;
import org.netbeans.modules.csl.api.Modifier;
import org.netbeans.modules.csl.api.OffsetRange;
import org.netbeans.modules.csl.spi.ParserResult;
import org.netbeans.modules.php.blade.editor.BladeLanguage;
import org.openide.filesystems.FileObject;

/**
*
* @author bogdan
*/
public class PhpKeywordElement implements ElementHandle {

private final String name;

public PhpKeywordElement(String name, String description){
this.name = name;
}

@Override
public String getName() {
return name;
}

@Override
public FileObject getFileObject() {
return null;
}

@Override
public String getMimeType() {
return BladeLanguage.MIME_TYPE;
}

@Override
public String getIn() {
return "";
}

@Override
public ElementKind getKind() {
return ElementKind.KEYWORD;
}

@Override
public Set<Modifier> getModifiers() {
return new HashSet<>();
}

@Override
public boolean signatureEquals(ElementHandle eh) {
return false;
}

@Override
public OffsetRange getOffsetRange(ParserResult pr) {
return OffsetRange.NONE;
}

}
30 changes: 12 additions & 18 deletions src/org/netbeans/modules/php/blade/editor/BladeBracesMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ public int[] findOrigin() throws InterruptedException, BadLocationException {
int start = currentToken.getStartIndex();
int end = currentToken.getStopIndex();

String tokenText = originToken.getText();
String tokenText = originToken.getText().trim();

if (!tokenText.startsWith("@")
&& !tokenText.startsWith("{")
&& !tokenText.endsWith("}")) {
if (!tokenText.startsWith("@") //NOI18N
&& !tokenText.startsWith("{") //NOI18N
&& !tokenText.endsWith("}")) { //NOI18N
return result;
}

currentDirection = findBraceDirectionType(tokenText, currentToken);
currentDirection = findBraceDirectionType(tokenText);

if (currentDirection.equals(BraceDirectionType.STOP)) {
return result;
Expand All @@ -105,7 +105,7 @@ public int[] findMatches() throws InterruptedException, BadLocationException {
if (originToken == null) {
return result;
}
String tokenText = originToken.getText();
String tokenText = originToken.getText().trim();

switch (currentDirection) {
case CURLY_START_TO_END:
Expand All @@ -127,18 +127,14 @@ public int[] findMatches() throws InterruptedException, BadLocationException {

private static boolean shouldLookForBraceMatch(@NonNull Token currentToken) {
switch (currentToken.getType()) {
case HTML:
case PHP_EXPRESSION:
case AT:
case BLADE_COMMENT:
case ERROR:
return false;
}

return true;
}

public BraceDirectionType findBraceDirectionType(String tokenText, Token token) {
public BraceDirectionType findBraceDirectionType(String tokenText) {
boolean isCloseTag = Arrays.asList(BladeTagsUtils.outputCloseTags()).indexOf(tokenText) >= 0;

if (isCloseTag) {
Expand All @@ -151,8 +147,8 @@ public BraceDirectionType findBraceDirectionType(String tokenText, Token token)
return BraceDirectionType.CURLY_START_TO_END;
}

if (tokenText.startsWith("@end") || tokenText.equals("@show")) {
if (BladeLexerUtils.isUndefinedDirective(token)) {
if (tokenText.startsWith("@end") || tokenText.equals("@show")) { //NOI18N
if (BladeLexerUtils.isUndefinedDirective(tokenText)) {
return BraceDirectionType.CUSTOM_END_TO_START;
}
return BraceDirectionType.END_TO_START;
Expand All @@ -162,7 +158,7 @@ public BraceDirectionType findBraceDirectionType(String tokenText, Token token)
return BraceDirectionType.START_TO_END;
}

if (BladeLexerUtils.isUndefinedDirective(token)) {
if (BladeLexerUtils.isUndefinedDirective(tokenText)) {
return BraceDirectionType.CUSTOM_START_TO_END;
}

Expand All @@ -172,7 +168,6 @@ public BraceDirectionType findBraceDirectionType(String tokenText, Token token)
public int[] findOpenTag() {
int matchTokenType = BladeAntlrUtils.getTagPairTokenType(originToken.getType());
List<Integer> skipableTokenTypes = new ArrayList<>();
skipableTokenTypes.add(HTML);
Token startToken = BladeAntlrUtils.findBackwardWithStop(context.getDocument(),
originToken,
matchTokenType,
Expand All @@ -190,7 +185,6 @@ public int[] findOpenTag() {
public int[] findCloseTag() {
int matchTokenType = BladeAntlrUtils.getTagPairTokenType(originToken.getType());
List<Integer> skipableTokenTypes = new ArrayList<>();
skipableTokenTypes.add(HTML);
Token endToken = BladeAntlrUtils.findForwardWithStop(context.getDocument(),
originToken,
matchTokenType,
Expand Down Expand Up @@ -237,7 +231,7 @@ public int[] findDirectiveEnd(String directive) {
}

public int[] findCustomDirectiveEnd(String directive) {
String[] pair = new String[]{"@end" + directive.substring(1)};
String[] pair = new String[]{"@end" + directive.substring(1)}; //NOI18N
Set<String> stopDirectives = new HashSet<>( Arrays.asList(pair));
Set<String> startDirectiveForBalance = new HashSet<>();
startDirectiveForBalance.add(directive);
Expand All @@ -257,7 +251,7 @@ public int[] findCustomDirectiveEnd(String directive) {
}

public int[] findCustomDirectiveStart(String directive) {
String[] pair = new String[]{"@" + directive.substring(4)};
String[] pair = new String[]{"@" + directive.substring(4)}; //NOI18N
Set<String> stopDirectives = new HashSet<>(Arrays.asList(pair));
Set<String> startDirectiveForBalance = new HashSet<>();
startDirectiveForBalance.add(directive);
Expand Down
Loading

0 comments on commit 303c623

Please sign in to comment.