GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

datemath.*DatemathParser.timestamp   F
last analyzed

Complexity

Conditions 20

Size

Total Lines 144
Code Lines 102

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 20
eloc 102
nop 1
dl 0
loc 144
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like datemath.*DatemathParser.timestamp often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
// Code generated from Datemath.g4 by ANTLR 4.7.2. DO NOT EDIT.
2
3
package datemath // Datemath
4
import (
5
	"fmt"
6
	"reflect"
7
	"strconv"
8
9
	"github.com/antlr/antlr4/runtime/Go/antlr"
10
)
11
12
// Suppress unused import errors
13
var _ = fmt.Printf
14
var _ = reflect.Copy
15
var _ = strconv.Itoa
16
17
var parserATN = []uint16{
18
	3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 14, 32, 4,
19
	2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3,
20
	3, 3, 3, 5, 3, 17, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 3, 25,
21
	10, 3, 12, 3, 14, 3, 28, 11, 3, 3, 4, 3, 4, 3, 4, 2, 3, 4, 5, 2, 4, 6,
22
	2, 4, 3, 2, 6, 7, 3, 2, 3, 4, 2, 33, 2, 8, 3, 2, 2, 2, 4, 16, 3, 2, 2,
23
	2, 6, 29, 3, 2, 2, 2, 8, 9, 5, 4, 3, 2, 9, 10, 7, 2, 2, 3, 10, 3, 3, 2,
24
	2, 2, 11, 12, 8, 3, 1, 2, 12, 17, 7, 9, 2, 2, 13, 17, 7, 12, 2, 2, 14,
25
	17, 7, 5, 2, 2, 15, 17, 7, 14, 2, 2, 16, 11, 3, 2, 2, 2, 16, 13, 3, 2,
26
	2, 2, 16, 14, 3, 2, 2, 2, 16, 15, 3, 2, 2, 2, 17, 26, 3, 2, 2, 2, 18, 19,
27
	12, 7, 2, 2, 19, 20, 9, 2, 2, 2, 20, 25, 5, 6, 4, 2, 21, 22, 12, 6, 2,
28
	2, 22, 23, 7, 8, 2, 2, 23, 25, 5, 6, 4, 2, 24, 18, 3, 2, 2, 2, 24, 21,
29
	3, 2, 2, 2, 25, 28, 3, 2, 2, 2, 26, 24, 3, 2, 2, 2, 26, 27, 3, 2, 2, 2,
30
	27, 5, 3, 2, 2, 2, 28, 26, 3, 2, 2, 2, 29, 30, 9, 3, 2, 2, 30, 7, 3, 2,
31
	2, 2, 5, 16, 24, 26,
32
}
33
var deserializer = antlr.NewATNDeserializer(nil)
34
var deserializedATN = deserializer.DeserializeFromUInt16(parserATN)
35
36
var literalNames = []string{
37
	"", "", "", "", "'+'", "'-'", "'/'",
38
}
39
var symbolicNames = []string{
40
	"", "EsDuration", "GoDuration", "Literal", "Plus", "Minus", "Round", "Builtins",
41
	"IntegerLiteral", "FloatLiteral", "Identifier", "WhiteSpaces", "DateLiteral",
42
}
43
44
var ruleNames = []string{
45
	"start", "timestamp", "duration",
46
}
47
var decisionToDFA = make([]*antlr.DFA, len(deserializedATN.DecisionToState))
48
49
func init() {
50
	for index, ds := range deserializedATN.DecisionToState {
51
		decisionToDFA[index] = antlr.NewDFA(ds, index)
52
	}
53
}
54
55
type DatemathParser struct {
56
	*antlr.BaseParser
57
}
58
59
func NewDatemathParser(input antlr.TokenStream) *DatemathParser {
60
	this := new(DatemathParser)
61
62
	this.BaseParser = antlr.NewBaseParser(input)
63
64
	this.Interpreter = antlr.NewParserATNSimulator(this, deserializedATN, decisionToDFA, antlr.NewPredictionContextCache())
65
	this.RuleNames = ruleNames
66
	this.LiteralNames = literalNames
67
	this.SymbolicNames = symbolicNames
68
	this.GrammarFileName = "Datemath.g4"
69
70
	return this
71
}
72
73
// DatemathParser tokens.
74
const (
75
	DatemathParserEOF            = antlr.TokenEOF
76
	DatemathParserEsDuration     = 1
77
	DatemathParserGoDuration     = 2
78
	DatemathParserLiteral        = 3
79
	DatemathParserPlus           = 4
80
	DatemathParserMinus          = 5
81
	DatemathParserRound          = 6
82
	DatemathParserBuiltins       = 7
83
	DatemathParserIntegerLiteral = 8
84
	DatemathParserFloatLiteral   = 9
85
	DatemathParserIdentifier     = 10
86
	DatemathParserWhiteSpaces    = 11
87
	DatemathParserDateLiteral    = 12
88
)
89
90
// DatemathParser rules.
91
const (
92
	DatemathParserRULE_start     = 0
93
	DatemathParserRULE_timestamp = 1
94
	DatemathParserRULE_duration  = 2
95
)
96
97
// IStartContext is an interface to support dynamic dispatch.
98
type IStartContext interface {
99
	antlr.ParserRuleContext
100
101
	// GetParser returns the parser.
102
	GetParser() antlr.Parser
103
104
	// GetE returns the e rule contexts.
105
	GetE() ITimestampContext
106
107
	// SetE sets the e rule contexts.
108
	SetE(ITimestampContext)
109
110
	// IsStartContext differentiates from other interfaces.
111
	IsStartContext()
112
}
113
114
type StartContext struct {
115
	*antlr.BaseParserRuleContext
116
	parser antlr.Parser
117
	e      ITimestampContext
118
}
119
120
func NewEmptyStartContext() *StartContext {
121
	var p = new(StartContext)
122
	p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
123
	p.RuleIndex = DatemathParserRULE_start
124
	return p
125
}
126
127
func (*StartContext) IsStartContext() {}
128
129
func NewStartContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *StartContext {
130
	var p = new(StartContext)
131
132
	p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
133
134
	p.parser = parser
135
	p.RuleIndex = DatemathParserRULE_start
136
137
	return p
138
}
139
140
func (s *StartContext) GetParser() antlr.Parser { return s.parser }
141
142
func (s *StartContext) GetE() ITimestampContext { return s.e }
143
144
func (s *StartContext) SetE(v ITimestampContext) { s.e = v }
145
146
func (s *StartContext) EOF() antlr.TerminalNode {
147
	return s.GetToken(DatemathParserEOF, 0)
148
}
149
150
func (s *StartContext) Timestamp() ITimestampContext {
151
	var t = s.GetTypedRuleContext(reflect.TypeOf((*ITimestampContext)(nil)).Elem(), 0)
152
153
	if t == nil {
154
		return nil
155
	}
156
157
	return t.(ITimestampContext)
158
}
159
160
func (s *StartContext) GetRuleContext() antlr.RuleContext {
161
	return s
162
}
163
164
func (s *StartContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
165
	return antlr.TreesStringTree(s, ruleNames, recog)
166
}
167
168
func (s *StartContext) EnterRule(listener antlr.ParseTreeListener) {
169
	if listenerT, ok := listener.(DatemathListener); ok {
170
		listenerT.EnterStart(s)
171
	}
172
}
173
174
func (s *StartContext) ExitRule(listener antlr.ParseTreeListener) {
175
	if listenerT, ok := listener.(DatemathListener); ok {
176
		listenerT.ExitStart(s)
177
	}
178
}
179
180
func (s *StartContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
181
	switch t := visitor.(type) {
182
	case DatemathVisitor:
183
		return t.VisitStart(s)
184
185
	default:
186
		return t.VisitChildren(s)
187
	}
188
}
189
190
func (p *DatemathParser) Start() (localctx IStartContext) {
191
	localctx = NewStartContext(p, p.GetParserRuleContext(), p.GetState())
192
	p.EnterRule(localctx, 0, DatemathParserRULE_start)
193
194
	defer func() {
195
		p.ExitRule()
196
	}()
197
198
	defer func() {
199
		if err := recover(); err != nil {
200
			if v, ok := err.(antlr.RecognitionException); ok {
201
				localctx.SetException(v)
202
				p.GetErrorHandler().ReportError(p, v)
203
				p.GetErrorHandler().Recover(p, v)
204
			} else {
205
				panic(err)
206
			}
207
		}
208
	}()
209
210
	p.EnterOuterAlt(localctx, 1)
211
	{
212
		p.SetState(6)
213
214
		var _x = p.timestamp(0)
215
216
		localctx.(*StartContext).e = _x
217
	}
218
	{
219
		p.SetState(7)
220
		p.Match(DatemathParserEOF)
221
	}
222
223
	return localctx
224
}
225
226
// ITimestampContext is an interface to support dynamic dispatch.
227
type ITimestampContext interface {
228
	antlr.ParserRuleContext
229
230
	// GetParser returns the parser.
231
	GetParser() antlr.Parser
232
233
	// IsTimestampContext differentiates from other interfaces.
234
	IsTimestampContext()
235
}
236
237
type TimestampContext struct {
238
	*antlr.BaseParserRuleContext
239
	parser antlr.Parser
240
}
241
242
func NewEmptyTimestampContext() *TimestampContext {
243
	var p = new(TimestampContext)
244
	p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
245
	p.RuleIndex = DatemathParserRULE_timestamp
246
	return p
247
}
248
249
func (*TimestampContext) IsTimestampContext() {}
250
251
func NewTimestampContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TimestampContext {
252
	var p = new(TimestampContext)
253
254
	p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
255
256
	p.parser = parser
257
	p.RuleIndex = DatemathParserRULE_timestamp
258
259
	return p
260
}
261
262
func (s *TimestampContext) GetParser() antlr.Parser { return s.parser }
263
264
func (s *TimestampContext) CopyFrom(ctx *TimestampContext) {
265
	s.BaseParserRuleContext.CopyFrom(ctx.BaseParserRuleContext)
266
}
267
268
func (s *TimestampContext) GetRuleContext() antlr.RuleContext {
269
	return s
270
}
271
272
func (s *TimestampContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
273
	return antlr.TreesStringTree(s, ruleNames, recog)
274
}
275
276
type IdentifierContext struct {
277
	*TimestampContext
278
}
279
280
func NewIdentifierContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *IdentifierContext {
281
	var p = new(IdentifierContext)
282
283
	p.TimestampContext = NewEmptyTimestampContext()
284
	p.parser = parser
285
	p.CopyFrom(ctx.(*TimestampContext))
286
287
	return p
288
}
289
290
func (s *IdentifierContext) GetRuleContext() antlr.RuleContext {
291
	return s
292
}
293
294
func (s *IdentifierContext) Identifier() antlr.TerminalNode {
295
	return s.GetToken(DatemathParserIdentifier, 0)
296
}
297
298
func (s *IdentifierContext) EnterRule(listener antlr.ParseTreeListener) {
299
	if listenerT, ok := listener.(DatemathListener); ok {
300
		listenerT.EnterIdentifier(s)
301
	}
302
}
303
304
func (s *IdentifierContext) ExitRule(listener antlr.ParseTreeListener) {
305
	if listenerT, ok := listener.(DatemathListener); ok {
306
		listenerT.ExitIdentifier(s)
307
	}
308
}
309
310
func (s *IdentifierContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
311
	switch t := visitor.(type) {
312
	case DatemathVisitor:
313
		return t.VisitIdentifier(s)
314
315
	default:
316
		return t.VisitChildren(s)
317
	}
318
}
319
320
type DateLiteralContext struct {
321
	*TimestampContext
322
}
323
324
func NewDateLiteralContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *DateLiteralContext {
325
	var p = new(DateLiteralContext)
326
327
	p.TimestampContext = NewEmptyTimestampContext()
328
	p.parser = parser
329
	p.CopyFrom(ctx.(*TimestampContext))
330
331
	return p
332
}
333
334
func (s *DateLiteralContext) GetRuleContext() antlr.RuleContext {
335
	return s
336
}
337
338
func (s *DateLiteralContext) DateLiteral() antlr.TerminalNode {
339
	return s.GetToken(DatemathParserDateLiteral, 0)
340
}
341
342
func (s *DateLiteralContext) EnterRule(listener antlr.ParseTreeListener) {
343
	if listenerT, ok := listener.(DatemathListener); ok {
344
		listenerT.EnterDateLiteral(s)
345
	}
346
}
347
348
func (s *DateLiteralContext) ExitRule(listener antlr.ParseTreeListener) {
349
	if listenerT, ok := listener.(DatemathListener); ok {
350
		listenerT.ExitDateLiteral(s)
351
	}
352
}
353
354
func (s *DateLiteralContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
355
	switch t := visitor.(type) {
356
	case DatemathVisitor:
357
		return t.VisitDateLiteral(s)
358
359
	default:
360
		return t.VisitChildren(s)
361
	}
362
}
363
364
type LiteralContext struct {
365
	*TimestampContext
366
}
367
368
func NewLiteralContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *LiteralContext {
369
	var p = new(LiteralContext)
370
371
	p.TimestampContext = NewEmptyTimestampContext()
372
	p.parser = parser
373
	p.CopyFrom(ctx.(*TimestampContext))
374
375
	return p
376
}
377
378
func (s *LiteralContext) GetRuleContext() antlr.RuleContext {
379
	return s
380
}
381
382
func (s *LiteralContext) Literal() antlr.TerminalNode {
383
	return s.GetToken(DatemathParserLiteral, 0)
384
}
385
386
func (s *LiteralContext) EnterRule(listener antlr.ParseTreeListener) {
387
	if listenerT, ok := listener.(DatemathListener); ok {
388
		listenerT.EnterLiteral(s)
389
	}
390
}
391
392
func (s *LiteralContext) ExitRule(listener antlr.ParseTreeListener) {
393
	if listenerT, ok := listener.(DatemathListener); ok {
394
		listenerT.ExitLiteral(s)
395
	}
396
}
397
398
func (s *LiteralContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
399
	switch t := visitor.(type) {
400
	case DatemathVisitor:
401
		return t.VisitLiteral(s)
402
403
	default:
404
		return t.VisitChildren(s)
405
	}
406
}
407
408
type RoundContext struct {
409
	*TimestampContext
410
}
411
412
func NewRoundContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *RoundContext {
413
	var p = new(RoundContext)
414
415
	p.TimestampContext = NewEmptyTimestampContext()
416
	p.parser = parser
417
	p.CopyFrom(ctx.(*TimestampContext))
418
419
	return p
420
}
421
422
func (s *RoundContext) GetRuleContext() antlr.RuleContext {
423
	return s
424
}
425
426
func (s *RoundContext) Timestamp() ITimestampContext {
427
	var t = s.GetTypedRuleContext(reflect.TypeOf((*ITimestampContext)(nil)).Elem(), 0)
428
429
	if t == nil {
430
		return nil
431
	}
432
433
	return t.(ITimestampContext)
434
}
435
436
func (s *RoundContext) Round() antlr.TerminalNode {
437
	return s.GetToken(DatemathParserRound, 0)
438
}
439
440
func (s *RoundContext) Duration() IDurationContext {
441
	var t = s.GetTypedRuleContext(reflect.TypeOf((*IDurationContext)(nil)).Elem(), 0)
442
443
	if t == nil {
444
		return nil
445
	}
446
447
	return t.(IDurationContext)
448
}
449
450
func (s *RoundContext) EnterRule(listener antlr.ParseTreeListener) {
451
	if listenerT, ok := listener.(DatemathListener); ok {
452
		listenerT.EnterRound(s)
453
	}
454
}
455
456
func (s *RoundContext) ExitRule(listener antlr.ParseTreeListener) {
457
	if listenerT, ok := listener.(DatemathListener); ok {
458
		listenerT.ExitRound(s)
459
	}
460
}
461
462
func (s *RoundContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
463
	switch t := visitor.(type) {
464
	case DatemathVisitor:
465
		return t.VisitRound(s)
466
467
	default:
468
		return t.VisitChildren(s)
469
	}
470
}
471
472
type BinaryContext struct {
473
	*TimestampContext
474
	op antlr.Token
475
}
476
477
func NewBinaryContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *BinaryContext {
478
	var p = new(BinaryContext)
479
480
	p.TimestampContext = NewEmptyTimestampContext()
481
	p.parser = parser
482
	p.CopyFrom(ctx.(*TimestampContext))
483
484
	return p
485
}
486
487
func (s *BinaryContext) GetOp() antlr.Token { return s.op }
488
489
func (s *BinaryContext) SetOp(v antlr.Token) { s.op = v }
490
491
func (s *BinaryContext) GetRuleContext() antlr.RuleContext {
492
	return s
493
}
494
495
func (s *BinaryContext) Timestamp() ITimestampContext {
496
	var t = s.GetTypedRuleContext(reflect.TypeOf((*ITimestampContext)(nil)).Elem(), 0)
497
498
	if t == nil {
499
		return nil
500
	}
501
502
	return t.(ITimestampContext)
503
}
504
505
func (s *BinaryContext) Duration() IDurationContext {
506
	var t = s.GetTypedRuleContext(reflect.TypeOf((*IDurationContext)(nil)).Elem(), 0)
507
508
	if t == nil {
509
		return nil
510
	}
511
512
	return t.(IDurationContext)
513
}
514
515
func (s *BinaryContext) Plus() antlr.TerminalNode {
516
	return s.GetToken(DatemathParserPlus, 0)
517
}
518
519
func (s *BinaryContext) Minus() antlr.TerminalNode {
520
	return s.GetToken(DatemathParserMinus, 0)
521
}
522
523
func (s *BinaryContext) EnterRule(listener antlr.ParseTreeListener) {
524
	if listenerT, ok := listener.(DatemathListener); ok {
525
		listenerT.EnterBinary(s)
526
	}
527
}
528
529
func (s *BinaryContext) ExitRule(listener antlr.ParseTreeListener) {
530
	if listenerT, ok := listener.(DatemathListener); ok {
531
		listenerT.ExitBinary(s)
532
	}
533
}
534
535
func (s *BinaryContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
536
	switch t := visitor.(type) {
537
	case DatemathVisitor:
538
		return t.VisitBinary(s)
539
540
	default:
541
		return t.VisitChildren(s)
542
	}
543
}
544
545
type BuiltinContext struct {
546
	*TimestampContext
547
}
548
549
func NewBuiltinContext(parser antlr.Parser, ctx antlr.ParserRuleContext) *BuiltinContext {
550
	var p = new(BuiltinContext)
551
552
	p.TimestampContext = NewEmptyTimestampContext()
553
	p.parser = parser
554
	p.CopyFrom(ctx.(*TimestampContext))
555
556
	return p
557
}
558
559
func (s *BuiltinContext) GetRuleContext() antlr.RuleContext {
560
	return s
561
}
562
563
func (s *BuiltinContext) Builtins() antlr.TerminalNode {
564
	return s.GetToken(DatemathParserBuiltins, 0)
565
}
566
567
func (s *BuiltinContext) EnterRule(listener antlr.ParseTreeListener) {
568
	if listenerT, ok := listener.(DatemathListener); ok {
569
		listenerT.EnterBuiltin(s)
570
	}
571
}
572
573
func (s *BuiltinContext) ExitRule(listener antlr.ParseTreeListener) {
574
	if listenerT, ok := listener.(DatemathListener); ok {
575
		listenerT.ExitBuiltin(s)
576
	}
577
}
578
579
func (s *BuiltinContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
580
	switch t := visitor.(type) {
581
	case DatemathVisitor:
582
		return t.VisitBuiltin(s)
583
584
	default:
585
		return t.VisitChildren(s)
586
	}
587
}
588
589
func (p *DatemathParser) Timestamp() (localctx ITimestampContext) {
590
	return p.timestamp(0)
591
}
592
593
func (p *DatemathParser) timestamp(_p int) (localctx ITimestampContext) {
594
	var _parentctx antlr.ParserRuleContext = p.GetParserRuleContext()
595
	_parentState := p.GetState()
596
	localctx = NewTimestampContext(p, p.GetParserRuleContext(), _parentState)
597
	var _prevctx ITimestampContext = localctx
598
	var _ antlr.ParserRuleContext = _prevctx // TODO: To prevent unused variable warning.
599
	_startState := 2
600
	p.EnterRecursionRule(localctx, 2, DatemathParserRULE_timestamp, _p)
601
	var _la int
602
603
	defer func() {
604
		p.UnrollRecursionContexts(_parentctx)
605
	}()
606
607
	defer func() {
608
		if err := recover(); err != nil {
609
			if v, ok := err.(antlr.RecognitionException); ok {
610
				localctx.SetException(v)
611
				p.GetErrorHandler().ReportError(p, v)
612
				p.GetErrorHandler().Recover(p, v)
613
			} else {
614
				panic(err)
615
			}
616
		}
617
	}()
618
619
	var _alt int
620
621
	p.EnterOuterAlt(localctx, 1)
622
	p.SetState(14)
623
	p.GetErrorHandler().Sync(p)
624
625
	switch p.GetTokenStream().LA(1) {
626
	case DatemathParserBuiltins:
627
		localctx = NewBuiltinContext(p, localctx)
628
		p.SetParserRuleContext(localctx)
629
		_prevctx = localctx
630
631
		{
632
			p.SetState(10)
633
			p.Match(DatemathParserBuiltins)
634
		}
635
636
	case DatemathParserIdentifier:
637
		localctx = NewIdentifierContext(p, localctx)
638
		p.SetParserRuleContext(localctx)
639
		_prevctx = localctx
640
		{
641
			p.SetState(11)
642
			p.Match(DatemathParserIdentifier)
643
		}
644
645
	case DatemathParserLiteral:
646
		localctx = NewLiteralContext(p, localctx)
647
		p.SetParserRuleContext(localctx)
648
		_prevctx = localctx
649
		{
650
			p.SetState(12)
651
			p.Match(DatemathParserLiteral)
652
		}
653
654
	case DatemathParserDateLiteral:
655
		localctx = NewDateLiteralContext(p, localctx)
656
		p.SetParserRuleContext(localctx)
657
		_prevctx = localctx
658
		{
659
			p.SetState(13)
660
			p.Match(DatemathParserDateLiteral)
661
		}
662
663
	default:
664
		panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))
665
	}
666
	p.GetParserRuleContext().SetStop(p.GetTokenStream().LT(-1))
667
	p.SetState(24)
668
	p.GetErrorHandler().Sync(p)
669
	_alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 2, p.GetParserRuleContext())
670
671
	for _alt != 2 && _alt != antlr.ATNInvalidAltNumber {
672
		if _alt == 1 {
673
			if p.GetParseListeners() != nil {
674
				p.TriggerExitRuleEvent()
675
			}
676
			_prevctx = localctx
677
			p.SetState(22)
678
			p.GetErrorHandler().Sync(p)
679
			switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 1, p.GetParserRuleContext()) {
680
			case 1:
681
				localctx = NewBinaryContext(p, NewTimestampContext(p, _parentctx, _parentState))
682
				p.PushNewRecursionContext(localctx, _startState, DatemathParserRULE_timestamp)
683
				p.SetState(16)
684
685
				if !(p.Precpred(p.GetParserRuleContext(), 5)) {
686
					panic(antlr.NewFailedPredicateException(p, "p.Precpred(p.GetParserRuleContext(), 5)", ""))
687
				}
688
				{
689
					p.SetState(17)
690
691
					var _lt = p.GetTokenStream().LT(1)
692
693
					localctx.(*BinaryContext).op = _lt
694
695
					_la = p.GetTokenStream().LA(1)
696
697
					if !(_la == DatemathParserPlus || _la == DatemathParserMinus) {
698
						var _ri = p.GetErrorHandler().RecoverInline(p)
699
700
						localctx.(*BinaryContext).op = _ri
701
					} else {
702
						p.GetErrorHandler().ReportMatch(p)
703
						p.Consume()
704
					}
705
				}
706
				{
707
					p.SetState(18)
708
					p.Duration()
709
				}
710
711
			case 2:
712
				localctx = NewRoundContext(p, NewTimestampContext(p, _parentctx, _parentState))
713
				p.PushNewRecursionContext(localctx, _startState, DatemathParserRULE_timestamp)
714
				p.SetState(19)
715
716
				if !(p.Precpred(p.GetParserRuleContext(), 4)) {
717
					panic(antlr.NewFailedPredicateException(p, "p.Precpred(p.GetParserRuleContext(), 4)", ""))
718
				}
719
				{
720
					p.SetState(20)
721
					p.Match(DatemathParserRound)
722
				}
723
				{
724
					p.SetState(21)
725
					p.Duration()
726
				}
727
728
			}
729
730
		}
731
		p.SetState(26)
732
		p.GetErrorHandler().Sync(p)
733
		_alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 2, p.GetParserRuleContext())
734
	}
735
736
	return localctx
737
}
738
739
// IDurationContext is an interface to support dynamic dispatch.
740
type IDurationContext interface {
741
	antlr.ParserRuleContext
742
743
	// GetParser returns the parser.
744
	GetParser() antlr.Parser
745
746
	// IsDurationContext differentiates from other interfaces.
747
	IsDurationContext()
748
}
749
750
type DurationContext struct {
751
	*antlr.BaseParserRuleContext
752
	parser antlr.Parser
753
}
754
755
func NewEmptyDurationContext() *DurationContext {
756
	var p = new(DurationContext)
757
	p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
758
	p.RuleIndex = DatemathParserRULE_duration
759
	return p
760
}
761
762
func (*DurationContext) IsDurationContext() {}
763
764
func NewDurationContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *DurationContext {
765
	var p = new(DurationContext)
766
767
	p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
768
769
	p.parser = parser
770
	p.RuleIndex = DatemathParserRULE_duration
771
772
	return p
773
}
774
775
func (s *DurationContext) GetParser() antlr.Parser { return s.parser }
776
777
func (s *DurationContext) EsDuration() antlr.TerminalNode {
778
	return s.GetToken(DatemathParserEsDuration, 0)
779
}
780
781
func (s *DurationContext) GoDuration() antlr.TerminalNode {
782
	return s.GetToken(DatemathParserGoDuration, 0)
783
}
784
785
func (s *DurationContext) GetRuleContext() antlr.RuleContext {
786
	return s
787
}
788
789
func (s *DurationContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
790
	return antlr.TreesStringTree(s, ruleNames, recog)
791
}
792
793
func (s *DurationContext) EnterRule(listener antlr.ParseTreeListener) {
794
	if listenerT, ok := listener.(DatemathListener); ok {
795
		listenerT.EnterDuration(s)
796
	}
797
}
798
799
func (s *DurationContext) ExitRule(listener antlr.ParseTreeListener) {
800
	if listenerT, ok := listener.(DatemathListener); ok {
801
		listenerT.ExitDuration(s)
802
	}
803
}
804
805
func (s *DurationContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
806
	switch t := visitor.(type) {
807
	case DatemathVisitor:
808
		return t.VisitDuration(s)
809
810
	default:
811
		return t.VisitChildren(s)
812
	}
813
}
814
815
func (p *DatemathParser) Duration() (localctx IDurationContext) {
816
	localctx = NewDurationContext(p, p.GetParserRuleContext(), p.GetState())
817
	p.EnterRule(localctx, 4, DatemathParserRULE_duration)
818
	var _la int
819
820
	defer func() {
821
		p.ExitRule()
822
	}()
823
824
	defer func() {
825
		if err := recover(); err != nil {
826
			if v, ok := err.(antlr.RecognitionException); ok {
827
				localctx.SetException(v)
828
				p.GetErrorHandler().ReportError(p, v)
829
				p.GetErrorHandler().Recover(p, v)
830
			} else {
831
				panic(err)
832
			}
833
		}
834
	}()
835
836
	p.EnterOuterAlt(localctx, 1)
837
	{
838
		p.SetState(27)
839
		_la = p.GetTokenStream().LA(1)
840
841
		if !(_la == DatemathParserEsDuration || _la == DatemathParserGoDuration) {
842
			p.GetErrorHandler().RecoverInline(p)
843
		} else {
844
			p.GetErrorHandler().ReportMatch(p)
845
			p.Consume()
846
		}
847
	}
848
849
	return localctx
850
}
851
852
func (p *DatemathParser) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool {
853
	switch ruleIndex {
854
	case 1:
855
		var t *TimestampContext = nil
856
		if localctx != nil {
857
			t = localctx.(*TimestampContext)
858
		}
859
		return p.Timestamp_Sempred(t, predIndex)
860
861
	default:
862
		panic("No predicate with index: " + fmt.Sprint(ruleIndex))
863
	}
864
}
865
866
func (p *DatemathParser) Timestamp_Sempred(localctx antlr.RuleContext, predIndex int) bool {
867
	switch predIndex {
868
	case 0:
869
		return p.Precpred(p.GetParserRuleContext(), 5)
870
871
	case 1:
872
		return p.Precpred(p.GetParserRuleContext(), 4)
873
874
	default:
875
		panic("No predicate with index: " + fmt.Sprint(predIndex))
876
	}
877
}
878