Skip to content

Commit 82eb929

Browse files
authored
Merge pull request #45 from javecs/feature/case-insensitive
関数名の文字は、大文字と小文字を区別しないように修正しました。
2 parents 9373b17 + 3bdfac3 commit 82eb929

14 files changed

Lines changed: 173 additions & 245 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,14 @@
105105
106106
### 関数
107107
108-
演算 | 説明 | 例 | 結果
108+
関数名 | 説明 | 例 | 結果
109109
--------| --------|--------|--------
110110
 sin | サイン。三角関数の正弦。 | sin(1) | 0.8414709848078965
111111
 cos | コサイン。三角関数の余弦。 | cos(1) | 0.5403023058681398
112112
 tan | タンジェント。三角関数の正接。 | tan(1) | 1.5574077246549023
113113
114+
- 関数名の文字は、大文字と小文字を区別しません。
115+
114116
115117
## Javaからの呼び出し方
116118

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ plugins {
1616
}
1717

1818
group 'xyz.javecs.tools'
19-
version '0.1.7'
19+
version '0.1.8'
2020

2121
apply plugin: 'kotlin'
2222
apply plugin: 'antlr'

src/main/antlr/Expr.g4

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ expr: <assoc=right> expr '^' expr # Pow
1111
| expr '%' expr # Mod
1212
| expr '+' expr # Add
1313
| expr '-' expr # Sub
14+
| ID '(' expr ')' # Function
1415
| NUMBER # Number
1516
| ID # Id
1617
| '(' expr ')' # Parens
17-
| func '(' expr ')' # Math
18-
;
19-
func: 'sin'
20-
| 'cos'
21-
| 'tan'
2218
;
2319
NUMBER: [0-9]+('.'[0-9]+)? ;
2420
ID: [a-zA-Z][a-zA-Z0-9]* ;
25-
WS: [ \t\r\n]+ -> skip ;
21+
WS: [ \t\r\n]+ -> skip ;

src/main/java/xyz/javecs/tools/expr/parser/Expr.tokens

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ T__5=6
77
T__6=7
88
T__7=8
99
T__8=9
10-
T__9=10
11-
T__10=11
12-
T__11=12
13-
NUMBER=13
14-
ID=14
15-
WS=15
10+
NUMBER=10
11+
ID=11
12+
WS=12
1613
'='=1
1714
'^'=2
1815
'+'=3
@@ -22,6 +19,3 @@ WS=15
2219
'%'=7
2320
'('=8
2421
')'=9
25-
'sin'=10
26-
'cos'=11
27-
'tan'=12

src/main/java/xyz/javecs/tools/expr/parser/ExprBaseVisitor.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public class ExprBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements E
4646
* {@link #visitChildren} on {@code ctx}.</p>
4747
*/
4848
@Override public T visitAdd(ExprParser.AddContext ctx) { return visitChildren(ctx); }
49+
/**
50+
* {@inheritDoc}
51+
*
52+
* <p>The default implementation returns the result of calling
53+
* {@link #visitChildren} on {@code ctx}.</p>
54+
*/
55+
@Override public T visitFunction(ExprParser.FunctionContext ctx) { return visitChildren(ctx); }
4956
/**
5057
* {@inheritDoc}
5158
*
@@ -102,18 +109,4 @@ public class ExprBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements E
102109
* {@link #visitChildren} on {@code ctx}.</p>
103110
*/
104111
@Override public T visitId(ExprParser.IdContext ctx) { return visitChildren(ctx); }
105-
/**
106-
* {@inheritDoc}
107-
*
108-
* <p>The default implementation returns the result of calling
109-
* {@link #visitChildren} on {@code ctx}.</p>
110-
*/
111-
@Override public T visitMath(ExprParser.MathContext ctx) { return visitChildren(ctx); }
112-
/**
113-
* {@inheritDoc}
114-
*
115-
* <p>The default implementation returns the result of calling
116-
* {@link #visitChildren} on {@code ctx}.</p>
117-
*/
118-
@Override public T visitFunc(ExprParser.FuncContext ctx) { return visitChildren(ctx); }
119112
}

src/main/java/xyz/javecs/tools/expr/parser/ExprLexer.java

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ExprLexer extends Lexer {
1818
new PredictionContextCache();
1919
public static final int
2020
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9,
21-
T__9=10, T__10=11, T__11=12, NUMBER=13, ID=14, WS=15;
21+
NUMBER=10, ID=11, WS=12;
2222
public static String[] channelNames = {
2323
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
2424
};
@@ -29,16 +29,15 @@ public class ExprLexer extends Lexer {
2929

3030
public static final String[] ruleNames = {
3131
"T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8",
32-
"T__9", "T__10", "T__11", "NUMBER", "ID", "WS"
32+
"NUMBER", "ID", "WS"
3333
};
3434

3535
private static final String[] _LITERAL_NAMES = {
36-
null, "'='", "'^'", "'+'", "'-'", "'*'", "'/'", "'%'", "'('", "')'", "'sin'",
37-
"'cos'", "'tan'"
36+
null, "'='", "'^'", "'+'", "'-'", "'*'", "'/'", "'%'", "'('", "')'"
3837
};
3938
private static final String[] _SYMBOLIC_NAMES = {
40-
null, null, null, null, null, null, null, null, null, null, null, null,
41-
null, "NUMBER", "ID", "WS"
39+
null, null, null, null, null, null, null, null, null, null, "NUMBER",
40+
"ID", "WS"
4241
};
4342
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
4443

@@ -98,30 +97,26 @@ public ExprLexer(CharStream input) {
9897
public ATN getATN() { return _ATN; }
9998

10099
public static final String _serializedATN =
101-
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\21Z\b\1\4\2\t\2\4"+
100+
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\16H\b\1\4\2\t\2\4"+
102101
"\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"+
103-
"\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\3\2\3\2\3\3\3\3\3\4"+
104-
"\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\n\3\n\3\13\3\13\3\13\3"+
105-
"\13\3\f\3\f\3\f\3\f\3\r\3\r\3\r\3\r\3\16\6\16A\n\16\r\16\16\16B\3\16\3"+
106-
"\16\6\16G\n\16\r\16\16\16H\5\16K\n\16\3\17\3\17\7\17O\n\17\f\17\16\17"+
107-
"R\13\17\3\20\6\20U\n\20\r\20\16\20V\3\20\3\20\2\2\21\3\3\5\4\7\5\t\6\13"+
108-
"\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33\17\35\20\37\21\3\2\6\3\2\62"+
109-
";\4\2C\\c|\5\2\62;C\\c|\5\2\13\f\17\17\"\"\2^\2\3\3\2\2\2\2\5\3\2\2\2"+
110-
"\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\2\2\2\21\3"+
111-
"\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\2\33\3\2\2"+
112-
"\2\2\35\3\2\2\2\2\37\3\2\2\2\3!\3\2\2\2\5#\3\2\2\2\7%\3\2\2\2\t\'\3\2"+
113-
"\2\2\13)\3\2\2\2\r+\3\2\2\2\17-\3\2\2\2\21/\3\2\2\2\23\61\3\2\2\2\25\63"+
114-
"\3\2\2\2\27\67\3\2\2\2\31;\3\2\2\2\33@\3\2\2\2\35L\3\2\2\2\37T\3\2\2\2"+
115-
"!\"\7?\2\2\"\4\3\2\2\2#$\7`\2\2$\6\3\2\2\2%&\7-\2\2&\b\3\2\2\2\'(\7/\2"+
116-
"\2(\n\3\2\2\2)*\7,\2\2*\f\3\2\2\2+,\7\61\2\2,\16\3\2\2\2-.\7\'\2\2.\20"+
117-
"\3\2\2\2/\60\7*\2\2\60\22\3\2\2\2\61\62\7+\2\2\62\24\3\2\2\2\63\64\7u"+
118-
"\2\2\64\65\7k\2\2\65\66\7p\2\2\66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\2\2\13"+
110+
"#\3\2\2\2\r%\3\2\2\2\17\'\3\2\2\2\21)\3\2\2\2\23+\3\2\2\2\25.\3\2\2\2"+
111+
"\27:\3\2\2\2\31B\3\2\2\2\33\34\7?\2\2\34\4\3\2\2\2\35\36\7`\2\2\36\6\3"+
112+
"\2\2\2\37 \7-\2\2 \b\3\2\2\2!\"\7/\2\2\"\n\3\2\2\2#$\7,\2\2$\f\3\2\2\2"+
113+
"%&\7\61\2\2&\16\3\2\2\2\'(\7\'\2\2(\20\3\2\2\2)*\7*\2\2*\22\3\2\2\2+,"+
114+
"\7+\2\2,\24\3\2\2\2-/\t\2\2\2.-\3\2\2\2/\60\3\2\2\2\60.\3\2\2\2\60\61"+
115+
"\3\2\2\2\618\3\2\2\2\62\64\7\60\2\2\63\65\t\2\2\2\64\63\3\2\2\2\65\66"+
116+
"\3\2\2\2\66\64\3\2\2\2\66\67\3\2\2\2\679\3\2\2\28\62\3\2\2\289\3\2\2\2"+
117+
"9\26\3\2\2\2:>\t\3\2\2;=\t\4\2\2<;\3\2\2\2=@\3\2\2\2><\3\2\2\2>?\3\2\2"+
118+
"\2?\30\3\2\2\2@>\3\2\2\2AC\t\5\2\2BA\3\2\2\2CD\3\2\2\2DB\3\2\2\2DE\3\2"+
119+
"\2\2EF\3\2\2\2FG\b\r\2\2G\32\3\2\2\2\b\2\60\668>D\3\b\2\2";
125120
public static final ATN _ATN =
126121
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
127122
static {

src/main/java/xyz/javecs/tools/expr/parser/ExprLexer.tokens

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ T__5=6
77
T__6=7
88
T__7=8
99
T__8=9
10-
T__9=10
11-
T__10=11
12-
T__11=12
13-
NUMBER=13
14-
ID=14
15-
WS=15
10+
NUMBER=10
11+
ID=11
12+
WS=12
1613
'='=1
1714
'^'=2
1815
'+'=3
@@ -22,6 +19,3 @@ WS=15
2219
'%'=7
2320
'('=8
2421
')'=9
25-
'sin'=10
26-
'cos'=11
27-
'tan'=12

0 commit comments

Comments
 (0)