diff --git a/Antlr4.Runtime/ANTLRFileStream.cs b/Antlr4.Runtime/ANTLRFileStream.cs index 857b764f6..4e295d7d1 100644 --- a/Antlr4.Runtime/ANTLRFileStream.cs +++ b/Antlr4.Runtime/ANTLRFileStream.cs @@ -88,9 +88,12 @@ namespace Antlr4.Runtime } } - public override string GetSourceName() + public override string SourceName { - return fileName; + get + { + return fileName; + } } } } diff --git a/Antlr4.Runtime/ANTLRInputStream.cs b/Antlr4.Runtime/ANTLRInputStream.cs index 0bcc8377f..2b032a116 100644 --- a/Antlr4.Runtime/ANTLRInputStream.cs +++ b/Antlr4.Runtime/ANTLRInputStream.cs @@ -233,14 +233,20 @@ namespace Antlr4.Runtime /// last symbol has been read. The index is the index of char to /// be returned from LA(1). /// - public virtual int Index() + public virtual int Index { - return p; + get + { + return p; + } } - public virtual int Size() + public virtual int Size { - return n; + get + { + return n; + } } /// mark/release do nothing; we have entire buffer @@ -295,9 +301,12 @@ namespace Antlr4.Runtime return new string(data, start, count); } - public virtual string GetSourceName() + public virtual string SourceName { - return name; + get + { + return name; + } } public override string ToString() diff --git a/Antlr4.Runtime/Atn/ATNConfig.cs b/Antlr4.Runtime/Atn/ATNConfig.cs index 14f69e87f..8b7d99638 100644 --- a/Antlr4.Runtime/Atn/ATNConfig.cs +++ b/Antlr4.Runtime/Atn/ATNConfig.cs @@ -305,17 +305,17 @@ namespace Antlr4.Runtime.Atn { return true; } - if (left.Size() < right.Size()) + if (left.Size < right.Size) { return false; } - if (right.IsEmpty()) + if (right.IsEmpty) { - return left.HasEmpty(); + return left.HasEmpty; } else { - for (int i = 0; i < right.Size(); i++) + for (int i = 0; i < right.Size; i++) { int index = left.FindReturnState(right.GetReturnState(i)); if (index < 0) @@ -394,7 +394,7 @@ namespace Antlr4.Runtime.Atn while (!workList.IsEmpty()) { PredictionContext current = workList.Pop(); - for (int i = 0; i < current.Size(); i++) + for (int i = 0; i < current.Size; i++) { builder.Append(" s").Append(Sharpen.Runtime.IdentityHashCode(current)); builder.Append("->"); diff --git a/Antlr4.Runtime/Atn/ATNSimulator.cs b/Antlr4.Runtime/Atn/ATNSimulator.cs index ca568fb43..b9637ea18 100644 --- a/Antlr4.Runtime/Atn/ATNSimulator.cs +++ b/Antlr4.Runtime/Atn/ATNSimulator.cs @@ -444,7 +444,7 @@ namespace Antlr4.Runtime.Atn RuleStartState startState = atn.ruleToStartState[i]; ATNState middleState = startState; while (middleState.OnlyHasEpsilonTransitions() && middleState.GetNumberOfOptimizedTransitions - () == 1 && middleState.GetOptimizedTransition(0).GetSerializationType() == Transition + () == 1 && middleState.GetOptimizedTransition(0).SerializationType == Transition .Epsilon) { middleState = middleState.GetOptimizedTransition(0).target; @@ -455,13 +455,13 @@ namespace Antlr4.Runtime.Atn } Transition matchTransition = middleState.GetOptimizedTransition(0); ATNState matchTarget = matchTransition.target; - if (matchTransition.IsEpsilon() || !matchTarget.OnlyHasEpsilonTransitions() || matchTarget + if (matchTransition.IsEpsilon || !matchTarget.OnlyHasEpsilonTransitions() || matchTarget .GetNumberOfOptimizedTransitions() != 1 || !(matchTarget.GetOptimizedTransition( 0).target is RuleStopState)) { continue; } - switch (matchTransition.GetSerializationType()) + switch (matchTransition.SerializationType) { case Transition.Atom: case Transition.Range: @@ -529,7 +529,7 @@ namespace Antlr4.Runtime.Atn intermediateState.SetRuleIndex(target.ruleIndex); atn.AddState(intermediateState); optimizedTransitions.AddItem(new EpsilonTransition(intermediateState)); - switch (effective.GetSerializationType()) + switch (effective.SerializationType) { case Transition.Atom: { @@ -547,7 +547,7 @@ namespace Antlr4.Runtime.Atn case Transition.Set: { - intermediateState.AddTransition(new SetTransition(target, effective.Label())); + intermediateState.AddTransition(new SetTransition(target, effective.Label)); break; } @@ -589,7 +589,7 @@ namespace Antlr4.Runtime.Atn { Transition transition = state.GetOptimizedTransition(i); ATNState intermediate = transition.target; - if (transition.GetSerializationType() != Transition.Epsilon || intermediate.GetStateType + if (transition.SerializationType != Transition.Epsilon || intermediate.GetStateType () != ATNState.Basic || !intermediate.OnlyHasEpsilonTransitions()) { if (optimizedTransitions != null) @@ -600,7 +600,7 @@ namespace Antlr4.Runtime.Atn } for (int j = 0; j < intermediate.GetNumberOfOptimizedTransitions(); j++) { - if (intermediate.GetOptimizedTransition(j).GetSerializationType() != Transition.Epsilon) + if (intermediate.GetOptimizedTransition(j).SerializationType != Transition.Epsilon) { if (optimizedTransitions != null) { @@ -712,7 +712,7 @@ nextState_break: ; } else { - matchSet.AddAll(matchTransition.Label()); + matchSet.AddAll(matchTransition.Label); } } } @@ -821,7 +821,7 @@ nextState_break: ; .transitions; foreach (Transition t in transitions) { - if (t.GetSerializationType() != Transition.Epsilon) + if (t.SerializationType != Transition.Epsilon) { return false; } diff --git a/Antlr4.Runtime/Atn/ATNState.cs b/Antlr4.Runtime/Atn/ATNState.cs index 256b7397c..ec21b38d6 100644 --- a/Antlr4.Runtime/Atn/ATNState.cs +++ b/Antlr4.Runtime/Atn/ATNState.cs @@ -212,11 +212,11 @@ namespace Antlr4.Runtime.Atn { if (transitions.IsEmpty()) { - epsilonOnlyTransitions = e.IsEpsilon(); + epsilonOnlyTransitions = e.IsEpsilon; } else { - if (epsilonOnlyTransitions != e.IsEpsilon()) + if (epsilonOnlyTransitions != e.IsEpsilon) { System.Console.Error.Format("ATN state %d has both epsilon and non-epsilon transitions.\n" , stateNumber); diff --git a/Antlr4.Runtime/Atn/ActionTransition.cs b/Antlr4.Runtime/Atn/ActionTransition.cs index b21d4e5d8..0668bbf73 100644 --- a/Antlr4.Runtime/Atn/ActionTransition.cs +++ b/Antlr4.Runtime/Atn/ActionTransition.cs @@ -54,14 +54,20 @@ namespace Antlr4.Runtime.Atn this.isCtxDependent = isCtxDependent; } - public override int GetSerializationType() + public override int SerializationType { - return Action; + get + { + return Action; + } } - public override bool IsEpsilon() + public override bool IsEpsilon { - return true; + get + { + return true; + } } // we are to be ignored by analysis 'cept for predicates diff --git a/Antlr4.Runtime/Atn/ArrayPredictionContext.cs b/Antlr4.Runtime/Atn/ArrayPredictionContext.cs index 133282b8a..9142be4a4 100644 --- a/Antlr4.Runtime/Atn/ArrayPredictionContext.cs +++ b/Antlr4.Runtime/Atn/ArrayPredictionContext.cs @@ -79,24 +79,33 @@ namespace Antlr4.Runtime.Atn return System.Array.BinarySearch(returnStates, returnState); } - public override int Size() + public override int Size { - return returnStates.Length; + get + { + return returnStates.Length; + } } - public override bool IsEmpty() + public override bool IsEmpty { - return false; + get + { + return false; + } } - public override bool HasEmpty() + public override bool HasEmpty { - return returnStates[returnStates.Length - 1] == EmptyFullStateKey; + get + { + return returnStates[returnStates.Length - 1] == EmptyFullStateKey; + } } protected internal override PredictionContext AddEmptyContext() { - if (HasEmpty()) + if (HasEmpty) { return this; } @@ -109,7 +118,7 @@ namespace Antlr4.Runtime.Atn protected internal override PredictionContext RemoveEmptyContext() { - if (!HasEmpty()) + if (!HasEmpty) { return this; } @@ -134,11 +143,11 @@ namespace Antlr4.Runtime.Atn private static PredictionContext AppendContext(PredictionContext context, PredictionContext suffix, PredictionContext.IdentityHashMap visited) { - if (suffix.IsEmpty()) + if (suffix.IsEmpty) { if (IsEmptyLocal(suffix)) { - if (context.HasEmpty()) + if (context.HasEmpty) { return EmptyLocal; } @@ -146,21 +155,21 @@ namespace Antlr4.Runtime.Atn } return context; } - if (suffix.Size() != 1) + if (suffix.Size != 1) { throw new NotSupportedException("Appending a tree suffix is not yet supported."); } PredictionContext result = visited.Get(context); if (result == null) { - if (context.IsEmpty()) + if (context.IsEmpty) { result = suffix; } else { - int parentCount = context.Size(); - if (context.HasEmpty()) + int parentCount = context.Size; + if (context.HasEmpty) { parentCount--; } @@ -185,7 +194,7 @@ namespace Antlr4.Runtime.Atn result = new Antlr4.Runtime.Atn.ArrayPredictionContext(updatedParents, updatedReturnStates ); } - if (context.HasEmpty()) + if (context.HasEmpty) { result = PredictionContext.Join(result, suffix); } @@ -235,28 +244,28 @@ namespace Antlr4.Runtime.Atn { continue; } - int selfSize = operands.GetX().Size(); + int selfSize = operands.X.Size; if (selfSize == 0) { - if (!operands.GetX().Equals(operands.GetY())) + if (!operands.X.Equals(operands.Y)) { return false; } continue; } - int otherSize = operands.GetY().Size(); + int otherSize = operands.Y.Size; if (selfSize != otherSize) { return false; } for (int i = 0; i < selfSize; i++) { - if (operands.GetX().GetReturnState(i) != operands.GetY().GetReturnState(i)) + if (operands.X.GetReturnState(i) != operands.Y.GetReturnState(i)) { return false; } - PredictionContext selfParent = operands.GetX().GetParent(i); - PredictionContext otherParent = operands.GetY().GetParent(i); + PredictionContext selfParent = operands.X.GetParent(i); + PredictionContext otherParent = operands.Y.GetParent(i); if (selfParent.GetHashCode() != otherParent.GetHashCode()) { return false; diff --git a/Antlr4.Runtime/Atn/AtomTransition.cs b/Antlr4.Runtime/Atn/AtomTransition.cs index 8b496c3b1..826db46dd 100644 --- a/Antlr4.Runtime/Atn/AtomTransition.cs +++ b/Antlr4.Runtime/Atn/AtomTransition.cs @@ -45,15 +45,20 @@ namespace Antlr4.Runtime.Atn this.label = label; } - public override int GetSerializationType() + public override int SerializationType { - return Atom; + get + { + return Atom; + } } - [NotNull] - public override IntervalSet Label() + public override IntervalSet Label { - return IntervalSet.Of(label); + get + { + return IntervalSet.Of(label); + } } public override bool Matches(int symbol, int minVocabSymbol, int maxVocabSymbol) diff --git a/Antlr4.Runtime/Atn/EmptyPredictionContext.cs b/Antlr4.Runtime/Atn/EmptyPredictionContext.cs index bb5daebd3..e3a9e63bf 100644 --- a/Antlr4.Runtime/Atn/EmptyPredictionContext.cs +++ b/Antlr4.Runtime/Atn/EmptyPredictionContext.cs @@ -80,9 +80,12 @@ namespace Antlr4.Runtime.Atn return -1; } - public override int Size() + public override int Size { - return 0; + get + { + return 0; + } } public override PredictionContext AppendContext(int returnContext, PredictionContextCache @@ -97,14 +100,20 @@ namespace Antlr4.Runtime.Atn return suffix; } - public override bool IsEmpty() + public override bool IsEmpty { - return true; + get + { + return true; + } } - public override bool HasEmpty() + public override bool HasEmpty { - return true; + get + { + return true; + } } public override bool Equals(object o) diff --git a/Antlr4.Runtime/Atn/EpsilonTransition.cs b/Antlr4.Runtime/Atn/EpsilonTransition.cs index dfac1c386..d5c3fcd65 100644 --- a/Antlr4.Runtime/Atn/EpsilonTransition.cs +++ b/Antlr4.Runtime/Atn/EpsilonTransition.cs @@ -39,14 +39,20 @@ namespace Antlr4.Runtime.Atn { } - public override int GetSerializationType() + public override int SerializationType { - return Epsilon; + get + { + return Epsilon; + } } - public override bool IsEpsilon() + public override bool IsEpsilon { - return true; + get + { + return true; + } } public override bool Matches(int symbol, int minVocabSymbol, int maxVocabSymbol) diff --git a/Antlr4.Runtime/Atn/LL1Analyzer.cs b/Antlr4.Runtime/Atn/LL1Analyzer.cs index 10975f632..926b868bd 100644 --- a/Antlr4.Runtime/Atn/LL1Analyzer.cs +++ b/Antlr4.Runtime/Atn/LL1Analyzer.cs @@ -155,19 +155,19 @@ namespace Antlr4.Runtime.Atn } else { - if (ctx.IsEmpty() && addEOF) + if (ctx.IsEmpty && addEOF) { look.Add(IToken.Eof); return; } } - for (int i = 0; i < ctx.Size(); i++) + for (int i = 0; i < ctx.Size; i++) { if (ctx.GetReturnState(i) != PredictionContext.EmptyFullStateKey) { ATNState returnState = atn.states[ctx.GetReturnState(i)]; // System.out.println("popping back to "+retState); - for (int j = 0; j < ctx.Size(); j++) + for (int j = 0; j < ctx.Size; j++) { Look(returnState, ctx.GetParent(j), look, lookBusy, seeThruPreds, addEOF); } @@ -200,7 +200,7 @@ namespace Antlr4.Runtime.Atn } else { - if (t.IsEpsilon()) + if (t.IsEpsilon) { Look(t.target, ctx, look, lookBusy, seeThruPreds, addEOF); } @@ -213,7 +213,7 @@ namespace Antlr4.Runtime.Atn else { // System.out.println("adding "+ t); - IntervalSet set = t.Label(); + IntervalSet set = t.Label; if (set != null) { if (t is NotSetTransition) diff --git a/Antlr4.Runtime/Atn/LexerATNSimulator.cs b/Antlr4.Runtime/Atn/LexerATNSimulator.cs index ffbbfbf50..72656715d 100644 --- a/Antlr4.Runtime/Atn/LexerATNSimulator.cs +++ b/Antlr4.Runtime/Atn/LexerATNSimulator.cs @@ -139,7 +139,7 @@ namespace Antlr4.Runtime.Atn int mark = input.Mark(); try { - this.startIndex = input.Index(); + this.startIndex = input.Index; this.prevAccept.Reset(); DFAState s0 = atn.modeToDFA[mode].s0.Get(); if (s0 == null) @@ -282,7 +282,7 @@ namespace Antlr4.Runtime.Atn else { // if no accept and EOF is first char, return EOF - if (t == IIntStream.Eof && input.Index() == startIndex) + if (t == IIntStream.Eof && input.Index == startIndex) { return IToken.Eof; } @@ -400,20 +400,20 @@ namespace Antlr4.Runtime.Atn if (config.GetState() is RuleStopState) { PredictionContext context = config.GetContext(); - if (context.IsEmpty()) + if (context.IsEmpty) { configs.AddItem(config); return true; } else { - if (context.HasEmpty()) + if (context.HasEmpty) { configs.AddItem(config.Transform(config.GetState(), PredictionContext.EmptyFull)); return true; } } - for (int i = 0; i < context.Size(); i++) + for (int i = 0; i < context.Size; i++) { int returnStateNumber = context.GetReturnState(i); if (returnStateNumber == PredictionContext.EmptyFullStateKey) @@ -458,13 +458,13 @@ namespace Antlr4.Runtime.Atn t, ATNConfigSet configs, bool speculative) { ATNConfig c; - switch (t.GetSerializationType()) + switch (t.SerializationType) { case Transition.Rule: { RuleTransition ruleTransition = (RuleTransition)t; if (optimize_tail_calls && ruleTransition.optimizedTailCall && !config.GetContext - ().HasEmpty()) + ().HasEmpty) { c = config.Transform(t.target); } @@ -539,11 +539,10 @@ namespace Antlr4.Runtime.Atn /// sensitive values, including /// Antlr4.Runtime.Lexer.GetText() /// , - /// Antlr4.Runtime.Lexer.GetLine() + /// Antlr4.Runtime.Lexer.Line() /// , /// and - /// Antlr4.Runtime.Lexer.GetCharPositionInLine() - /// + /// Antlr4.Runtime.Lexer.Column() /// , properly reflect the current /// lexer state. This method should restore /// input @@ -586,7 +585,7 @@ namespace Antlr4.Runtime.Atn } int savedCharPositionInLine = charPositionInLine; int savedLine = line; - int index = input.Index(); + int index = input.Index; int marker = input.Mark(); try { @@ -605,7 +604,7 @@ namespace Antlr4.Runtime.Atn protected internal virtual void CaptureSimState(LexerATNSimulator.SimState settings , ICharStream input, DFAState dfaState) { - settings.index = input.Index(); + settings.index = input.Index; settings.line = line; settings.charPos = charPositionInLine; settings.dfaState = dfaState; @@ -690,7 +689,7 @@ namespace Antlr4.Runtime.Atn public virtual string GetText(ICharStream input) { // index is first lookahead char, don't include. - return input.GetText(Interval.Of(startIndex, input.Index() - 1)); + return input.GetText(Interval.Of(startIndex, input.Index - 1)); } public virtual int GetLine() diff --git a/Antlr4.Runtime/Atn/NotSetTransition.cs b/Antlr4.Runtime/Atn/NotSetTransition.cs index 12c9bcda8..41c0b814a 100644 --- a/Antlr4.Runtime/Atn/NotSetTransition.cs +++ b/Antlr4.Runtime/Atn/NotSetTransition.cs @@ -39,9 +39,12 @@ namespace Antlr4.Runtime.Atn { } - public override int GetSerializationType() + public override int SerializationType { - return NotSet; + get + { + return NotSet; + } } public override bool Matches(int symbol, int minVocabSymbol, int maxVocabSymbol) diff --git a/Antlr4.Runtime/Atn/ParserATNSimulator.cs b/Antlr4.Runtime/Atn/ParserATNSimulator.cs index 60d6074fb..13c033df0 100644 --- a/Antlr4.Runtime/Atn/ParserATNSimulator.cs +++ b/Antlr4.Runtime/Atn/ParserATNSimulator.cs @@ -343,7 +343,7 @@ namespace Antlr4.Runtime.Atn //dump(dfa); // start with the DFA int m = input.Mark(); - int index = input.Index(); + int index = input.Index; try { int alt = ExecDFA(dfa, input, index, state); @@ -371,17 +371,17 @@ namespace Antlr4.Runtime.Atn ParserRuleContext remainingContext = outerContext; System.Diagnostics.Debug.Assert(outerContext != null); DFAState s0 = dfa.s0full.Get(); - while (remainingContext != null && s0 != null && s0.IsContextSensitive()) + while (remainingContext != null && s0 != null && s0.IsContextSensitive) { remainingContext = SkipTailCalls(remainingContext); s0 = s0.GetContextTarget(GetReturnState(remainingContext)); if (remainingContext.IsEmpty()) { - System.Diagnostics.Debug.Assert(s0 == null || !s0.IsContextSensitive()); + System.Diagnostics.Debug.Assert(s0 == null || !s0.IsContextSensitive); } else { - remainingContext = ((ParserRuleContext)remainingContext.GetParent()); + remainingContext = ((ParserRuleContext)remainingContext.Parent); } } if (s0 == null) @@ -400,7 +400,7 @@ namespace Antlr4.Runtime.Atn } int alt = 0; int m = input.Mark(); - int index = input.Index(); + int index = input.Index; try { SimulatorState state = ComputeStartState(dfa, outerContext, useContext); @@ -452,7 +452,7 @@ namespace Antlr4.Runtime.Atn , remainingOuterContext); return ExecATN(dfa, input, startIndex, initialState); } - remainingOuterContext = ((ParserRuleContext)remainingOuterContext.GetParent()); + remainingOuterContext = ((ParserRuleContext)remainingOuterContext.Parent); s = next; } } @@ -523,7 +523,7 @@ namespace Antlr4.Runtime.Atn if (dfa.atnStartState is DecisionState) { if (!userWantsCtxSensitive || !acceptState.configs.GetDipsIntoOuterContext() || ( - treat_sllk1_conflict_as_ambiguity && input.Index() == startIndex)) + treat_sllk1_conflict_as_ambiguity && input.Index == startIndex)) { } else @@ -538,7 +538,7 @@ namespace Antlr4.Runtime.Atn // immediate decision if (acceptState.predicates != null) { - int conflictIndex = input.Index(); + int conflictIndex = input.Index; if (conflictIndex != startIndex) { input.Seek(startIndex); @@ -558,7 +558,7 @@ namespace Antlr4.Runtime.Atn if (reportAmbiguities) { SimulatorState fullContextState = ComputeStartState(dfa, outerContext, true); - ReportAttemptingFullContext(dfa, fullContextState, startIndex, input.Index()); + ReportAttemptingFullContext(dfa, fullContextState, startIndex, input.Index); } input.Seek(startIndex); return AdaptivePredict(input, dfa.decision, outerContext, true); @@ -569,7 +569,7 @@ namespace Antlr4.Runtime.Atn // disambiguating or validating predicates to evaluate if (s.predicates != null) { - int stopIndex = input.Index(); + int stopIndex = input.Index; if (startIndex != stopIndex) { input.Seek(startIndex); @@ -679,7 +679,7 @@ namespace Antlr4.Runtime.Atn .InvalidAltNumber; if (predictedAlt != ATN.InvalidAltNumber) { - if (optimize_ll1 && input.Index() == startIndex && nextState.outerContext == nextState + if (optimize_ll1 && input.Index == startIndex && nextState.outerContext == nextState .remainingOuterContext && dfa.decision >= 0 && !D.configs.HasSemanticContext()) { if (t >= 0 && t <= short.MaxValue) @@ -690,7 +690,7 @@ namespace Antlr4.Runtime.Atn } if (useContext && always_try_local_context) { - ReportContextSensitivity(dfa, nextState, startIndex, input.Index()); + ReportContextSensitivity(dfa, nextState, startIndex, input.Index); } } else @@ -701,12 +701,12 @@ namespace Antlr4.Runtime.Atn // int k = input.index() - startIndex + 1; // how much input we used // System.out.println("used k="+k); if (!userWantsCtxSensitive || !D.configs.GetDipsIntoOuterContext() || (treat_sllk1_conflict_as_ambiguity - && input.Index() == startIndex)) + && input.Index == startIndex)) { if (reportAmbiguities && !D.configs.HasSemanticContext()) { - ReportAmbiguity(dfa, D, startIndex, input.Index(), D.configs.GetConflictingAlts() - , D.configs); + ReportAmbiguity(dfa, D, startIndex, input.Index, D.configs.GetConflictingAlts(), + D.configs); } } else @@ -719,7 +719,7 @@ namespace Antlr4.Runtime.Atn DFAState.PredPrediction[] predPredictions = D.predicates; if (predPredictions != null) { - int conflictIndex = input.Index(); + int conflictIndex = input.Index; if (conflictIndex != startIndex) { input.Seek(startIndex); @@ -741,7 +741,7 @@ namespace Antlr4.Runtime.Atn SimulatorState fullContextState = ComputeStartState(dfa, outerContext, true); if (reportAmbiguities) { - ReportAttemptingFullContext(dfa, fullContextState, startIndex, input.Index()); + ReportAttemptingFullContext(dfa, fullContextState, startIndex, input.Index); } input.Seek(startIndex); return ExecATN(dfa, input, startIndex, fullContextState); @@ -750,7 +750,7 @@ namespace Antlr4.Runtime.Atn } if (D.predicates != null) { - int stopIndex = input.Index(); + int stopIndex = input.Index; if (startIndex != stopIndex) { input.Seek(startIndex); @@ -836,7 +836,7 @@ namespace Antlr4.Runtime.Atn { break; } - remainingGlobalContext = ((ParserRuleContext)remainingGlobalContext.GetParent()); + remainingGlobalContext = ((ParserRuleContext)remainingGlobalContext.Parent); s = next; } } @@ -870,7 +870,7 @@ namespace Antlr4.Runtime.Atn { if (c.GetState() is RuleStopState) { - System.Diagnostics.Debug.Assert(c.GetContext().IsEmpty()); + System.Diagnostics.Debug.Assert(c.GetContext().IsEmpty); if (useContext && !c.GetReachesIntoOuterContext() || t == IIntStream.Eof) { if (skippedStopStates == null) @@ -932,7 +932,7 @@ namespace Antlr4.Runtime.Atn } else { - remainingGlobalContext = ((ParserRuleContext)remainingGlobalContext.GetParent()); + remainingGlobalContext = ((ParserRuleContext)remainingGlobalContext.Parent); } contextElements.Add(nextContextElement); if (nextContextElement != PredictionContext.EmptyFullStateKey) @@ -1034,7 +1034,7 @@ namespace Antlr4.Runtime.Atn PredictionContextCache contextCache = new PredictionContextCache(); if (useContext) { - while (s0 != null && s0.IsContextSensitive() && remainingGlobalContext != null) + while (s0 != null && s0.IsContextSensitive && remainingGlobalContext != null) { DFAState next; remainingGlobalContext = SkipTailCalls(remainingGlobalContext); @@ -1049,7 +1049,7 @@ namespace Antlr4.Runtime.Atn previousContext = GetReturnState(remainingGlobalContext); next = s0.GetContextTarget(previousContext); initialContext = initialContext.AppendContext(previousContext, contextCache); - remainingGlobalContext = ((ParserRuleContext)remainingGlobalContext.GetParent()); + remainingGlobalContext = ((ParserRuleContext)remainingGlobalContext.Parent); } if (next == null) { @@ -1058,7 +1058,7 @@ namespace Antlr4.Runtime.Atn s0 = next; } } - if (s0 != null && !s0.IsContextSensitive()) + if (s0 != null && !s0.IsContextSensitive) { return new SimulatorState(globalContext, s0, useContext, remainingGlobalContext); } @@ -1111,7 +1111,7 @@ namespace Antlr4.Runtime.Atn } else { - remainingGlobalContext = ((ParserRuleContext)remainingGlobalContext.GetParent()); + remainingGlobalContext = ((ParserRuleContext)remainingGlobalContext.Parent); } if (nextContextElement != PredictionContext.EmptyFullStateKey) { @@ -1313,10 +1313,10 @@ namespace Antlr4.Runtime.Atn if (config.GetState() is RuleStopState) { // We hit rule end. If we have context info, use it - if (!config.GetContext().IsEmpty()) + if (!config.GetContext().IsEmpty) { - bool hasEmpty = config.GetContext().HasEmpty(); - int nonEmptySize = config.GetContext().Size() - (hasEmpty ? 1 : 0); + bool hasEmpty = config.GetContext().HasEmpty; + int nonEmptySize = config.GetContext().Size - (hasEmpty ? 1 : 0); for (int i = 0; i < nonEmptySize; i++) { PredictionContext newContext = config.GetContext().GetParent(i); @@ -1329,7 +1329,7 @@ namespace Antlr4.Runtime.Atn // Make sure we track that we are now out of context. c.SetOuterContextDepth(config.GetOuterContextDepth()); System.Diagnostics.Debug.Assert(depth > int.MinValue); - if (optimize_closure_busy && c.GetContext().IsEmpty() && !closureBusy.AddItem(c)) + if (optimize_closure_busy && c.GetContext().IsEmpty && !closureBusy.AddItem(c)) { continue; } @@ -1403,7 +1403,7 @@ namespace Antlr4.Runtime.Atn case ATNState.RuleStop: { - checkClosure = c.GetContext().IsEmpty(); + checkClosure = c.GetContext().IsEmpty; break; } @@ -1482,7 +1482,7 @@ namespace Antlr4.Runtime.Atn public virtual ATNConfig GetEpsilonTarget(ATNConfig config, Transition t, bool collectPredicates , bool inContext, PredictionContextCache contextCache) { - switch (t.GetSerializationType()) + switch (t.SerializationType) { case Transition.Rule: { @@ -2167,14 +2167,14 @@ namespace Antlr4.Runtime.Atn { ATNState state = atn.states[context.invokingState]; System.Diagnostics.Debug.Assert(state.GetNumberOfTransitions() == 1 && state.Transition - (0).GetSerializationType() == Transition.Rule); + (0).SerializationType == Transition.Rule); Antlr4.Runtime.Atn.RuleTransition transition = (Antlr4.Runtime.Atn.RuleTransition )state.Transition(0); if (!transition.tailCall) { break; } - context = ((ParserRuleContext)context.GetParent()); + context = ((ParserRuleContext)context.Parent); } return context; } diff --git a/Antlr4.Runtime/Atn/PrecedencePredicateTransition.cs b/Antlr4.Runtime/Atn/PrecedencePredicateTransition.cs index ec5e4c2fc..29489ca05 100644 --- a/Antlr4.Runtime/Atn/PrecedencePredicateTransition.cs +++ b/Antlr4.Runtime/Atn/PrecedencePredicateTransition.cs @@ -43,14 +43,20 @@ namespace Antlr4.Runtime.Atn this.precedence = precedence; } - public override int GetSerializationType() + public override int SerializationType { - return Precedence; + get + { + return Precedence; + } } - public override bool IsEpsilon() + public override bool IsEpsilon { - return true; + get + { + return true; + } } public override bool Matches(int symbol, int minVocabSymbol, int maxVocabSymbol) diff --git a/Antlr4.Runtime/Atn/PredicateTransition.cs b/Antlr4.Runtime/Atn/PredicateTransition.cs index 4857c87f1..5356561e2 100644 --- a/Antlr4.Runtime/Atn/PredicateTransition.cs +++ b/Antlr4.Runtime/Atn/PredicateTransition.cs @@ -61,14 +61,20 @@ namespace Antlr4.Runtime.Atn this.isCtxDependent = isCtxDependent; } - public override int GetSerializationType() + public override int SerializationType { - return Predicate; + get + { + return Predicate; + } } - public override bool IsEpsilon() + public override bool IsEpsilon { - return true; + get + { + return true; + } } public override bool Matches(int symbol, int minVocabSymbol, int maxVocabSymbol) diff --git a/Antlr4.Runtime/Atn/PredictionContext.cs b/Antlr4.Runtime/Atn/PredictionContext.cs index c960f0ee7..6cceb93c2 100644 --- a/Antlr4.Runtime/Atn/PredictionContext.cs +++ b/Antlr4.Runtime/Atn/PredictionContext.cs @@ -134,7 +134,10 @@ namespace Antlr4.Runtime.Atn return (InitialHash * HashMultiplier ^ parentHashCode) * HashMultiplier ^ returnStateHashCode; } - public abstract int Size(); + public abstract int Size + { + get; + } public abstract int GetReturnState(int index); @@ -203,19 +206,19 @@ namespace Antlr4.Runtime.Atn { return context0; } - if (context0.IsEmpty()) + if (context0.IsEmpty) { return IsEmptyLocal(context0) ? context0 : AddEmptyContext(context1); } else { - if (context1.IsEmpty()) + if (context1.IsEmpty) { return IsEmptyLocal(context1) ? context1 : AddEmptyContext(context0); } } - int context0size = context0.Size(); - int context1size = context1.Size(); + int context0size = context0.Size; + int context1size = context1.Size; if (context0size == 1 && context1size == 1 && context0.GetReturnState(0) == context1 .GetReturnState(0)) { @@ -339,7 +342,7 @@ namespace Antlr4.Runtime.Atn context, IConcurrentMap contextCache, PredictionContext.IdentityHashMap visited) { - if (context.IsEmpty()) + if (context.IsEmpty) { return context; } @@ -356,7 +359,7 @@ namespace Antlr4.Runtime.Atn } bool changed = false; Antlr4.Runtime.Atn.PredictionContext[] parents = new Antlr4.Runtime.Atn.PredictionContext - [context.Size()]; + [context.Size]; for (int i = 0; i < parents.Length; i++) { Antlr4.Runtime.Atn.PredictionContext parent = GetCachedContext(context.GetParent( @@ -365,8 +368,8 @@ namespace Antlr4.Runtime.Atn { if (!changed) { - parents = new Antlr4.Runtime.Atn.PredictionContext[context.Size()]; - for (int j = 0; j < context.Size(); j++) + parents = new Antlr4.Runtime.Atn.PredictionContext[context.Size]; + for (int j = 0; j < context.Size; j++) { parents[j] = context.GetParent(j); } @@ -414,9 +417,15 @@ namespace Antlr4.Runtime.Atn return new SingletonPredictionContext(this, returnState); } - public abstract bool IsEmpty(); + public abstract bool IsEmpty + { + get; + } - public abstract bool HasEmpty(); + public abstract bool HasEmpty + { + get; + } public sealed override int GetHashCode() { @@ -448,20 +457,20 @@ namespace Antlr4.Runtime.Atn int stateNumber = currentState; StringBuilder localBuffer = new StringBuilder(); localBuffer.Append("["); - while (!p.IsEmpty() && p != stop) + while (!p.IsEmpty && p != stop) { int index = 0; - if (p.Size() > 0) + if (p.Size > 0) { int bits = 1; - while ((1 << bits) < p.Size()) + while ((1 << bits) < p.Size) { bits++; } int mask = (1 << bits) - 1; index = (perm >> offset) & mask; - last &= index >= p.Size() - 1; - if (index >= p.Size()) + last &= index >= p.Size - 1; + if (index >= p.Size) { goto outer_continue; } @@ -483,7 +492,7 @@ namespace Antlr4.Runtime.Atn { if (p.GetReturnState(index) != EmptyFullStateKey) { - if (!p.IsEmpty()) + if (!p.IsEmpty) { if (localBuffer.Length > 1) { diff --git a/Antlr4.Runtime/Atn/PredictionContextCache.cs b/Antlr4.Runtime/Atn/PredictionContextCache.cs index 90c93b3df..431a6491d 100644 --- a/Antlr4.Runtime/Atn/PredictionContextCache.cs +++ b/Antlr4.Runtime/Atn/PredictionContextCache.cs @@ -174,14 +174,20 @@ namespace Antlr4.Runtime.Atn this.y = y; } - public PredictionContext GetX() + public PredictionContext X { - return x; + get + { + return x; + } } - public PredictionContext GetY() + public PredictionContext Y { - return y; + get + { + return y; + } } public override bool Equals(object obj) diff --git a/Antlr4.Runtime/Atn/RangeTransition.cs b/Antlr4.Runtime/Atn/RangeTransition.cs index 05fb2d46c..6f22f5d28 100644 --- a/Antlr4.Runtime/Atn/RangeTransition.cs +++ b/Antlr4.Runtime/Atn/RangeTransition.cs @@ -45,15 +45,20 @@ namespace Antlr4.Runtime.Atn this.to = to; } - public override int GetSerializationType() + public override int SerializationType { - return Range; + get + { + return Range; + } } - [NotNull] - public override IntervalSet Label() + public override IntervalSet Label { - return IntervalSet.Of(from, to); + get + { + return IntervalSet.Of(from, to); + } } public override bool Matches(int symbol, int minVocabSymbol, int maxVocabSymbol) diff --git a/Antlr4.Runtime/Atn/RuleTransition.cs b/Antlr4.Runtime/Atn/RuleTransition.cs index a1eb5a4ed..66be47b37 100644 --- a/Antlr4.Runtime/Atn/RuleTransition.cs +++ b/Antlr4.Runtime/Atn/RuleTransition.cs @@ -57,14 +57,20 @@ namespace Antlr4.Runtime.Atn this.followState = followState; } - public override int GetSerializationType() + public override int SerializationType { - return Rule; + get + { + return Rule; + } } - public override bool IsEpsilon() + public override bool IsEpsilon { - return true; + get + { + return true; + } } public override bool Matches(int symbol, int minVocabSymbol, int maxVocabSymbol) diff --git a/Antlr4.Runtime/Atn/SetTransition.cs b/Antlr4.Runtime/Atn/SetTransition.cs index fa8513a9c..b0474b44f 100644 --- a/Antlr4.Runtime/Atn/SetTransition.cs +++ b/Antlr4.Runtime/Atn/SetTransition.cs @@ -51,15 +51,20 @@ namespace Antlr4.Runtime.Atn this.set = set; } - public override int GetSerializationType() + public override int SerializationType { - return Set; + get + { + return Set; + } } - [NotNull] - public override IntervalSet Label() + public override IntervalSet Label { - return set; + get + { + return set; + } } public override bool Matches(int symbol, int minVocabSymbol, int maxVocabSymbol) diff --git a/Antlr4.Runtime/Atn/SingletonPredictionContext.cs b/Antlr4.Runtime/Atn/SingletonPredictionContext.cs index 005ac3635..6dff57647 100644 --- a/Antlr4.Runtime/Atn/SingletonPredictionContext.cs +++ b/Antlr4.Runtime/Atn/SingletonPredictionContext.cs @@ -67,19 +67,28 @@ namespace Antlr4.Runtime.Atn return this.returnState == returnState ? 0 : -1; } - public override int Size() + public override int Size { - return 1; + get + { + return 1; + } } - public override bool IsEmpty() + public override bool IsEmpty { - return false; + get + { + return false; + } } - public override bool HasEmpty() + public override bool HasEmpty { - return false; + get + { + return false; + } } public override PredictionContext AppendContext(PredictionContext suffix, PredictionContextCache diff --git a/Antlr4.Runtime/Atn/Transition.cs b/Antlr4.Runtime/Atn/Transition.cs index 84f2da870..49fefb0dc 100644 --- a/Antlr4.Runtime/Atn/Transition.cs +++ b/Antlr4.Runtime/Atn/Transition.cs @@ -115,18 +115,26 @@ namespace Antlr4.Runtime.Atn this.target = target; } - public abstract int GetSerializationType(); - - /// Are we epsilon, action, sempred? - public virtual bool IsEpsilon() + public abstract int SerializationType { - return false; + get; } - [Nullable] - public virtual IntervalSet Label() + /// Are we epsilon, action, sempred? + public virtual bool IsEpsilon { - return null; + get + { + return false; + } + } + + public virtual IntervalSet Label + { + get + { + return null; + } } public abstract bool Matches(int symbol, int minVocabSymbol, int maxVocabSymbol); diff --git a/Antlr4.Runtime/Atn/WildcardTransition.cs b/Antlr4.Runtime/Atn/WildcardTransition.cs index 34247c8d6..8438a9a69 100644 --- a/Antlr4.Runtime/Atn/WildcardTransition.cs +++ b/Antlr4.Runtime/Atn/WildcardTransition.cs @@ -39,9 +39,12 @@ namespace Antlr4.Runtime.Atn { } - public override int GetSerializationType() + public override int SerializationType { - return Wildcard; + get + { + return Wildcard; + } } public override bool Matches(int symbol, int minVocabSymbol, int maxVocabSymbol) diff --git a/Antlr4.Runtime/BailErrorStrategy.cs b/Antlr4.Runtime/BailErrorStrategy.cs index 3e29e46bd..1d7cfc7cc 100644 --- a/Antlr4.Runtime/BailErrorStrategy.cs +++ b/Antlr4.Runtime/BailErrorStrategy.cs @@ -57,7 +57,7 @@ namespace Antlr4.Runtime public override void Recover(Parser recognizer, RecognitionException e) { for (ParserRuleContext context = recognizer.GetContext(); context != null; context - = ((ParserRuleContext)context.GetParent())) + = ((ParserRuleContext)context.Parent)) { context.exception = e; } @@ -77,7 +77,7 @@ namespace Antlr4.Runtime { InputMismatchException e = new InputMismatchException(recognizer); for (ParserRuleContext context = recognizer.GetContext(); context != null; context - = ((ParserRuleContext)context.GetParent())) + = ((ParserRuleContext)context.Parent)) { context.exception = e; } diff --git a/Antlr4.Runtime/BufferedTokenStream.cs b/Antlr4.Runtime/BufferedTokenStream.cs index fa3183145..61d1edfc4 100644 --- a/Antlr4.Runtime/BufferedTokenStream.cs +++ b/Antlr4.Runtime/BufferedTokenStream.cs @@ -122,14 +122,20 @@ namespace Antlr4.Runtime this.tokenSource = tokenSource; } - public virtual ITokenSource GetTokenSource() + public virtual ITokenSource TokenSource { - return tokenSource; + get + { + return tokenSource; + } } - public virtual int Index() + public virtual int Index { - return p; + get + { + return p; + } } // public int range() { return range; } @@ -154,9 +160,12 @@ namespace Antlr4.Runtime p = AdjustSeekIndex(index); } - public virtual int Size() + public virtual int Size { - return tokens.Count; + get + { + return tokens.Count; + } } public virtual void Consume() @@ -217,10 +226,10 @@ namespace Antlr4.Runtime IToken t = tokenSource.NextToken(); if (t is IWritableToken) { - ((IWritableToken)t).SetTokenIndex(tokens.Count); + ((IWritableToken)t).TokenIndex = tokens.Count; } tokens.AddItem(t); - if (t.GetType() == IToken.Eof) + if (t.Type == IToken.Eof) { fetchedEOF = true; return i + 1; @@ -256,7 +265,7 @@ namespace Antlr4.Runtime for (int i = start; i <= stop; i++) { IToken t = tokens[i]; - if (t.GetType() == IToken.Eof) + if (t.Type == IToken.Eof) { break; } @@ -267,7 +276,7 @@ namespace Antlr4.Runtime public virtual int La(int i) { - return Lt(i).GetType(); + return Lt(i).Type; } protected internal virtual IToken Lb(int k) @@ -389,7 +398,7 @@ namespace Antlr4.Runtime for (int i = start; i <= stop; i++) { IToken t = tokens[i]; - if (types == null || types.Get(t.GetType())) + if (types == null || types.Get(t.Type)) { filteredTokens.AddItem(t); } @@ -426,13 +435,13 @@ namespace Antlr4.Runtime { Sync(i); IToken token = tokens[i]; - if (i >= Size()) + if (i >= Size) { return -1; } - while (token.GetChannel() != channel) + while (token.Channel != channel) { - if (token.GetType() == IToken.Eof) + if (token.Type == IToken.Eof) { return -1; } @@ -462,7 +471,7 @@ namespace Antlr4.Runtime /// protected internal virtual int PreviousTokenOnChannel(int i, int channel) { - while (i >= 0 && tokens[i].GetChannel() != channel) + while (i >= 0 && tokens[i].Channel != channel) { i--; } @@ -494,7 +503,7 @@ namespace Antlr4.Runtime // if none onchannel to right, nextOnChannel=-1 so set to = last token if (nextOnChannel == -1) { - to = Size() - 1; + to = Size - 1; } else { @@ -565,14 +574,14 @@ namespace Antlr4.Runtime IToken t = tokens[i]; if (channel == -1) { - if (t.GetChannel() != Lexer.DefaultTokenChannel) + if (t.Channel != Lexer.DefaultTokenChannel) { hidden.AddItem(t); } } else { - if (t.GetChannel() == channel) + if (t.Channel == channel) { hidden.AddItem(t); } @@ -585,9 +594,12 @@ namespace Antlr4.Runtime return hidden; } - public virtual string GetSourceName() + public virtual string SourceName { - return tokenSource.GetSourceName(); + get + { + return tokenSource.SourceName; + } } /// Get the text of all tokens in this buffer. @@ -596,7 +608,7 @@ namespace Antlr4.Runtime public virtual string GetText() { Fill(); - return GetText(Interval.Of(0, Size() - 1)); + return GetText(Interval.Of(0, Size - 1)); } [NotNull] @@ -617,11 +629,11 @@ namespace Antlr4.Runtime for (int i = start; i <= stop; i++) { IToken t = tokens[i]; - if (t.GetType() == IToken.Eof) + if (t.Type == IToken.Eof) { break; } - buf.Append(t.GetText()); + buf.Append(t.Text); } return buf.ToString(); } @@ -629,7 +641,7 @@ namespace Antlr4.Runtime [NotNull] public virtual string GetText(RuleContext ctx) { - return GetText(ctx.GetSourceInterval()); + return GetText(ctx.SourceInterval); } [NotNull] @@ -637,7 +649,7 @@ namespace Antlr4.Runtime { if (start != null && stop != null) { - return GetText(Interval.Of(start.GetTokenIndex(), stop.GetTokenIndex())); + return GetText(Interval.Of(start.TokenIndex, stop.TokenIndex)); } return string.Empty; } diff --git a/Antlr4.Runtime/CommonToken.cs b/Antlr4.Runtime/CommonToken.cs index 51689d184..b1802042e 100644 --- a/Antlr4.Runtime/CommonToken.cs +++ b/Antlr4.Runtime/CommonToken.cs @@ -84,8 +84,8 @@ namespace Antlr4.Runtime this.stop = stop; if (source.GetItem1() != null) { - this.line = source.GetItem1().GetLine(); - this.charPositionInLine = source.GetItem1().GetCharPositionInLine(); + this.line = source.GetItem1().Line; + this.charPositionInLine = source.GetItem1().Column; } } @@ -98,53 +98,47 @@ namespace Antlr4.Runtime public CommonToken(IToken oldToken) { - text = oldToken.GetText(); - type = oldToken.GetType(); - line = oldToken.GetLine(); - index = oldToken.GetTokenIndex(); - charPositionInLine = oldToken.GetCharPositionInLine(); - channel = oldToken.GetChannel(); - start = oldToken.GetStartIndex(); - stop = oldToken.GetStopIndex(); + text = oldToken.Text; + type = oldToken.Type; + line = oldToken.Line; + index = oldToken.TokenIndex; + charPositionInLine = oldToken.Column; + channel = oldToken.Channel; + start = oldToken.StartIndex; + stop = oldToken.StopIndex; if (oldToken is Antlr4.Runtime.CommonToken) { source = ((Antlr4.Runtime.CommonToken)oldToken).source; } else { - source = Tuple.Create(oldToken.GetTokenSource(), oldToken.GetInputStream()); + source = Tuple.Create(oldToken.TokenSource, oldToken.InputStream); } } - public virtual int GetType() + public virtual int Type { - return type; + get + { + return type; + } + set + { + int type = value; + this.type = type; + } } - public virtual void SetLine(int line) + public virtual int Line { - this.line = line; - } - - public virtual string GetText() - { - if (text != null) + get { - return text; + return line; } - ICharStream input = GetInputStream(); - if (input == null) + set { - return null; - } - int n = input.Size(); - if (start < n && stop < n) - { - return input.GetText(Interval.Of(start, stop)); - } - else - { - return ""; + int line = value; + this.line = line; } } @@ -155,44 +149,68 @@ namespace Antlr4.Runtime /// that start/stop indexes are not valid. It means that that input /// was converted to a new string in the token object. /// - public virtual void SetText(string text) + public virtual string Text { - this.text = text; + get + { + if (text != null) + { + return text; + } + ICharStream input = InputStream; + if (input == null) + { + return null; + } + int n = input.Size; + if (start < n && stop < n) + { + return input.GetText(Interval.Of(start, stop)); + } + else + { + return ""; + } + } + set + { + string text = value; + this.text = text; + } } - public virtual int GetLine() + public virtual int Column { - return line; + get + { + return charPositionInLine; + } + set + { + int charPositionInLine = value; + this.charPositionInLine = charPositionInLine; + } } - public virtual int GetCharPositionInLine() + public virtual int Channel { - return charPositionInLine; + get + { + return channel; + } + set + { + int channel = value; + this.channel = channel; + } } - public virtual void SetCharPositionInLine(int charPositionInLine) + public virtual int StartIndex { - this.charPositionInLine = charPositionInLine; - } - - public virtual int GetChannel() - { - return channel; - } - - public virtual void SetChannel(int channel) - { - this.channel = channel; - } - - public virtual void SetType(int type) - { - this.type = type; - } - - public virtual int GetStartIndex() - { - return start; + get + { + return start; + } } public virtual void SetStartIndex(int start) @@ -200,9 +218,12 @@ namespace Antlr4.Runtime this.start = start; } - public virtual int GetStopIndex() + public virtual int StopIndex { - return stop; + get + { + return stop; + } } public virtual void SetStopIndex(int stop) @@ -210,24 +231,33 @@ namespace Antlr4.Runtime this.stop = stop; } - public virtual int GetTokenIndex() + public virtual int TokenIndex { - return index; + get + { + return index; + } + set + { + int index = value; + this.index = index; + } } - public virtual void SetTokenIndex(int index) + public virtual ITokenSource TokenSource { - this.index = index; + get + { + return source.GetItem1(); + } } - public virtual ITokenSource GetTokenSource() + public virtual ICharStream InputStream { - return source.GetItem1(); - } - - public virtual ICharStream GetInputStream() - { - return source.GetItem2(); + get + { + return source.GetItem2(); + } } public override string ToString() @@ -237,7 +267,7 @@ namespace Antlr4.Runtime { channelStr = ",channel=" + channel; } - string txt = GetText(); + string txt = Text; if (txt != null) { txt = txt.ReplaceAll("\n", "\\\\n"); @@ -248,8 +278,8 @@ namespace Antlr4.Runtime { txt = ""; } - return "[@" + GetTokenIndex() + "," + start + ":" + stop + "='" + txt + "',<" + type - + ">" + channelStr + "," + line + ":" + GetCharPositionInLine() + "]"; + return "[@" + TokenIndex + "," + start + ":" + stop + "='" + txt + "',<" + type + + ">" + channelStr + "," + line + ":" + Column + "]"; } } } diff --git a/Antlr4.Runtime/CommonTokenFactory.cs b/Antlr4.Runtime/CommonTokenFactory.cs index 84f5f3449..423c89602 100644 --- a/Antlr4.Runtime/CommonTokenFactory.cs +++ b/Antlr4.Runtime/CommonTokenFactory.cs @@ -68,17 +68,17 @@ namespace Antlr4.Runtime int channel, int start, int stop, int line, int charPositionInLine) where _T0:ITokenSource { CommonToken t = new CommonToken(source, type, channel, start, stop); - t.SetLine(line); - t.SetCharPositionInLine(charPositionInLine); + t.Line = line; + t.Column = charPositionInLine; if (text != null) { - t.SetText(text); + t.Text = text; } else { if (copyText && source.GetItem2() != null) { - t.SetText(source.GetItem2().GetText(Interval.Of(start, stop))); + t.Text = source.GetItem2().GetText(Interval.Of(start, stop)); } } return t; diff --git a/Antlr4.Runtime/CommonTokenStream.cs b/Antlr4.Runtime/CommonTokenStream.cs index 17e7a3151..bd26f3a9e 100644 --- a/Antlr4.Runtime/CommonTokenStream.cs +++ b/Antlr4.Runtime/CommonTokenStream.cs @@ -141,11 +141,11 @@ namespace Antlr4.Runtime for (int i = 0; i < tokens.Count; i++) { IToken t = tokens[i]; - if (t.GetChannel() == channel) + if (t.Channel == channel) { n++; } - if (t.GetType() == IToken.Eof) + if (t.Type == IToken.Eof) { break; } diff --git a/Antlr4.Runtime/DefaultErrorStrategy.cs b/Antlr4.Runtime/DefaultErrorStrategy.cs index 5414b2cd5..a4d51371b 100644 --- a/Antlr4.Runtime/DefaultErrorStrategy.cs +++ b/Antlr4.Runtime/DefaultErrorStrategy.cs @@ -145,7 +145,7 @@ namespace Antlr4.Runtime // ", lastErrorIndex="+ // lastErrorIndex+ // ", states="+lastErrorStates); - if (lastErrorIndex == ((ITokenStream)recognizer.GetInputStream()).Index() && lastErrorStates + if (lastErrorIndex == ((ITokenStream)recognizer.GetInputStream()).Index && lastErrorStates != null && lastErrorStates.Contains(recognizer.GetState())) { // uh oh, another error at same token index and previously-visited @@ -157,7 +157,7 @@ namespace Antlr4.Runtime // System.err.println("FAILSAFE consumes "+recognizer.getTokenNames()[recognizer.getInputStream().LA(1)]); recognizer.Consume(); } - lastErrorIndex = ((ITokenStream)recognizer.GetInputStream()).Index(); + lastErrorIndex = ((ITokenStream)recognizer.GetInputStream()).Index; if (lastErrorStates == null) { lastErrorStates = new IntervalSet(); @@ -249,7 +249,7 @@ namespace Antlr4.Runtime string input; if (tokens != null) { - if (e.GetStartToken().GetType() == IToken.Eof) + if (e.GetStartToken().Type == IToken.Eof) { input = ""; } @@ -437,21 +437,21 @@ namespace Antlr4.Runtime } IToken current = currentSymbol; IToken lookback = ((ITokenStream)recognizer.GetInputStream()).Lt(-1); - if (current.GetType() == IToken.Eof && lookback != null) + if (current.Type == IToken.Eof && lookback != null) { current = lookback; } - return ConstructToken(((ITokenStream)recognizer.GetInputStream()).GetTokenSource( - ), expectedTokenType, tokenText, current); + return ConstructToken(((ITokenStream)recognizer.GetInputStream()).TokenSource, expectedTokenType + , tokenText, current); } protected internal virtual IToken ConstructToken(ITokenSource tokenSource, int expectedTokenType , string tokenText, IToken current) { - ITokenFactory factory = tokenSource.GetTokenFactory(); - return factory.Create(Tuple.Create(tokenSource, current.GetTokenSource().GetInputStream - ()), expectedTokenType, tokenText, IToken.DefaultChannel, -1, -1, current.GetLine - (), current.GetCharPositionInLine()); + ITokenFactory factory = tokenSource.TokenFactory; + return factory.Create(Tuple.Create(tokenSource, current.TokenSource.InputStream), + expectedTokenType, tokenText, IToken.DefaultChannel, -1, -1, current.Line, current + .Column); } public virtual IntervalSet GetExpectedTokens(Parser recognizer) @@ -496,12 +496,12 @@ namespace Antlr4.Runtime protected internal virtual string GetSymbolText(IToken symbol) { - return symbol.GetText(); + return symbol.Text; } protected internal virtual int GetSymbolType(IToken symbol) { - return symbol.GetType(); + return symbol.Type; } protected internal virtual string EscapeWSAndQuote(string s) diff --git a/Antlr4.Runtime/Dfa/DFASerializer.cs b/Antlr4.Runtime/Dfa/DFASerializer.cs index 6324f1d86..cb0b8b4b6 100644 --- a/Antlr4.Runtime/Dfa/DFASerializer.cs +++ b/Antlr4.Runtime/Dfa/DFASerializer.cs @@ -85,8 +85,8 @@ namespace Antlr4.Runtime.Dfa states.Sort(new _IComparer_85()); foreach (DFAState s in states) { - IDictionary edges = s.GetEdgeMap(); - IDictionary contextEdges = s.GetContextEdgeMap(); + IDictionary edges = s.EdgeMap; + IDictionary contextEdges = s.ContextEdgeMap; foreach (KeyValuePair entry in edges.EntrySet()) { if ((entry.Value == null || entry.Value == ATNSimulator.Error) && !s.IsContextSymbol @@ -115,7 +115,7 @@ namespace Antlr4.Runtime.Dfa } } } - if (s.IsContextSensitive()) + if (s.IsContextSensitive) { foreach (KeyValuePair entry_1 in contextEdges.EntrySet()) { @@ -204,7 +204,7 @@ namespace Antlr4.Runtime.Dfa stateStr = ":s" + n + "=>" + s.prediction; } } - if (s.IsContextSensitive()) + if (s.IsContextSensitive) { stateStr += "*"; foreach (ATNConfig config in s.configs) diff --git a/Antlr4.Runtime/Dfa/DFAState.cs b/Antlr4.Runtime/Dfa/DFAState.cs index ca8d5a824..7aee76338 100644 --- a/Antlr4.Runtime/Dfa/DFAState.cs +++ b/Antlr4.Runtime/Dfa/DFAState.cs @@ -154,14 +154,17 @@ namespace Antlr4.Runtime.Dfa this.maxSymbol = maxSymbol; } - public bool IsContextSensitive() + public bool IsContextSensitive { - return contextEdges != null; + get + { + return contextEdges != null; + } } public bool IsContextSymbol(int symbol) { - if (!IsContextSensitive() || symbol < minSymbol) + if (!IsContextSensitive || symbol < minSymbol) { return false; } @@ -170,7 +173,7 @@ namespace Antlr4.Runtime.Dfa public void SetContextSymbol(int symbol) { - System.Diagnostics.Debug.Assert(IsContextSensitive()); + System.Diagnostics.Debug.Assert(IsContextSensitive); if (symbol < minSymbol) { return; @@ -183,7 +186,7 @@ namespace Antlr4.Runtime.Dfa lock (this) { System.Diagnostics.Debug.Assert(!configs.IsOutermostConfigSet()); - if (IsContextSensitive()) + if (IsContextSensitive) { return; } @@ -213,13 +216,16 @@ namespace Antlr4.Runtime.Dfa } } - public virtual IDictionary GetEdgeMap() + public virtual IDictionary EdgeMap { - if (edges == null) + get { - return Sharpen.Collections.EmptyMap(); + if (edges == null) + { + return Sharpen.Collections.EmptyMap(); + } + return edges.ToMap(); } - return edges.ToMap(); } public virtual DFAState GetContextTarget(int invokingState) @@ -251,35 +257,38 @@ namespace Antlr4.Runtime.Dfa } } - public virtual IDictionary GetContextEdgeMap() + public virtual IDictionary ContextEdgeMap { - if (contextEdges == null) + get { - return Sharpen.Collections.EmptyMap(); - } - IDictionary map = contextEdges.ToMap(); - if (map.ContainsKey(-1)) - { - if (map.Count == 1) + if (contextEdges == null) { - return Sharpen.Collections.SingletonMap(PredictionContext.EmptyFullStateKey, map. - Get(-1)); + return Sharpen.Collections.EmptyMap(); } - else + IDictionary map = contextEdges.ToMap(); + if (map.ContainsKey(-1)) { - try + if (map.Count == 1) { - map.Put(PredictionContext.EmptyFullStateKey, Sharpen.Collections.Remove(map, -1)); + return Sharpen.Collections.SingletonMap(PredictionContext.EmptyFullStateKey, map. + Get(-1)); } - catch (NotSupportedException) + else { - // handles read only, non-singleton maps - map = new LinkedHashMap(map); - map.Put(PredictionContext.EmptyFullStateKey, Sharpen.Collections.Remove(map, -1)); + try + { + map.Put(PredictionContext.EmptyFullStateKey, Sharpen.Collections.Remove(map, -1)); + } + catch (NotSupportedException) + { + // handles read only, non-singleton maps + map = new LinkedHashMap(map); + map.Put(PredictionContext.EmptyFullStateKey, Sharpen.Collections.Remove(map, -1)); + } } } + return map; } - return map; } public override int GetHashCode() diff --git a/Antlr4.Runtime/IIntStream.cs b/Antlr4.Runtime/IIntStream.cs index c270304a7..a288192bc 100644 --- a/Antlr4.Runtime/IIntStream.cs +++ b/Antlr4.Runtime/IIntStream.cs @@ -28,7 +28,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ using Antlr4.Runtime; -using Antlr4.Runtime.Misc; using Sharpen; namespace Antlr4.Runtime @@ -69,7 +68,7 @@ namespace Antlr4.Runtime /// /// The value returned by - /// GetSourceName() + /// SourceName() /// when the actual name of the /// underlying source is not known. /// @@ -282,7 +281,10 @@ namespace Antlr4.Runtime /// has occurred after this stream was /// constructed. /// - public abstract int Index(); + internal abstract int Index + { + get; + } /// /// Set the input cursor to the position indicated by @@ -346,7 +348,10 @@ namespace Antlr4.Runtime /// if the size of the stream is /// unknown. /// - public abstract int Size(); + internal abstract int Size + { + get; + } /// Gets the name of the underlying symbol source. /// @@ -356,7 +361,9 @@ namespace Antlr4.Runtime /// UnknownSourceName /// . /// - [NotNull] - public abstract string GetSourceName(); + public abstract string SourceName + { + get; + } } } diff --git a/Antlr4.Runtime/IToken.cs b/Antlr4.Runtime/IToken.cs index 7e730fc74..58883fc53 100644 --- a/Antlr4.Runtime/IToken.cs +++ b/Antlr4.Runtime/IToken.cs @@ -81,23 +81,37 @@ namespace Antlr4.Runtime /// public const int HiddenChannel = 1; - /// Get the text of the token - public abstract string GetText(); + /// Get the text of the token. + /// Get the text of the token. + internal abstract string Text + { + get; + } - /// Get the token type of the token - public abstract int GetType(); + /// Get the token type of the token. + /// Get the token type of the token. + internal abstract int Type + { + get; + } /// /// The line number on which the 1st character of this token was matched, /// line=1..n /// - public abstract int GetLine(); + internal abstract int Line + { + get; + } /// /// The index of the first character of this token relative to the /// beginning of the line at which it occurs, 0..n-1 /// - public abstract int GetCharPositionInLine(); + internal abstract int Column + { + get; + } /// Return the channel this token. /// @@ -105,7 +119,10 @@ namespace Antlr4.Runtime /// on a different channel, but the parser only "tunes" to a single channel. /// The parser ignores everything not on DEFAULT_CHANNEL. /// - public abstract int GetChannel(); + internal abstract int Channel + { + get; + } /// An index from 0..n-1 of the token object in the input stream. /// @@ -115,7 +132,10 @@ namespace Antlr4.Runtime /// Return -1 to indicate that this token was conjured up since /// it doesn't have a valid index. /// - public abstract int GetTokenIndex(); + internal abstract int TokenIndex + { + get; + } /// /// The starting character index of the token @@ -125,27 +145,39 @@ namespace Antlr4.Runtime /// The starting character index of the token /// This method is optional; return -1 if not implemented. /// - public abstract int GetStartIndex(); + internal abstract int StartIndex + { + get; + } /// The last character index of the token. /// /// The last character index of the token. /// This method is optional; return -1 if not implemented. /// - public abstract int GetStopIndex(); + internal abstract int StopIndex + { + get; + } /// /// Gets the /// ITokenSource /// which created this token. /// - public abstract ITokenSource GetTokenSource(); + internal abstract ITokenSource TokenSource + { + get; + } /// /// Gets the /// ICharStream /// from which this token was derived. /// - public abstract ICharStream GetInputStream(); + internal abstract ICharStream InputStream + { + get; + } } } diff --git a/Antlr4.Runtime/ITokenSource.cs b/Antlr4.Runtime/ITokenSource.cs index aaf50bf07..5dd4e45a1 100644 --- a/Antlr4.Runtime/ITokenSource.cs +++ b/Antlr4.Runtime/ITokenSource.cs @@ -60,9 +60,15 @@ namespace Antlr4.Runtime /// IToken NextToken(); - int GetLine(); + int Line + { + get; + } - int GetCharPositionInLine(); + int Column + { + get; + } /// /// From what character stream was this token created? You don't have to @@ -74,7 +80,10 @@ namespace Antlr4.Runtime /// implement but it's nice to know where a Token comes from if you have /// include files etc... on the input. /// - ICharStream GetInputStream(); + ICharStream InputStream + { + get; + } /// /// Where are you getting tokens from? normally the implication will simply @@ -84,13 +93,18 @@ namespace Antlr4.Runtime /// Where are you getting tokens from? normally the implication will simply /// ask lexers input stream. /// - string GetSourceName(); + string SourceName + { + get; + } /// Gets the factory used for constructing tokens. /// Gets the factory used for constructing tokens. - ITokenFactory GetTokenFactory(); - /// Optional method that lets users set factory in lexer or other source - void SetTokenFactory(ITokenFactory factory); + ITokenFactory TokenFactory + { + get; + set; + } } } diff --git a/Antlr4.Runtime/ITokenStream.cs b/Antlr4.Runtime/ITokenStream.cs index 1859f79f5..596b77867 100644 --- a/Antlr4.Runtime/ITokenStream.cs +++ b/Antlr4.Runtime/ITokenStream.cs @@ -104,8 +104,10 @@ namespace Antlr4.Runtime /// which provides tokens for this /// stream. /// - [NotNull] - ITokenSource GetTokenSource(); + ITokenSource TokenSource + { + get; + } /// /// Return the text of all tokens within the specified @@ -213,7 +215,7 @@ namespace Antlr4.Runtime /// token, the behavior is unspecified. ///

/// For streams which ensure that the - /// IToken.GetTokenIndex() + /// IToken.TokenIndex() /// method is /// accurate for all of its provided tokens, this method behaves like the /// following code. Other streams may implement this method in other ways diff --git a/Antlr4.Runtime/IWritableToken.cs b/Antlr4.Runtime/IWritableToken.cs index 2b02e218e..add55022d 100644 --- a/Antlr4.Runtime/IWritableToken.cs +++ b/Antlr4.Runtime/IWritableToken.cs @@ -34,16 +34,34 @@ namespace Antlr4.Runtime { public interface IWritableToken : IToken { - void SetText(string text); + string Text + { + set; + } - void SetType(int ttype); + int Type + { + set; + } - void SetLine(int line); + int Line + { + set; + } - void SetCharPositionInLine(int pos); + int Column + { + set; + } - void SetChannel(int channel); + int Channel + { + set; + } - void SetTokenIndex(int index); + int TokenIndex + { + set; + } } } diff --git a/Antlr4.Runtime/Lexer.cs b/Antlr4.Runtime/Lexer.cs index 79c7565eb..976248b5d 100644 --- a/Antlr4.Runtime/Lexer.cs +++ b/Antlr4.Runtime/Lexer.cs @@ -179,7 +179,7 @@ namespace Antlr4.Runtime } _token = null; _channel = IToken.DefaultChannel; - _tokenStartCharIndex = _input.Index(); + _tokenStartCharIndex = _input.Index; _tokenStartCharPositionInLine = GetInterpreter().GetCharPositionInLine(); _tokenStartLine = GetInterpreter().GetLine(); _text = null; @@ -274,14 +274,17 @@ outer_break: ; return _mode; } - public virtual ITokenFactory GetTokenFactory() + public virtual ITokenFactory TokenFactory { - return _factory; - } - - public virtual void SetTokenFactory(ITokenFactory factory) - { - this._factory = factory; + get + { + return _factory; + } + set + { + ITokenFactory factory = value; + this._factory = factory; + } } ///

Set the char stream and reset the lexer @@ -294,9 +297,12 @@ outer_break: ; this._tokenFactorySourcePair = Tuple.Create(this, _input); } - public virtual string GetSourceName() + public virtual string SourceName { - return _input.GetSourceName(); + get + { + return _input.SourceName; + } } public override IIntStream GetInputStream() @@ -341,28 +347,34 @@ outer_break: ; public virtual IToken EmitEOF() { - int cpos = GetCharPositionInLine(); + int cpos = Column; // The character position for EOF is one beyond the position of // the previous token's last character if (_token != null) { - int n = _token.GetStopIndex() - _token.GetStartIndex() + 1; - cpos = _token.GetCharPositionInLine() + n; + int n = _token.StopIndex - _token.StartIndex + 1; + cpos = _token.Column + n; } IToken eof = _factory.Create(_tokenFactorySourcePair, IToken.Eof, null, IToken.DefaultChannel - , _input.Index(), _input.Index() - 1, GetLine(), cpos); + , _input.Index, _input.Index - 1, Line, cpos); Emit(eof); return eof; } - public virtual int GetLine() + public virtual int Line { - return GetInterpreter().GetLine(); + get + { + return GetInterpreter().GetLine(); + } } - public virtual int GetCharPositionInLine() + public virtual int Column { - return GetInterpreter().GetCharPositionInLine(); + get + { + return GetInterpreter().GetCharPositionInLine(); + } } public virtual void SetLine(int line) @@ -378,7 +390,7 @@ outer_break: ; /// What is the index of the current character of lookahead? public virtual int GetCharIndex() { - return _input.Index(); + return _input.Index; } /// @@ -471,7 +483,7 @@ outer_break: ; { IList tokens = new List(); IToken t = NextToken(); - while (t.GetType() != IToken.Eof) + while (t.Type != IToken.Eof) { tokens.AddItem(t); t = NextToken(); @@ -490,7 +502,7 @@ outer_break: ; public virtual void NotifyListeners(LexerNoViableAltException e) { - string text = _input.GetText(Interval.Of(_tokenStartCharIndex, _input.Index())); + string text = _input.GetText(Interval.Of(_tokenStartCharIndex, _input.Index)); string msg = "token recognition error at: '" + GetErrorDisplay(text) + "'"; IAntlrErrorListener listener = GetErrorListenerDispatch(); listener.SyntaxError(this, null, _tokenStartLine, _tokenStartCharPositionInLine, diff --git a/Antlr4.Runtime/LexerNoViableAltException.cs b/Antlr4.Runtime/LexerNoViableAltException.cs index f329cbd2b..fa5d19b6d 100644 --- a/Antlr4.Runtime/LexerNoViableAltException.cs +++ b/Antlr4.Runtime/LexerNoViableAltException.cs @@ -73,7 +73,7 @@ namespace Antlr4.Runtime public override string ToString() { string symbol = string.Empty; - if (startIndex >= 0 && startIndex < ((ICharStream)GetInputStream()).Size()) + if (startIndex >= 0 && startIndex < ((ICharStream)GetInputStream()).Size) { symbol = ((ICharStream)GetInputStream()).GetText(Interval.Of(startIndex, startIndex )); diff --git a/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs b/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs index 27269ac3a..1d2c4f61b 100644 --- a/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs +++ b/Antlr4.Runtime/Misc/RuleDependencyProcessor.cs @@ -742,7 +742,7 @@ namespace Antlr4.Runtime.Misc } foreach (Transition transition in state.GetTransitions()) { - if (transition.GetSerializationType() != Transition.Rule) + if (transition.SerializationType != Transition.Rule) { continue; } diff --git a/Antlr4.Runtime/Parser.cs b/Antlr4.Runtime/Parser.cs index e447ee8bc..562c0205a 100644 --- a/Antlr4.Runtime/Parser.cs +++ b/Antlr4.Runtime/Parser.cs @@ -49,13 +49,13 @@ namespace Antlr4.Runtime public virtual void EnterEveryRule(ParserRuleContext ctx) { System.Console.Out.WriteLine("enter " + this._enclosing.GetRuleNames()[ctx.GetRuleIndex - ()] + ", LT(1)=" + this._enclosing._input.Lt(1).GetText()); + ()] + ", LT(1)=" + this._enclosing._input.Lt(1).Text); } public virtual void ExitEveryRule(ParserRuleContext ctx) { System.Console.Out.WriteLine("exit " + this._enclosing.GetRuleNames()[ctx.GetRuleIndex - ()] + ", LT(1)=" + this._enclosing._input.Lt(1).GetText()); + ()] + ", LT(1)=" + this._enclosing._input.Lt(1).Text); } public virtual void VisitErrorNode(IErrorNode node) @@ -64,8 +64,8 @@ namespace Antlr4.Runtime public virtual void VisitTerminal(ITerminalNode node) { - ParserRuleContext parent = (ParserRuleContext)node.GetParent().GetRuleContext(); - IToken token = node.GetSymbol(); + ParserRuleContext parent = (ParserRuleContext)((IRuleNode)node.Parent).RuleContext; + IToken token = node.Symbol; System.Console.Out.WriteLine("consume " + token + " rule " + this._enclosing.GetRuleNames ()[parent.GetRuleIndex()] + " alt=" + parent.altNum); } @@ -182,7 +182,7 @@ namespace Antlr4.Runtime public virtual IToken Match(int ttype) { IToken t = GetCurrentToken(); - if (t.GetType() == ttype) + if (t.Type == ttype) { _errHandler.EndErrorCondition(this); Consume(); @@ -190,7 +190,7 @@ namespace Antlr4.Runtime else { t = _errHandler.RecoverInline(this); - if (_buildParseTrees && t.GetTokenIndex() == -1) + if (_buildParseTrees && t.TokenIndex == -1) { // we must have conjured up a new token during single token insertion // if it's not the current symbol @@ -204,7 +204,7 @@ namespace Antlr4.Runtime public virtual IToken MatchWildcard() { IToken t = GetCurrentToken(); - if (t.GetType() > 0) + if (t.Type > 0) { _errHandler.EndErrorCondition(this); Consume(); @@ -212,7 +212,7 @@ namespace Antlr4.Runtime else { t = _errHandler.RecoverInline(this); - if (_buildParseTrees && t.GetTokenIndex() == -1) + if (_buildParseTrees && t.TokenIndex == -1) { // we must have conjured up a new token during single token insertion // if it's not the current symbol @@ -464,8 +464,8 @@ namespace Antlr4.Runtime int charPositionInLine = -1; if (offendingToken != null) { - line = offendingToken.GetLine(); - charPositionInLine = offendingToken.GetCharPositionInLine(); + line = offendingToken.Line; + charPositionInLine = offendingToken.Column; } IAntlrErrorListener listener = ((IParserErrorListener)GetErrorListenerDispatch ()); @@ -486,7 +486,7 @@ namespace Antlr4.Runtime public virtual IToken Consume() { IToken o = GetCurrentToken(); - if (o.GetType() != Eof) + if (o.Type != Eof) { ((ITokenStream)GetInputStream()).Consume(); } @@ -559,8 +559,8 @@ namespace Antlr4.Runtime SetState(state); if (_buildParseTrees) { - ParserRuleContext factoredContext = (ParserRuleContext)_ctx.GetChild(_ctx.GetChildCount - () - 1); + ParserRuleContext factoredContext = (ParserRuleContext)_ctx.GetChild(_ctx.ChildCount + - 1); _ctx.RemoveLastChild(); factoredContext.parent = localctx; localctx.AddChild(factoredContext); @@ -868,7 +868,7 @@ namespace Antlr4.Runtime public virtual string GetSourceName() { - return _input.GetSourceName(); + return _input.SourceName; } /// A convenience method for use most often with template rewrites. @@ -885,7 +885,7 @@ namespace Antlr4.Runtime IList strings = new List(tokens.Count); for (int i = 0; i < tokens.Count; i++) { - strings.AddItem(tokens[i].GetText()); + strings.AddItem(tokens[i].Text); } return strings; } diff --git a/Antlr4.Runtime/ParserRuleContext.cs b/Antlr4.Runtime/ParserRuleContext.cs index 8ef9212c3..14e660ec8 100644 --- a/Antlr4.Runtime/ParserRuleContext.cs +++ b/Antlr4.Runtime/ParserRuleContext.cs @@ -223,9 +223,12 @@ namespace Antlr4.Runtime return t; } - public override RuleContext GetParent() + public override RuleContext Parent { - return (Antlr4.Runtime.ParserRuleContext)base.GetParent(); + get + { + return (Antlr4.Runtime.ParserRuleContext)base.Parent; + } } public override IParseTree GetChild(int i) @@ -269,8 +272,8 @@ namespace Antlr4.Runtime if (o is ITerminalNode) { ITerminalNode tnode = (ITerminalNode)o; - IToken symbol = tnode.GetSymbol(); - if (symbol.GetType() == ttype) + IToken symbol = tnode.Symbol; + if (symbol.Type == ttype) { j++; if (j == i) @@ -295,8 +298,8 @@ namespace Antlr4.Runtime if (o is ITerminalNode) { ITerminalNode tnode = (ITerminalNode)o; - IToken symbol = tnode.GetSymbol(); - if (symbol.GetType() == ttype) + IToken symbol = tnode.Symbol; + if (symbol.Type == ttype) { if (tokens == null) { @@ -345,18 +348,24 @@ namespace Antlr4.Runtime return contexts; } - public override int GetChildCount() + public override int ChildCount { - return children != null ? children.Count : 0; + get + { + return children != null ? children.Count : 0; + } } - public override Interval GetSourceInterval() + public override Interval SourceInterval { - if (start == null || stop == null) + get { - return Interval.Invalid; + if (start == null || stop == null) + { + return Interval.Invalid; + } + return Interval.Of(start.TokenIndex, stop.TokenIndex); } - return Interval.Of(start.GetTokenIndex(), stop.GetTokenIndex()); } public virtual IToken GetStart() diff --git a/Antlr4.Runtime/Recognizer`2.cs b/Antlr4.Runtime/Recognizer`2.cs index 0dc8d6fdd..aa7e5851e 100644 --- a/Antlr4.Runtime/Recognizer`2.cs +++ b/Antlr4.Runtime/Recognizer`2.cs @@ -96,8 +96,8 @@ namespace Antlr4.Runtime /// What is the error header, normally line/character position information? public virtual string GetErrorHeader(RecognitionException e) { - int line = e.GetOffendingToken().GetLine(); - int charPositionInLine = e.GetOffendingToken().GetCharPositionInLine(); + int line = e.GetOffendingToken().Line; + int charPositionInLine = e.GetOffendingToken().Column; return "line " + line + ":" + charPositionInLine; } @@ -121,16 +121,16 @@ namespace Antlr4.Runtime { return ""; } - string s = t.GetText(); + string s = t.Text; if (s == null) { - if (t.GetType() == IToken.Eof) + if (t.Type == IToken.Eof) { s = ""; } else { - s = "<" + t.GetType() + ">"; + s = "<" + t.Type + ">"; } } s = s.ReplaceAll("\n", "\\\\n"); diff --git a/Antlr4.Runtime/RuleContext.cs b/Antlr4.Runtime/RuleContext.cs index e104b68e2..bb68d2482 100644 --- a/Antlr4.Runtime/RuleContext.cs +++ b/Antlr4.Runtime/RuleContext.cs @@ -116,25 +116,37 @@ namespace Antlr4.Runtime return invokingState == -1; } - // satisfy the ParseTree / SyntaxTree interface - public virtual Interval GetSourceInterval() + public virtual Interval SourceInterval { - return Interval.Invalid; + get + { + // satisfy the ParseTree / SyntaxTree interface + return Interval.Invalid; + } } - public virtual Antlr4.Runtime.RuleContext GetRuleContext() + public virtual Antlr4.Runtime.RuleContext RuleContext { - return this; + get + { + return this; + } } - public virtual Antlr4.Runtime.RuleContext GetParent() + public virtual Antlr4.Runtime.RuleContext Parent { - return parent; + get + { + return parent; + } } - public virtual Antlr4.Runtime.RuleContext GetPayload() + public virtual Antlr4.Runtime.RuleContext Payload { - return this; + get + { + return this; + } } /// Return the combined text of all child nodes. @@ -148,12 +160,12 @@ namespace Antlr4.Runtime /// public virtual string GetText() { - if (GetChildCount() == 0) + if (ChildCount == 0) { return string.Empty; } StringBuilder builder = new StringBuilder(); - for (int i = 0; i < GetChildCount(); i++) + for (int i = 0; i < ChildCount; i++) { builder.Append(GetChild(i).GetText()); } @@ -170,9 +182,12 @@ namespace Antlr4.Runtime return null; } - public virtual int GetChildCount() + public virtual int ChildCount { - return 0; + get + { + return 0; + } } public virtual T Accept(IParseTreeVisitor<_T1> visitor) where _T1:T diff --git a/Antlr4.Runtime/TokenStreamRewriter.cs b/Antlr4.Runtime/TokenStreamRewriter.cs index 95cb4c017..ac71f1744 100644 --- a/Antlr4.Runtime/TokenStreamRewriter.cs +++ b/Antlr4.Runtime/TokenStreamRewriter.cs @@ -156,9 +156,9 @@ namespace Antlr4.Runtime public override int Execute(StringBuilder buf) { buf.Append(text); - if (tokens.Get(index).GetType() != IToken.Eof) + if (tokens.Get(index).Type != IToken.Eof) { - buf.Append(tokens.Get(index).GetText()); + buf.Append(tokens.Get(index).Text); } return index + 1; } @@ -278,7 +278,7 @@ namespace Antlr4.Runtime public virtual void InsertAfter(string programName, IToken t, object text) { - InsertAfter(programName, t.GetTokenIndex(), text); + InsertAfter(programName, t.TokenIndex, text); } public virtual void InsertAfter(string programName, int index, object text) @@ -299,7 +299,7 @@ namespace Antlr4.Runtime public virtual void InsertBefore(string programName, IToken t, object text) { - InsertBefore(programName, t.GetTokenIndex(), text); + InsertBefore(programName, t.TokenIndex, text); } public virtual void InsertBefore(string programName, int index, object text) @@ -333,10 +333,10 @@ namespace Antlr4.Runtime public virtual void Replace(string programName, int from, int to, object text) { - if (from > to || from < 0 || to < 0 || to >= tokens.Size()) + if (from > to || from < 0 || to < 0 || to >= tokens.Size) { throw new ArgumentException("replace: range invalid: " + from + ".." + to + "(size=" - + tokens.Size() + ")"); + + tokens.Size + ")"); } TokenStreamRewriter.RewriteOperation op = new TokenStreamRewriter.ReplaceOp(tokens , from, to, text); @@ -348,7 +348,7 @@ namespace Antlr4.Runtime public virtual void Replace(string programName, IToken from, IToken to, object text ) { - Replace(programName, from.GetTokenIndex(), to.GetTokenIndex(), text); + Replace(programName, from.TokenIndex, to.TokenIndex, text); } public virtual void Delete(int index) @@ -432,7 +432,7 @@ namespace Antlr4.Runtime /// public virtual string GetText() { - return GetText(DefaultProgramName, Interval.Of(0, tokens.Size() - 1)); + return GetText(DefaultProgramName, Interval.Of(0, tokens.Size - 1)); } /// @@ -460,9 +460,9 @@ namespace Antlr4.Runtime int start = interval.a; int stop = interval.b; // ensure start/end are in range - if (stop > tokens.Size() - 1) + if (stop > tokens.Size - 1) { - stop = tokens.Size() - 1; + stop = tokens.Size - 1; } if (start < 0) { @@ -479,7 +479,7 @@ namespace Antlr4.Runtime (rewrites); // Walk buffer, executing instructions and emitting tokens int i = start; - while (i <= stop && i < tokens.Size()) + while (i <= stop && i < tokens.Size) { TokenStreamRewriter.RewriteOperation op = indexToOp.Get(i); Sharpen.Collections.Remove(indexToOp, i); @@ -488,9 +488,9 @@ namespace Antlr4.Runtime if (op == null) { // no operation at that index, just dump token - if (t.GetType() != IToken.Eof) + if (t.Type != IToken.Eof) { - buf.Append(t.GetText()); + buf.Append(t.Text); } i++; } @@ -504,13 +504,13 @@ namespace Antlr4.Runtime // include stuff after end if it's last index in buffer // So, if they did an insertAfter(lastValidIndex, "foo"), include // foo if end==lastValidIndex. - if (stop == tokens.Size() - 1) + if (stop == tokens.Size - 1) { // Scan any remaining operations after last token // should be included (they will be inserts). foreach (TokenStreamRewriter.RewriteOperation op in indexToOp.Values) { - if (op.index >= tokens.Size() - 1) + if (op.index >= tokens.Size - 1) { buf.Append(op.text); } diff --git a/Antlr4.Runtime/Tree/AbstractParseTreeVisitor`1.cs b/Antlr4.Runtime/Tree/AbstractParseTreeVisitor`1.cs index 49c80b829..1e5b6150d 100644 --- a/Antlr4.Runtime/Tree/AbstractParseTreeVisitor`1.cs +++ b/Antlr4.Runtime/Tree/AbstractParseTreeVisitor`1.cs @@ -72,7 +72,7 @@ namespace Antlr4.Runtime.Tree public virtual Result VisitChildren(IRuleNode node) { Result result = DefaultResult(); - int n = node.GetChildCount(); + int n = node.ChildCount; for (int i = 0; i < n; i++) { if (!ShouldVisitNextChild(node, result)) diff --git a/Antlr4.Runtime/Tree/IParseTree.cs b/Antlr4.Runtime/Tree/IParseTree.cs index 2f02430b2..d6530fcf3 100644 --- a/Antlr4.Runtime/Tree/IParseTree.cs +++ b/Antlr4.Runtime/Tree/IParseTree.cs @@ -49,9 +49,12 @@ namespace Antlr4.Runtime.Tree /// public interface IParseTree : ISyntaxTree { - // the following methods narrow the return type; they are not additional methods - IParseTree GetParent(); + IParseTree Parent + { + get; + } + // the following methods narrow the return type; they are not additional methods IParseTree GetChild(int i); /// diff --git a/Antlr4.Runtime/Tree/IRuleNode.cs b/Antlr4.Runtime/Tree/IRuleNode.cs index 33cbdc9ae..c7098d0d6 100644 --- a/Antlr4.Runtime/Tree/IRuleNode.cs +++ b/Antlr4.Runtime/Tree/IRuleNode.cs @@ -27,7 +27,6 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -using Antlr4.Runtime; using Antlr4.Runtime.Tree; using Sharpen; @@ -35,8 +34,14 @@ namespace Antlr4.Runtime.Tree { public interface IRuleNode : IParseTree { - RuleContext GetRuleContext(); + Antlr4.Runtime.RuleContext RuleContext + { + get; + } - IRuleNode GetParent(); + IRuleNode Parent + { + get; + } } } diff --git a/Antlr4.Runtime/Tree/ISyntaxTree.cs b/Antlr4.Runtime/Tree/ISyntaxTree.cs index 2ad7e3a5f..ef2ca13f1 100644 --- a/Antlr4.Runtime/Tree/ISyntaxTree.cs +++ b/Antlr4.Runtime/Tree/ISyntaxTree.cs @@ -58,7 +58,9 @@ namespace Antlr4.Runtime.Tree /// /// . /// - [NotNull] - Interval GetSourceInterval(); + Interval SourceInterval + { + get; + } } } diff --git a/Antlr4.Runtime/Tree/ITerminalNode.cs b/Antlr4.Runtime/Tree/ITerminalNode.cs index 7103956ae..b086eb541 100644 --- a/Antlr4.Runtime/Tree/ITerminalNode.cs +++ b/Antlr4.Runtime/Tree/ITerminalNode.cs @@ -35,8 +35,14 @@ namespace Antlr4.Runtime.Tree { public interface ITerminalNode : IParseTree { - IToken GetSymbol(); + IToken Symbol + { + get; + } - IRuleNode GetParent(); + IRuleNode Parent + { + get; + } } } diff --git a/Antlr4.Runtime/Tree/ITree.cs b/Antlr4.Runtime/Tree/ITree.cs index 66d065007..f71b11c59 100644 --- a/Antlr4.Runtime/Tree/ITree.cs +++ b/Antlr4.Runtime/Tree/ITree.cs @@ -45,7 +45,10 @@ namespace Antlr4.Runtime.Tree /// The parent of this node. If the return value is null, then this /// node is the root of the tree. /// - ITree GetParent(); + ITree Parent + { + get; + } /// This method returns whatever object represents the data at this note. /// @@ -60,7 +63,10 @@ namespace Antlr4.Runtime.Tree /// Antlr4.Runtime.IToken /// object. /// - object GetPayload(); + object Payload + { + get; + } /// /// If there are children, get the @@ -77,7 +83,10 @@ namespace Antlr4.Runtime.Tree /// How many children are there? If there is none, then this /// node represents a leaf node. /// - int GetChildCount(); + int ChildCount + { + get; + } /// /// Print out a whole tree, not just a node, in LISP format diff --git a/Antlr4.Runtime/Tree/ParseTreeWalker.cs b/Antlr4.Runtime/Tree/ParseTreeWalker.cs index c2f3e42dc..53e0a1673 100644 --- a/Antlr4.Runtime/Tree/ParseTreeWalker.cs +++ b/Antlr4.Runtime/Tree/ParseTreeWalker.cs @@ -54,7 +54,7 @@ namespace Antlr4.Runtime.Tree } IRuleNode r = (IRuleNode)t; EnterRule(listener, r); - int n = r.GetChildCount(); + int n = r.ChildCount; for (int i = 0; i < n; i++) { Walk(listener, r.GetChild(i)); @@ -74,7 +74,7 @@ namespace Antlr4.Runtime.Tree protected internal virtual void EnterRule(IParseTreeListener listener, IRuleNode r) { - ParserRuleContext ctx = (ParserRuleContext)r.GetRuleContext(); + ParserRuleContext ctx = (ParserRuleContext)r.RuleContext; listener.EnterEveryRule(ctx); ctx.EnterRule(listener); } @@ -82,7 +82,7 @@ namespace Antlr4.Runtime.Tree protected internal virtual void ExitRule(IParseTreeListener listener, IRuleNode r ) { - ParserRuleContext ctx = (ParserRuleContext)r.GetRuleContext(); + ParserRuleContext ctx = (ParserRuleContext)r.RuleContext; ctx.ExitRule(listener); listener.ExitEveryRule(ctx); } diff --git a/Antlr4.Runtime/Tree/TerminalNodeImpl.cs b/Antlr4.Runtime/Tree/TerminalNodeImpl.cs index c5dc2d319..db338eb15 100644 --- a/Antlr4.Runtime/Tree/TerminalNodeImpl.cs +++ b/Antlr4.Runtime/Tree/TerminalNodeImpl.cs @@ -50,34 +50,49 @@ namespace Antlr4.Runtime.Tree return null; } - public virtual IToken GetSymbol() + public virtual IToken Symbol { - return symbol; - } - - public virtual IRuleNode GetParent() - { - return parent; - } - - public virtual IToken GetPayload() - { - return symbol; - } - - public virtual Interval GetSourceInterval() - { - if (symbol != null) + get { - int tokenIndex = symbol.GetTokenIndex(); - return new Interval(tokenIndex, tokenIndex); + return symbol; } - return Interval.Invalid; } - public virtual int GetChildCount() + public virtual IRuleNode Parent { - return 0; + get + { + return parent; + } + } + + public virtual IToken Payload + { + get + { + return symbol; + } + } + + public virtual Interval SourceInterval + { + get + { + if (symbol != null) + { + int tokenIndex = symbol.TokenIndex; + return new Interval(tokenIndex, tokenIndex); + } + return Interval.Invalid; + } + } + + public virtual int ChildCount + { + get + { + return 0; + } } public virtual T Accept(IParseTreeVisitor<_T1> visitor) where _T1:T @@ -89,7 +104,7 @@ namespace Antlr4.Runtime.Tree { if (symbol != null) { - return symbol.GetText(); + return symbol.Text; } return null; } @@ -103,11 +118,11 @@ namespace Antlr4.Runtime.Tree { if (symbol != null) { - if (symbol.GetType() == IToken.Eof) + if (symbol.Type == IToken.Eof) { return ""; } - return symbol.GetText(); + return symbol.Text; } else { diff --git a/Antlr4.Runtime/Tree/Trees.cs b/Antlr4.Runtime/Tree/Trees.cs index 2cf658eb4..73166a88a 100644 --- a/Antlr4.Runtime/Tree/Trees.cs +++ b/Antlr4.Runtime/Tree/Trees.cs @@ -114,7 +114,7 @@ namespace Antlr4.Runtime.Tree public static string ToStringTree(ITree t, IList ruleNames) { string s = Utils.EscapeWhitespace(GetNodeText(t, ruleNames), false); - if (t.GetChildCount() == 0) + if (t.ChildCount == 0) { return s; } @@ -123,7 +123,7 @@ namespace Antlr4.Runtime.Tree s = Utils.EscapeWhitespace(GetNodeText(t, ruleNames), false); buf.Append(s); buf.Append(' '); - for (int i = 0; i < t.GetChildCount(); i++) + for (int i = 0; i < t.ChildCount; i++) { if (i > 0) { @@ -148,7 +148,7 @@ namespace Antlr4.Runtime.Tree { if (t is IRuleNode) { - int ruleIndex = ((IRuleNode)t).GetRuleContext().GetRuleIndex(); + int ruleIndex = ((IRuleNode)t).RuleContext.GetRuleIndex(); string ruleName = ruleNames[ruleIndex]; return ruleName; } @@ -162,10 +162,10 @@ namespace Antlr4.Runtime.Tree { if (t is ITerminalNode) { - object symbol = ((ITerminalNode)t).GetSymbol(); + object symbol = ((ITerminalNode)t).Symbol; if (symbol is IToken) { - string s = ((IToken)symbol).GetText(); + string s = ((IToken)symbol).Text; return s; } } @@ -173,12 +173,12 @@ namespace Antlr4.Runtime.Tree } } // no recog for rule names - object payload = t.GetPayload(); + object payload = t.Payload; if (payload is IToken) { - return ((IToken)payload).GetText(); + return ((IToken)payload).Text; } - return t.GetPayload().ToString(); + return t.Payload.ToString(); } /// Return a list of all ancestors of this node. @@ -189,17 +189,17 @@ namespace Antlr4.Runtime.Tree [NotNull] public static IList GetAncestors(ITree t) { - if (t.GetParent() == null) + if (t.Parent == null) { return Sharpen.Collections.EmptyList(); } IList ancestors = new List(); - t = t.GetParent(); + t = t.Parent; while (t != null) { ancestors.Add(0, t); // insert at start - t = t.GetParent(); + t = t.Parent; } return ancestors; } diff --git a/Antlr4.Runtime/UnbufferedCharStream.cs b/Antlr4.Runtime/UnbufferedCharStream.cs index cbcd8fe1e..d690cf52c 100644 --- a/Antlr4.Runtime/UnbufferedCharStream.cs +++ b/Antlr4.Runtime/UnbufferedCharStream.cs @@ -342,9 +342,12 @@ namespace Antlr4.Runtime } } - public virtual int Index() + public virtual int Index { - return currentCharIndex; + get + { + return currentCharIndex; + } } /// @@ -396,14 +399,20 @@ namespace Antlr4.Runtime } } - public virtual int Size() + public virtual int Size { - throw new NotSupportedException("Unbuffered stream cannot know its size"); + get + { + throw new NotSupportedException("Unbuffered stream cannot know its size"); + } } - public virtual string GetSourceName() + public virtual string SourceName { - return name; + get + { + return name; + } } public override string GetText(Interval interval) diff --git a/Antlr4.Runtime/UnbufferedTokenStream.cs b/Antlr4.Runtime/UnbufferedTokenStream.cs index 1c4942ecb..3b0d385ab 100644 --- a/Antlr4.Runtime/UnbufferedTokenStream.cs +++ b/Antlr4.Runtime/UnbufferedTokenStream.cs @@ -167,7 +167,7 @@ namespace Antlr4.Runtime } if (index >= n) { - System.Diagnostics.Debug.Assert(n > 0 && tokens[n - 1].GetType() == IToken.Eof); + System.Diagnostics.Debug.Assert(n > 0 && tokens[n - 1].Type == IToken.Eof); return tokens[n - 1]; } return tokens[index]; @@ -175,12 +175,15 @@ namespace Antlr4.Runtime public virtual int La(int i) { - return Lt(i).GetType(); + return Lt(i).Type; } - public virtual ITokenSource GetTokenSource() + public virtual ITokenSource TokenSource { - return tokenSource; + get + { + return tokenSource; + } } [NotNull] @@ -192,7 +195,7 @@ namespace Antlr4.Runtime [NotNull] public virtual string GetText(RuleContext ctx) { - return GetText(ctx.GetSourceInterval()); + return GetText(ctx.SourceInterval); } [NotNull] @@ -200,7 +203,7 @@ namespace Antlr4.Runtime { if (start != null && stop != null) { - return GetText(Interval.Of(start.GetTokenIndex(), stop.GetTokenIndex())); + return GetText(Interval.Of(start.TokenIndex, stop.TokenIndex)); } throw new NotSupportedException("The specified start and stop symbols are not supported." ); @@ -269,7 +272,7 @@ namespace Antlr4.Runtime { for (int i = 0; i < n; i++) { - if (this.n > 0 && tokens[this.n - 1].GetType() == IToken.Eof) + if (this.n > 0 && tokens[this.n - 1].Type == IToken.Eof) { return i; } @@ -287,7 +290,7 @@ namespace Antlr4.Runtime } if (t is IWritableToken) { - ((IWritableToken)t).SetTokenIndex(GetBufferStartIndex() + n); + ((IWritableToken)t).TokenIndex = GetBufferStartIndex() + n; } tokens[n++] = t; } @@ -338,9 +341,12 @@ namespace Antlr4.Runtime } } - public virtual int Index() + public virtual int Index { - return currentTokenIndex; + get + { + return currentTokenIndex; + } } public virtual void Seek(int index) @@ -381,14 +387,20 @@ namespace Antlr4.Runtime } } - public virtual int Size() + public virtual int Size { - throw new NotSupportedException("Unbuffered stream cannot know its size"); + get + { + throw new NotSupportedException("Unbuffered stream cannot know its size"); + } } - public virtual string GetSourceName() + public virtual string SourceName { - return tokenSource.GetSourceName(); + get + { + return tokenSource.SourceName; + } } [NotNull] @@ -409,7 +421,7 @@ namespace Antlr4.Runtime for (int i = a; i <= b; i++) { IToken t = tokens[i]; - buf.Append(t.GetText()); + buf.Append(t.Text); } return buf.ToString(); } diff --git a/reference/antlr4 b/reference/antlr4 index c7dc3828f..88652241c 160000 --- a/reference/antlr4 +++ b/reference/antlr4 @@ -1 +1 @@ -Subproject commit c7dc3828fc49781d3015565db387f37c38137ee6 +Subproject commit 88652241cf2c248a66307e5866be98e3910b6519