add jflex

This commit is contained in:
Владимир Фёдоров 2024-04-02 20:11:56 +07:00
parent e2041cfa27
commit 29232018e5
3 changed files with 50 additions and 1 deletions

2
.gitignore vendored
View File

@ -42,3 +42,5 @@ bin/
.DS_Store
src/main/gen
/idea-flex.skeleton
/jflex-1.9.1.jar

View File

@ -13,9 +13,11 @@
tokenTypeClass="ru.crabs.sjson.SJsonTokenType"
tokens = [
space='regexp:\s+'
space = 'regexp:\s+'
string = "regexp:\"[^$][^\"]*\""
number = "regexp:\d*"
vars_word = "@vars"
]
}

View File

@ -0,0 +1,45 @@
package ru.crabs.sjson.language;
import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import ru.crabs.sjson.SJsonTypes;
import com.intellij.psi.TokenType;
%%
%class SJsonLexer
%implements FlexLexer
%unicode
%function advance
%type IElementType
%eof{ return;
%eof}
string = \"{valid_character}*\"
valid_character = {valid_set_char} | {valid_escape_seq}
valid_set_char = [^\u0000-\u001F\"\\]
valid_escape_seq = \\([\"\\/bfnrt]|(u({hex_digit}{4})))
hex_digit = [0-9a-fA-F]
%state STRING
%%
<YYINITIAL> {
"@vars" { return SJsonTypes.VARS_WORD; }
{string} { return SJsonTypes.STRING; }
\" { yybegin(STRING); return TokenType.WHITE_SPACE; }
}
<STRING> {
"{" { return TokenType.WHITE_SPACE; } // todo может "левая скобка" должна возвращаться
"}" { return TokenType.WHITE_SPACE; }
"[" { return TokenType.WHITE_SPACE; }
"]" { return TokenType.WHITE_SPACE; }
"," { return TokenType.WHITE_SPACE; }
":" { return TokenType.WHITE_SPACE; }
\" { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; }
}