Skip to content

Commit

Permalink
fix: more robust tag parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Xstoudi committed Nov 9, 2023
1 parent 641be4d commit d2697d9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 63 deletions.
125 changes: 68 additions & 57 deletions src/main/gen/io/stouder/adonis/edge/parsing/_EdgeLexer.java

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

5 changes: 3 additions & 2 deletions src/main/java/io/stouder/adonis/edge/parsing/EdgeParsing.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ protected void parseTag() {
IElementType nextToken = this.builder.getTokenType();
if(nextToken == EdgeTokenTypes.TAG_CONTENT_OPEN) {
this.parseLeafToken(EdgeTokenTypes.TAG_CONTENT_OPEN);
this.parseLeafTokenGreedy(EdgeTokenTypes.TAG_CONTENT);
this.parseLeafTokenGreedy(EdgeTokenTypes.TAG_CONTENT_CLOSE);
this.parseLeafToken(EdgeTokenTypes.TAG_CONTENT);
this.parseLeafToken(EdgeTokenTypes.TAG_CONTENT_CLOSE);
this.parseLeafToken(EdgeTokenTypes.NEWLINE);
} else if(nextToken == EdgeTokenTypes.NEWLINE) {
this.parseLeafToken(EdgeTokenTypes.NEWLINE);
} else {
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/io/stouder/adonis/edge/parsing/edge.flex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.intellij.util.containers.Stack;

%{
private Stack<Integer> stack = new Stack<>();
private int tagParenLevel;

public void yypushState(int newState) {
stack.push(yystate());
Expand All @@ -43,7 +44,7 @@ CRLF = \R
%state COMMENT_MUSTACHE
%state TAG
%state TAG_CONTENT

%state TAG_CLOSE

%%

Expand Down Expand Up @@ -79,6 +80,7 @@ CRLF = \R
<TAG> {
"(" {
yybegin(TAG_CONTENT);
tagParenLevel = 1;
return EdgeTokenTypes.TAG_CONTENT_OPEN;
}
{CRLF} {
Expand All @@ -87,13 +89,27 @@ CRLF = \R
}
}
<TAG_CONTENT> {
[)]{CRLF} {
yybegin(YYINITIAL);
return EdgeTokenTypes.TAG_CONTENT_CLOSE;
")" {
if (--tagParenLevel <= 0) {
yybegin(TAG_CLOSE);
return EdgeTokenTypes.TAG_CONTENT_CLOSE;
}
return EdgeTokenTypes.TAG_CONTENT;
}
"(" {
tagParenLevel++;
return EdgeTokenTypes.TAG_CONTENT;
}
[^\R] { return EdgeTokenTypes.TAG_CONTENT; }
}

<TAG_CLOSE> {
{CRLF} {
yybegin(YYINITIAL);
return EdgeTokenTypes.NEWLINE;
}
}

<ESCAPED_SAFE_MUSTACHE> {
"}}}" { yypopState(); return EdgeTokenTypes.ESCAPED_SAFE_MUSTACHE_CLOSE; }
}
Expand Down

0 comments on commit d2697d9

Please sign in to comment.