Skip to content

Commit

Permalink
feat: support style object syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jan 6, 2024
1 parent 743e9b4 commit f713b30
Show file tree
Hide file tree
Showing 16 changed files with 896 additions and 582 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pluginGroup=com.dvd.intellij.d2
pluginName=D2
pluginRepositoryUrl=https://github.com/develar/d2-intellij-plugin

pluginVersion=1.1.1
pluginVersion=1.2.0
pluginSinceBuild=232
pluginUntilBuild=241.*

Expand Down

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

1,055 changes: 543 additions & 512 deletions src/main/gen/org/jetbrains/plugins/d2/lang/D2FlexLexer.java

Large diffs are not rendered by default.

102 changes: 89 additions & 13 deletions src/main/gen/org/jetbrains/plugins/d2/lang/D2Parser.java

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

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jetbrains.plugins.d2.lang.psi.ShapeId

private val BRACE_PAIRS = arrayOf(
BracePair(D2ElementTypes.LBRACE, D2ElementTypes.RBRACE, true),
BracePair(D2ElementTypes.LBRACKET, D2ElementTypes.RBRACKET, true),
BracePair(D2ElementTypes.BLOCK_STRING_OPEN, D2ElementTypes.BLOCK_STRING_CLOSE, true),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jetbrains.plugins.d2.editor

import com.intellij.codeInsight.codeVision.CodeVisionState
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.process.OSProcessHandler
import com.intellij.execution.process.ProcessNotCreatedException
Expand Down Expand Up @@ -54,7 +53,7 @@ private fun format(file: Path, request: AsyncFormattingRequest) {
val params = command.parametersList
params.add("fmt")
Files.copy(file, result, StandardCopyOption.REPLACE_EXISTING)
params.add(CodeVisionState.NotReady.result.toString())
params.add(result.toString())
val output = ScriptRunnerUtil.getProcessOutput(
command,
ScriptRunnerUtil.STDOUT_OR_STDERR_OUTPUT_KEY_FILTER,
Expand Down
73 changes: 49 additions & 24 deletions src/main/kotlin/org/jetbrains/plugins/d2/lang/D2Lexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import static org.jetbrains.plugins.d2.lang.D2ElementTypes.*;
%unicode

// non style/holder keywords, see SimpleReservedKeywords in d2 source code,
// `classes` is not SimpleReservedKeyword, from CompositeReservedKeywords
SimpleReservedKeywords = label | desc | shape | icon | constraint | tooltip | link | near | width | height | top | left |
grid-rows | grid-columns | grid-gap |
vertical-gap | horizontal-gap |
class | vars | classes
class

CompositeReservedKeywords = classes | vars

StyleKeyword = style

Expand Down Expand Up @@ -64,10 +65,17 @@ WhiteSpace=\s+
LBrace="{"
RBrace="}"

UnquotedStringFragment=[^\s{}|;]+
LBracket="["
RBracket="]"

UnquotedLabelStringFragment=[^\s{}|;]+
UnquotedLabelString={UnquotedLabelStringFragment}([ \t]+{UnquotedLabelStringFragment})*

// [] is not supported - it is array
UnquotedStringFragment=[^\s{}[]|;]+
UnquotedString={UnquotedStringFragment}([ \t]+{UnquotedStringFragment})*

%states LABEL_STATE PROPERTY_VALUE_STATE BLOCK_STRING_LANG_STATE BLOCK_STRING_BODY_STATE
%states LABEL_STATE PROPERTY_VALUE_BEGIN_STATE PROPERTY_VALUE_STATE BLOCK_STRING_LANG_STATE BLOCK_STRING_BODY_STATE ARRAY_STATE

%%
<YYINITIAL> {
Expand All @@ -77,19 +85,20 @@ UnquotedString={UnquotedStringFragment}([ \t]+{UnquotedStringFragment})*
{RBrace} { return RBRACE; }
"." { return DOT; }
{Semicolon} { return SEMICOLON; }
":" { yybegin(LABEL_STATE); return COLON; }
":" { yybegin(LABEL_STATE); return COLON; }

{ARROW} { return ARROW; }
{REVERSE_ARROW} { return REVERSE_ARROW; }
{DOUBLE_HYPHEN_ARROW} { return DOUBLE_HYPHEN_ARROW; }
{DOUBLE_ARROW} { return DOUBLE_ARROW; }
{Comment} { return COMMENT; }

{SimpleReservedKeywords} { yybegin(PROPERTY_VALUE_STATE); return SIMPLE_RESERVED_KEYWORDS; }
{CompositeReservedKeywords} { return COMPOSITE_RESERVED_KEYWORDS; }
{SimpleReservedKeywords} { yybegin(PROPERTY_VALUE_BEGIN_STATE); return SIMPLE_RESERVED_KEYWORDS; }
{ReservedKeywordHolders} { return RESERVED_KEYWORD_HOLDERS; }
{StyleKeyword} { return STYLE_KEYWORD; }
{StyleKeywords} { yybegin(PROPERTY_VALUE_STATE); return STYLE_KEYWORDS; }
{ContainerLessKeywords} { yybegin(PROPERTY_VALUE_STATE); return CONTAINER_LESS_KEYWORDS; }
{StyleKeywords} { yybegin(PROPERTY_VALUE_BEGIN_STATE); return STYLE_KEYWORDS; }
{ContainerLessKeywords} { yybegin(PROPERTY_VALUE_BEGIN_STATE); return CONTAINER_LESS_KEYWORDS; }

{Id} { return ID; }

Expand All @@ -98,6 +107,11 @@ UnquotedString={UnquotedStringFragment}([ \t]+{UnquotedStringFragment})*
{Color} { return COLOR; }
}

<PROPERTY_VALUE_BEGIN_STATE> {
":" { yybegin(PROPERTY_VALUE_STATE); return COLON; }
{WhiteSpace} { return WHITE_SPACE; }
}

// block string is not allowed for property value
<PROPERTY_VALUE_STATE> {
":" { return COLON; }
Expand All @@ -108,8 +122,9 @@ UnquotedString={UnquotedStringFragment}([ \t]+{UnquotedStringFragment})*
"false" { return FALSE; }
{Color} { return COLOR; }
{String} { return STRING; }
// unquoted string - opposite to LABEL_STATE, `:` is not allowed (otherwise, we match `:` as UNQUOTED_STRING instead of COLON)
[^\s{}|:;]+([ \t]+[^\s{}|:;]+)* { return UNQUOTED_STRING; }
{LBracket} { yybegin(ARRAY_STATE); return LBRACKET; }
{RBracket} { return RBRACKET; }
{UnquotedString} { return UNQUOTED_STRING; }

[ \t]+ { return WHITE_SPACE; }
[\r\n]+ { yybegin(YYINITIAL); return WHITE_SPACE; }
Expand All @@ -119,6 +134,16 @@ UnquotedString={UnquotedStringFragment}([ \t]+{UnquotedStringFragment})*
{RBrace} { yybegin(YYINITIAL); return RBRACE; }
}

<ARRAY_STATE> {
{Semicolon} { return SEMICOLON; }
// D2 supports nested arrays, but we don't for now (nested states are nnot supported, can be implemented, but not clear yet for what)
{LBracket} { return LBRACKET; }
{RBracket} { yybegin(YYINITIAL); return RBRACKET; }
{UnquotedString} { return UNQUOTED_STRING; }

{WhiteSpace} { return WHITE_SPACE; }
}

<LABEL_STATE> {
// docs: D2 actually allows you to use any special symbols (not alphanumeric, space, or _) after the first pipe
\|+[^a-zA-Z0-9\s_|]* {
Expand All @@ -128,7 +153,7 @@ UnquotedString={UnquotedStringFragment}([ \t]+{UnquotedStringFragment})*
}

{String} { return STRING; }
{UnquotedString} { return UNQUOTED_STRING; }
{UnquotedLabelString} { return UNQUOTED_STRING; }
[ \t]+ { return WHITE_SPACE; }
[\r\n]+ { yybegin(YYINITIAL); return WHITE_SPACE; }
{LBrace} { yybegin(YYINITIAL); return LBRACE; }
Expand All @@ -148,19 +173,19 @@ UnquotedString={UnquotedStringFragment}([ \t]+{UnquotedStringFragment})*
// so, we can be sure that lexing will be never performed in the middle of block string (always from BLOCK_STRING_OPEN)
<BLOCK_STRING_BODY_STATE> {
[^|]*\|+ {
if (blockStringToken == null) {
yybegin(YYINITIAL);
blockStringToken = null;
return BLOCK_STRING_CLOSE;
}
else if (StringUtilRt.endsWith(yytext(), blockStringToken)) {
// push back to register on next step as a BLOCK_STRING_CLOSE token,
// (we neeed it to easily implement embededed language, brace matcher and so on)
yypushback(blockStringToken.length());
blockStringToken = null;
return BLOCK_STRING_BODY;
}
}
if (blockStringToken == null) {
yybegin(YYINITIAL);
blockStringToken = null;
return BLOCK_STRING_CLOSE;
}
else if (StringUtilRt.endsWith(yytext(), blockStringToken)) {
// push back to register on next step as a BLOCK_STRING_CLOSE token,
// (we neeed it to easily implement embededed language, brace matcher and so on)
yypushback(blockStringToken.length());
blockStringToken = null;
return BLOCK_STRING_BODY;
}
}

<<EOF>> { yybegin(YYINITIAL); return BAD_CHARACTER; }
}
Expand Down
Loading

0 comments on commit f713b30

Please sign in to comment.