From 29232018e597947d508caa8c6fedefcd8d09478c Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Tue, 2 Apr 2024 20:11:56 +0700 Subject: [PATCH] add jflex --- .gitignore | 2 + src/main/kotlin/ru/crabs/sjson/SJson.bnf | 4 +- src/main/kotlin/ru/crabs/sjson/SJson.flex | 45 +++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/ru/crabs/sjson/SJson.flex diff --git a/.gitignore b/.gitignore index 060b072..3cc0617 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ bin/ .DS_Store src/main/gen +/idea-flex.skeleton +/jflex-1.9.1.jar diff --git a/src/main/kotlin/ru/crabs/sjson/SJson.bnf b/src/main/kotlin/ru/crabs/sjson/SJson.bnf index e7af41f..06a6c50 100644 --- a/src/main/kotlin/ru/crabs/sjson/SJson.bnf +++ b/src/main/kotlin/ru/crabs/sjson/SJson.bnf @@ -13,9 +13,11 @@ tokenTypeClass="ru.crabs.sjson.SJsonTokenType" tokens = [ - space='regexp:\s+' + space = 'regexp:\s+' string = "regexp:\"[^$][^\"]*\"" number = "regexp:\d*" + + vars_word = "@vars" ] } diff --git a/src/main/kotlin/ru/crabs/sjson/SJson.flex b/src/main/kotlin/ru/crabs/sjson/SJson.flex new file mode 100644 index 0000000..a4e0f56 --- /dev/null +++ b/src/main/kotlin/ru/crabs/sjson/SJson.flex @@ -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 + +%% + + { + "@vars" { return SJsonTypes.VARS_WORD; } + {string} { return SJsonTypes.STRING; } + \" { yybegin(STRING); return TokenType.WHITE_SPACE; } +} + + { + "{" { 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; } +}