Skip to content

Commit

Permalink
Merge branch 'v1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
oowekyala committed Apr 28, 2019
2 parents 4b9c0b4 + 3b93fd6 commit 073f88f
Show file tree
Hide file tree
Showing 40 changed files with 608 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/markdown-navigator/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.jetbrains.grammarkit.tasks.GenerateLexer
import org.jetbrains.grammarkit.tasks.GenerateParser
import java.net.URI
import java.nio.file.Files.delete

plugins {
kotlin("jvm") version "1.3.10"
Expand All @@ -17,7 +18,7 @@ val PathToPsiRoot = "$PackageRoot/lang/psi"


group = "com.github.oowekyala"
version = "1.2"
version = "1.3"


ext {
Expand All @@ -40,8 +41,9 @@ dependencies {
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KotlinVersion")
compile("org.apache.commons:commons-lang3:3.1") // only used to unescape java I think
compile("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.1")
implementation(kotlin("reflect"))
// https://mvnrepository.com/artifact/net.java.dev.javacc/javacc
testCompile("com.github.oowekyala.treeutils:tree-matchers:2.0.1")
testCompile("com.github.oowekyala.treeutils:tree-matchers:2.0.2")
testCompile("org.jetbrains.kotlin:kotlin-reflect:$KotlinVersion")
testImplementation("io.kotlintest:kotlintest-runner-junit5:3.1.11")

Expand Down
36 changes: 9 additions & 27 deletions changelog.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
<p>What's new:

<ul>
<li>JJTree and JavaCC grammars now are more clearly cut. Before this release, *.jjt and *.jj
files were both treated as JJTree grammars (because JJTree is a clean superset of JavaCC),
and features of JJTree insight were always available. For reasons of code organisation and
to enable better error reporting, the JJTree features are now only enabled in *.jjt files,
usage in *.jj files raise an error and a suggestion to rename the file. You can configure
different file patterns in <b>Settings | Editor | File Types</b>.
</li>
<li>A bunch of features:
<ul>
<li>Links to the grammar for a JJTree node from their corresponding Java node class
if it can be found in the project.</li>
<li>Link from the parser file to the grammar.</li>
<li>Completion suggestions for regex productions, options, and lexical states</li>
<li>Options are now documented.</li>
<li>JJTree inline node declarations are now in the structure view</li>
<li>Prettier icons; the file icons are based on a JavaCC logo</li>
<li>Folding of code generated by JJTree in .jj files (<code>@bgen</code> sections)</li>
<li>Find usages, completion, and summary documentation for lexical states</li>
<li>Implicit tokens now also have a link in the documentation of BNF expansions</li>
<li>Some performance optimisations</li>
</ul>
</li>
<li>Gutter link from productions to their parser method, and vice-versa</li>
<li>Code folding can now be disabled selectively in <i>Editor > General > Code Folding</i></li>
</ul>

<p>What's changed:
<ul>
<li>Suppression IDs of inspections now don't have the "JavaCC" prefix unless they collide with another inspection</li>
</ul>

<p>What's fixed:
<ul>
<li>Parser tolerance to incomplete code has been significantly improved. Starting to type a new production should
now never break the rest of the grammar</li>
<li>Completion result insertion making a mess when the tail characters are already present</li>
<li>Unnecessary parentheses inspection wasn't initialised correctly</li>
<li>Rename refactoring was broken since 1.1. There are still some things to do to make it smarter.</li>
<li>Invoking the Rename action on a JJTree node descriptor now renames all instances of the name in the grammar</li>
<li>The suppression ID of UnusedProduction was "JavaCCJccUnusedProduction"</li>
</ul>
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-rc-1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
18 changes: 17 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed 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.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down
18 changes: 17 additions & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem http://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
Expand All @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
12 changes: 7 additions & 5 deletions intellij-javacc.iml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sandbox/PldocAST.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

*/

package net.sourceforge.pmd.lang.plsql.ast;


import java.io.*;
import net.sourceforge.pmd.lang.ast.Node;
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/com/github/oowekyala/ijcc/icons/JccIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ enum class JccIcons(icon: Icon) : Icon by icon {
// other
/** For [com.github.oowekyala.ijcc.ide.gutter.JjtreeNodeClassLineMarkerProvider]. */
GUTTER_NODE_CLASS(AllIcons.Gutter.OverridenMethod),
GUTTER_PARSER_METHOD(AllIcons.Gutter.ImplementedMethod),
/** For [com.github.oowekyala.ijcc.ide.gutter.JjtreePartialDeclarationLineMarkerProvider]. */
GUTTER_PARTIAL_DECL("jjtreeNodeLocate.svg"),
GUTTER_NAVIGATE_TO_GRAMMAR("jccNavigateToGrammar.svg"),
GUTTER_NAVIGATE_TO_PRODUCTION(GUTTER_NAVIGATE_TO_GRAMMAR),
GUTTER_NAVIGATE_TO_JJTREE_NODE("jccNavigateToNode.svg"),
GUTTER_RECURSION(AllIcons.Gutter.RecursiveMethod),
/** File type icon. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.github.oowekyala.ijcc
package com.github.oowekyala.ijcc.ide.folding

import com.github.oowekyala.ijcc.ide.folding.JccFoldingBuilder.Companion.FolderVisitor.Companion.BGEN_PATTERN
import com.github.oowekyala.ijcc.lang.psi.*
import com.github.oowekyala.ijcc.settings.globalPluginSettings
import com.intellij.lang.ASTNode
import com.intellij.lang.folding.CustomFoldingBuilder
import com.intellij.lang.folding.FoldingDescriptor
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Document
import com.intellij.openapi.editor.FoldingGroup
import com.intellij.openapi.util.TextRange
import com.intellij.psi.JavaTokenType
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.TokenType
import com.intellij.psi.javadoc.PsiDocComment


/**
Expand Down Expand Up @@ -40,15 +44,32 @@ class JccFoldingBuilder : CustomFoldingBuilder() {

private fun TextRange.isProperTextRange() = startOffset in 0..endOffset

override fun isRegionCollapsedByDefault(node: ASTNode): Boolean = when (node.psi) {
is JccNonTerminalProduction -> false
else -> true
override fun isRegionCollapsedByDefault(node: ASTNode): Boolean {
val opts = globalPluginSettings
return when (val psi = node.psi) {
is JccNonTerminalProduction -> false
is JccOptionSection -> opts.isFoldOptions
is JccParserDeclaration -> opts.isFoldParserDecl
is JccTokenManagerDecls -> opts.isFoldTokenMgrDecl
is JccRegexProduction -> opts.isFoldTokenProds
is JccJavaBlock,
is JccParserActionsUnit -> opts.isFoldJavaFragments
is JccLocalLookaheadUnit -> opts.isFoldLookaheads
is PsiComment ->
psi.text.matches(BGEN_PATTERN) && opts.isFoldBgenSections
else -> true
}
}

override fun getLanguagePlaceholderText(node: ASTNode, range: TextRange): String {
val psi = node.psi
return when (psi) {
is PsiComment -> node.text // start comment of a generated section
is PsiComment ->
when {
// start comment of a generated section
node.text.matches(BGEN_PATTERN) -> node.text
else -> "/*...*/"
}
is JccTokenReferenceRegexUnit -> literalRegexForRef(psi)!!.stringLiteral.text
is JccParserDeclaration -> "/PARSER DECLARATION/"
is JccTokenManagerDecls -> "/TOKEN MANAGER DECLARATIONS/"
Expand Down Expand Up @@ -88,6 +109,9 @@ class JccFoldingBuilder : CustomFoldingBuilder() {
* Collects all folded regions in the file.
*/
private class FolderVisitor(val result: MutableList<FoldingDescriptor>) : DepthFirstVisitor() {

val opts = globalPluginSettings

// all java blocks in the same bnf production belong in the same group
private var currentJBlockGroup: FoldingGroup? = null
// all lookaheads in the same bnf production belong in the same group
Expand All @@ -100,14 +124,16 @@ class JccFoldingBuilder : CustomFoldingBuilder() {
private var inGenSection: Boolean = false

override fun visitTokenReferenceRegexUnit(o: JccTokenReferenceRegexUnit) {
if (!opts.isFoldTokenRefs) return

val ref = literalRegexForRef(o)
if (ref != null) {
result += FoldingDescriptor(o, o.textRange)
}
}

override fun visitComment(comment: PsiComment) {
if (comment.text.matches(BEGEN_PATTERN)) {
if (comment.text.matches(BGEN_PATTERN)) {
val startOffset = comment.textOffset
val end = comment.containingFile.text.indexOf(EGEN, startIndex = startOffset + comment.textLength)
val endOffset = end + EGEN.length
Expand All @@ -117,6 +143,9 @@ class JccFoldingBuilder : CustomFoldingBuilder() {
inGenSection = false
}

if (comment.node.elementType != JavaTokenType.END_OF_LINE_COMMENT) {
result += FoldingDescriptor(comment, comment.textRange)
}
}

override fun visitRegexProduction(o: JccRegexProduction) {
Expand Down Expand Up @@ -185,16 +214,24 @@ class JccFoldingBuilder : CustomFoldingBuilder() {
if (elt.textLength > 2) { // not just "{}"
result +=
when {
inGenSection -> FoldingDescriptor(elt.node, trimWhitespace(elt), jjtreeGenGroup)
currentJBlockGroup != null -> FoldingDescriptor(elt.node, trimWhitespace(elt), currentJBlockGroup)
inGenSection -> FoldingDescriptor(
elt.node,
trimWhitespace(elt),
jjtreeGenGroup
)
currentJBlockGroup != null -> FoldingDescriptor(
elt.node,
trimWhitespace(elt),
currentJBlockGroup
)
else -> FoldingDescriptor(elt, trimWhitespace(elt))
}
}
}

companion object {
private val BEGEN_PATTERN = Regex("""/\*@bgen\(\w++\).*\*/""")
private const val EGEN = "/*@egen*/"
val BGEN_PATTERN = Regex("""/\*@bgen\(\w++\).*\*/""")
const val EGEN = "/*@egen*/"

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.oowekyala.ijcc.ide.folding

import com.github.oowekyala.ijcc.settings.JccGlobalSettingsState
import com.github.oowekyala.ijcc.settings.globalPluginSettings
import com.intellij.application.options.editor.CodeFoldingOptionsProvider
import com.intellij.openapi.options.BeanConfigurable
import com.intellij.openapi.util.Getter
import com.intellij.openapi.util.Setter
import kotlin.reflect.KMutableProperty

/**
* @author Clément Fournier
*/
class JccFoldingOptionsProvider :
BeanConfigurable<JccGlobalSettingsState>(globalPluginSettings), CodeFoldingOptionsProvider {

init {

checkBox("foldJavaFragments", "Java fragments in JavaCC code")
checkBox("foldLookaheads", "JavaCC local lookahead declarations")
checkBox("foldTokenRefs", "JavaCC token references that can be replaced by a string literal")
checkBox("foldOptions", "JavaCC options section")
checkBox("foldParserDecl", "JavaCC parser declaration section")
checkBox("foldTokenMgrDecl", "JavaCC token manager declaration section")
checkBox("foldTokenProds", "JavaCC regular expression productions (token declarations)")
checkBox("foldBgenSections", "Generated sections in .jj files (@bgen ... @egen)")

}

}

0 comments on commit 073f88f

Please sign in to comment.