Skip to content

Commit

Permalink
Merge pull request #15 from KyrylR/dev
Browse files Browse the repository at this point in the history
Update Grammar
  • Loading branch information
KyrylR authored Nov 15, 2024
2 parents ea955ec + 9a7a937 commit 274a1c4
Show file tree
Hide file tree
Showing 27 changed files with 793 additions and 154 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

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

6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
- [ ] Click the <kbd>Watch</kbd> button on the top of the [IntelliJ Platform Plugin Template][template] to be notified about releases containing new features and fixes.

<!-- Plugin description -->
This Fancy IntelliJ Platform Plugin is going to be your implementation of the brilliant ideas that you have.

This specific section is a source for the [plugin.xml](/src/main/resources/META-INF/plugin.xml) file which will be extracted by the [Gradle](/build.gradle.kts) during the build process.

To keep everything working, do not remove `<!-- ... -->` sections.
Enables syntax highlighting for the Circom language in IntelliJ IDEA.
<!-- Plugin description end -->

## Installation
Expand Down
45 changes: 43 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ fun environment(key: String) = providers.environmentVariable(key)

plugins {
id("java") // Java support
id("antlr") // ANTLR support

alias(libs.plugins.kotlin) // Kotlin support
alias(libs.plugins.gradleIntelliJPlugin) // Gradle IntelliJ Plugin
alias(libs.plugins.changelog) // Gradle Changelog Plugin
Expand All @@ -23,10 +25,12 @@ repositories {

// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
dependencies {
// implementation(libs.exampleLibrary)
implementation(libs.antlr4IntellijAdaptor)

antlr("org.antlr:antlr4:4.13.1")
implementation("org.antlr:antlr4-runtime:4.13.1")
}

// Set the JVM language level used to build the project.
kotlin {
jvmToolchain(17)
}
Expand All @@ -47,6 +51,11 @@ changelog {
repositoryUrl = properties("pluginRepositoryUrl")
}

configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

// Configure Gradle Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration
kover {
reports {
Expand Down Expand Up @@ -119,3 +128,35 @@ tasks {
channels = properties("pluginVersion").map { listOf(it.substringAfter('-', "").substringBefore('.').ifEmpty { "default" }) }
}
}

tasks.named<AntlrTask>("generateGrammarSource") {
include("**/*.g4")

arguments = arguments + listOf(
"-visitor",
"-package", "com.github.kyrylr.intellijcircom.parser",
"-Xexact-output-dir"
)

doLast {
val parserPackagePath = "${outputDirectory.canonicalPath}/com/github/kyrylr/intellijcircom/parser"

copy {
from(outputDirectory.canonicalPath)
into(parserPackagePath)
include("*Circom*")
}

delete(fileTree(outputDirectory) {
include("*Circom*")
})
}
}

tasks.named("compileKotlin") {
mustRunAfter("generateGrammarSource")
}

tasks.named("compileTestKotlin") {
mustRunAfter("generateGrammarSource")
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gradleVersion = 8.9
kotlin.stdlib.default.dependency = false

# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html
org.gradle.configuration-cache = true
org.gradle.configuration-cache = false

# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html
org.gradle.caching = true
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
# libraries
exampleLibrary = "24.1.0"
antlr4IntellijAdaptor = "0.1"

# plugins
kotlin = "1.9.24"
Expand All @@ -10,7 +10,7 @@ qodana = "2024.1.5"
kover = "0.8.1"

[libraries]
exampleLibrary = { group = "com.example", name = "exampleLibrary", version.ref = "exampleLibrary" }
antlr4IntellijAdaptor = { group = "org.antlr", name = "antlr4-intellij-adaptor", version.ref = "antlr4IntellijAdaptor" }

[plugins]
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
Expand Down
152 changes: 152 additions & 0 deletions src/main/antlr/CircomLexer.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
lexer grammar CircomLexer;

/*//////////////////////////////////////////////////////////////
COMMON STRUCTURES AND TERMINALS
//////////////////////////////////////////////////////////////*/

VERSION: NUMBER '.' NUMBER '.' NUMBER ;

SIGNAL_TYPE: INPUT | OUTPUT ;

/*//////////////////////////////////////////////////////////////
EXPLICIT KEYWORDS DEFINITION
//////////////////////////////////////////////////////////////*/

PRAGMA: 'pragma' ;
CIRCOM: 'circom' ;

CUSTOM_TEMPLATES: 'custom_templates' ;

INCLUDE: 'include' ;

CUSTOM: 'custom' ;
PARALLEL: 'parallel' ;

BUS: 'bus' ;
TEMPLATE: 'template' ;
FUNCTION: 'function' ;

MAIN: 'main' ;
PUBLIC: 'public' ;
COMPONENT: 'component' ;

VAR: 'var' ;
SIGNAL: 'signal' ;

INPUT: 'input' ;
OUTPUT: 'output' ;

IF: 'if' ;
ELSE: 'else' ;

FOR: 'for' ;
WHILE: 'while' ;
DO: 'do' ;

LOG: 'log' ;
ASSERT: 'assert' ;

RETURN: 'return' ;

/*//////////////////////////////////////////////////////////////
SYMBOLS
//////////////////////////////////////////////////////////////*/

LP: '(' ;
RP: ')' ;

LB: '[' ;
RB: ']' ;

LC: '{' ;
RC: '}' ;

SEMICOLON: ';' ;

DOT: '.' ;
COMMA: ',' ;

UNDERSCORE: '_' ;

/*//////////////////////////////////////////////////////////////
OPERATORS
//////////////////////////////////////////////////////////////*/

TERNARY_CONDITION: '?' ;
TERNARY_ALTERNATIVE: ':' ;

EQ_CONSTRAINT: '===' ;

LEFT_CONSTRAINT: '<==' ;
LEFT_ASSIGNMENT: '<--' ;

RIGHT_CONSTRAINT: '==>' ;
RIGHT_ASSIGNMENT: '-->' ;

// Unary operators
SELF_OP: '++' | '--' ;

NOT: '!' ;
BNOT: '~' ;

// left to right associativity
POW: '**' ;

MUL: '*' ;
DIV: '/' ;
QUO: '\\' ;
MOD: '%' ;

ADD: '+' ;
SUB: '-' ;

SHL: '<<' ;
SHR: '>>' ;

BAND: '&' ;
BXOR: '^' ;
BOR: '|' ;

// Require parentheses associativity
EQ: '==' ;
NEQ: '!=' ;
GT: '>' ;
LT: '<' ;
LE: '<=' ;
GE: '>=' ;

// left to right associativity
AND: '&&' ;
OR: '||' ;

// right to left associativity
ASSIGNMENT: '=' ;
ASSIGNMENT_WITH_OP: '+=' | '-=' | '*=' | '**=' | '/=' | '\\=' | '%=' | '<<=' | '>>=' | '&=' | '^=' | '|=' ;

ID : ID_SYMBOL* LETTER (LETTER|ID_SYMBOL|DIGIT)* ; // r"[$_]*[a-zA-Z][a-zA-Z$_0-9]*"
fragment
LETTER : [a-zA-Z] ;
fragment
ID_SYMBOL : [_$] ;

NUMBER: DIGIT+ | HEX;
fragment
DIGIT: [0-9] ;

HEX : '0' 'x' HEXDIGIT+ ; // 0x[0-9A-Fa-f]*
fragment
HEXDIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;

STRING : '"' (ESC|.)*? '"' ;
fragment ESC: '\\' [btnrf"\\] ;
COMMENT
: '/*' .*? '*/' -> channel(HIDDEN)
;
LINE_COMMENT
: '//' ~[\r\n]* -> channel(HIDDEN)
;
WS : [ \r\t\u000C\n]+ -> channel(HIDDEN)
;
Loading

0 comments on commit 274a1c4

Please sign in to comment.