Skip to content

Commit af9183e

Browse files
authored
Merge pull request #41 from javecs/feature/optional-value
指定のフィルドが見つからないときに、デフォルトを設定する機能を追加しました。
2 parents 3a8e19f + c798a72 commit af9183e

12 files changed

Lines changed: 265 additions & 138 deletions

File tree

src/main/antlr/Text2Expr.g4

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ word: word ',' word
99
;
1010
field: PREFIX op=(':'|'?') value ;
1111
value: value '|' value
12-
| JAPANESE
13-
| SYMBOL
12+
| JAPANESE optionalValue?
13+
| SYMBOL optionalValue?
1414
;
1515
expr: .+ | NEWLINE ;
16+
optionalValue: '(' NUMBER ')' ;
1617

1718
// SF : Source form
1819
// PS : Part-of-Speech

src/main/java/xyz/javecs/tools/text2expr/parser/Text2Expr.tokens

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@ T__1=2
33
T__2=3
44
T__3=4
55
T__4=5
6-
PREFIX=6
7-
LEVEL=7
8-
JAPANESE=8
9-
SYMBOL=9
10-
OPERATOR=10
11-
NUMBER=11
12-
ID=12
13-
NEWLINE=13
14-
WS=14
6+
T__5=6
7+
T__6=7
8+
PREFIX=8
9+
LEVEL=9
10+
JAPANESE=10
11+
SYMBOL=11
12+
OPERATOR=12
13+
NUMBER=13
14+
ID=14
15+
NEWLINE=15
16+
WS=16
1517
'='=1
1618
','=2
1719
':'=3
1820
'?'=4
1921
'|'=5
22+
'('=6
23+
')'=7

src/main/java/xyz/javecs/tools/text2expr/parser/Text2ExprBaseVisitor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,11 @@ public class Text2ExprBaseVisitor<T> extends AbstractParseTreeVisitor<T> impleme
6060
* {@link #visitChildren} on {@code ctx}.</p>
6161
*/
6262
@Override public T visitExpr(Text2ExprParser.ExprContext ctx) { return visitChildren(ctx); }
63+
/**
64+
* {@inheritDoc}
65+
*
66+
* <p>The default implementation returns the result of calling
67+
* {@link #visitChildren} on {@code ctx}.</p>
68+
*/
69+
@Override public T visitOptionalValue(Text2ExprParser.OptionalValueContext ctx) { return visitChildren(ctx); }
6370
}

src/main/java/xyz/javecs/tools/text2expr/parser/Text2ExprLexer.java

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class Text2ExprLexer extends Lexer {
1717
protected static final PredictionContextCache _sharedContextCache =
1818
new PredictionContextCache();
1919
public static final int
20-
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, PREFIX=6, LEVEL=7, JAPANESE=8,
21-
SYMBOL=9, OPERATOR=10, NUMBER=11, ID=12, NEWLINE=13, WS=14;
20+
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, PREFIX=8, LEVEL=9,
21+
JAPANESE=10, SYMBOL=11, OPERATOR=12, NUMBER=13, ID=14, NEWLINE=15, WS=16;
2222
public static String[] channelNames = {
2323
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
2424
};
@@ -28,16 +28,16 @@ public class Text2ExprLexer extends Lexer {
2828
};
2929

3030
public static final String[] ruleNames = {
31-
"T__0", "T__1", "T__2", "T__3", "T__4", "PREFIX", "LEVEL", "JAPANESE",
32-
"SYMBOL", "OPERATOR", "NUMBER", "ID", "NEWLINE", "WS"
31+
"T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "PREFIX", "LEVEL",
32+
"JAPANESE", "SYMBOL", "OPERATOR", "NUMBER", "ID", "NEWLINE", "WS"
3333
};
3434

3535
private static final String[] _LITERAL_NAMES = {
36-
null, "'='", "','", "':'", "'?'", "'|'"
36+
null, "'='", "','", "':'", "'?'", "'|'", "'('", "')'"
3737
};
3838
private static final String[] _SYMBOLIC_NAMES = {
39-
null, null, null, null, null, null, "PREFIX", "LEVEL", "JAPANESE", "SYMBOL",
40-
"OPERATOR", "NUMBER", "ID", "NEWLINE", "WS"
39+
null, null, null, null, null, null, null, null, "PREFIX", "LEVEL", "JAPANESE",
40+
"SYMBOL", "OPERATOR", "NUMBER", "ID", "NEWLINE", "WS"
4141
};
4242
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
4343

@@ -97,35 +97,36 @@ public Text2ExprLexer(CharStream input) {
9797
public ATN getATN() { return _ATN; }
9898

9999
public static final String _serializedATN =
100-
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\20f\b\1\4\2\t\2\4"+
100+
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\22n\b\1\4\2\t\2\4"+
101101
"\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+
102-
"\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\3\2\3\2\3\3\3\3\3\4\3\4\3\5\3"+
103-
"\5\3\6\3\6\3\7\3\7\3\7\3\7\3\7\3\7\3\7\3\7\3\7\3\7\5\7\64\n\7\3\b\3\b"+
104-
"\3\t\6\t9\n\t\r\t\16\t:\3\n\3\n\6\n?\n\n\r\n\16\n@\3\n\3\n\3\13\3\13\3"+
105-
"\f\6\fH\n\f\r\f\16\fI\3\f\3\f\6\fN\n\f\r\f\16\fO\5\fR\n\f\3\r\3\r\7\r"+
106-
"V\n\r\f\r\16\rY\13\r\3\16\5\16\\\n\16\3\16\3\16\3\17\6\17a\n\17\r\17\16"+
107-
"\17b\3\17\3\17\2\2\20\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27"+
108-
"\r\31\16\33\17\35\20\3\2\t\3\2\63\66\4\2\u3042\u3101\u4e02\ua001\7\2\'"+
109-
"\'*/\61\61??``\3\2\62;\4\2C\\c|\5\2\62;C\\c|\4\2\13\13\"\"\2q\2\3\3\2"+
110-
"\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17"+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U\3\2\2\2WX\3\2\2\2X\32\3\2\2\2YW\3\2\2\2Z\\\7\17\2\2[Z\3\2\2\2[\\"+
126-
"\3\2\2\2\\]\3\2\2\2]^\7\f\2\2^\34\3\2\2\2_a\t\b\2\2`_\3\2\2\2ab\3\2\2"+
127-
"\2b`\3\2\2\2bc\3\2\2\2cd\3\2\2\2de\b\17\2\2e\36\3\2\2\2\f\2\63:@IOQW["+
128-
"b\3\b\2\2";
102+
"\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\3\2\3\2\3"+
103+
"\3\3\3\3\4\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\t\3\t\3\t\3\t"+
104+
"\3\t\3\t\3\t\3\t\5\t<\n\t\3\n\3\n\3\13\6\13A\n\13\r\13\16\13B\3\f\3\f"+
105+
"\6\fG\n\f\r\f\16\fH\3\f\3\f\3\r\3\r\3\16\6\16P\n\16\r\16\16\16Q\3\16\3"+
106+
"\16\6\16V\n\16\r\16\16\16W\5\16Z\n\16\3\17\3\17\7\17^\n\17\f\17\16\17"+
107+
"a\13\17\3\20\5\20d\n\20\3\20\3\20\3\21\6\21i\n\21\r\21\16\21j\3\21\3\21"+
108+
"\2\2\22\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33\17"+
109+
"\35\20\37\21!\22\3\2\t\3\2\63\66\4\2\u3042\u3101\u4e02\ua001\7\2\'\'*"+
110+
"/\61\61??``\3\2\62;\4\2C\\c|\5\2\62;C\\c|\4\2\13\13\"\"\2y\2\3\3\2\2\2"+
111+
"\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2"+
112+
"\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2"+
113+
"\2\33\3\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\2!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2\2\2bd\7\17\2\2cb\3\2\2\2cd\3\2\2\2de"+
128+
"\3\2\2\2ef\7\f\2\2f \3\2\2\2gi\t\b\2\2hg\3\2\2\2ij\3\2\2\2jh\3\2\2\2j"+
129+
"k\3\2\2\2kl\3\2\2\2lm\b\21\2\2m\"\3\2\2\2\f\2;BHQWY_cj\3\b\2\2";
129130
public static final ATN _ATN =
130131
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
131132
static {

src/main/java/xyz/javecs/tools/text2expr/parser/Text2ExprLexer.tokens

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@ T__1=2
33
T__2=3
44
T__3=4
55
T__4=5
6-
PREFIX=6
7-
LEVEL=7
8-
JAPANESE=8
9-
SYMBOL=9
10-
OPERATOR=10
11-
NUMBER=11
12-
ID=12
13-
NEWLINE=13
14-
WS=14
6+
T__5=6
7+
T__6=7
8+
PREFIX=8
9+
LEVEL=9
10+
JAPANESE=10
11+
SYMBOL=11
12+
OPERATOR=12
13+
NUMBER=13
14+
ID=14
15+
NEWLINE=15
16+
WS=16
1517
'='=1
1618
','=2
1719
':'=3
1820
'?'=4
1921
'|'=5
22+
'('=6
23+
')'=7

0 commit comments

Comments
 (0)