@@ -32,7 +32,6 @@ public sealed partial class Tokenizer : TokenizerService {
3232 private bool _disableLineFeedLineSeparator ;
3333 private SourceUnit _sourceUnit ;
3434 private ErrorSink _errors ;
35- private Severity _indentationInconsistencySeverity ;
3635 private bool _endContinues ;
3736 private List < int > _newLineLocations ;
3837 private SourceLocation _initialLocation ;
@@ -127,17 +126,6 @@ public override ErrorSink ErrorSink {
127126 }
128127 }
129128
130- public Severity IndentationInconsistencySeverity {
131- get { return _indentationInconsistencySeverity ; }
132- set {
133- _indentationInconsistencySeverity = value ;
134-
135- if ( value != Severity . Ignore && _state . IndentFormat == null ) {
136- _state . IndentFormat = new StringBuilder [ MaxIndent ] ;
137- }
138- }
139- }
140-
141129 public bool IsEndOfFile {
142130 get {
143131 return Peek ( ) == EOF ;
@@ -1321,70 +1309,11 @@ public bool EndContinues {
13211309 }
13221310 }
13231311
1324- /// <summary>
1325- /// Returns whether the
1326- /// </summary>
1312+ // <summary>
1313+ // Returns whether the
1314+ // </summary>
13271315 private bool ReadNewline ( ) {
1328- // Check whether we're currently scanning for inconsistent use of identation characters. If
1329- // we are we'll switch to using a slower version of this method with the extra checks embedded.
1330- if ( IndentationInconsistencySeverity != Severity . Ignore )
1331- return ReadNewlineWithChecks ( ) ;
1332-
1333- int spaces = 0 ;
1334- while ( true ) {
1335- int ch = NextChar ( ) ;
1336-
1337- switch ( ch ) {
1338- case ' ' : spaces += 1 ; break ;
1339- case '\t ' : spaces += 8 - ( spaces % 8 ) ; break ;
1340- case '\f ' : spaces = 0 ; break ;
1341-
1342- case '#' :
1343- if ( _verbatim ) {
1344- BufferBack ( ) ;
1345- MarkTokenEnd ( ) ;
1346- return true ;
1347- } else {
1348- ch = ReadLine ( ) ;
1349- break ;
1350- }
1351- default :
1352- BufferBack ( ) ;
1353-
1354- if ( GroupingLevel > 0 ) {
1355- return false ;
1356- }
1357-
1358- MarkTokenEnd ( ) ;
1359-
1360- // if there's a blank line then we don't want to mess w/ the
1361- // indentation level - Python says that blank lines are ignored.
1362- // And if we're the last blank line in a file we don't want to
1363- // increase the new indentation level.
1364- if ( ch == EOF ) {
1365- if ( spaces < _state . Indent [ _state . IndentLevel ] ) {
1366- if ( _sourceUnit . Kind == SourceCodeKind . InteractiveCode ||
1367- _sourceUnit . Kind == SourceCodeKind . Statements ) {
1368- SetIndent ( spaces , null ) ;
1369- } else {
1370- DoDedent ( spaces , _state . Indent [ _state . IndentLevel ] ) ;
1371- }
1372- }
1373- } else if ( ch != '\n ' && ch != '\r ' ) {
1374- SetIndent ( spaces , null ) ;
1375- }
1376-
1377- return true ;
1378- }
1379- }
1380- }
1381-
1382- // This is another version of ReadNewline with nearly identical semantics. The difference is
1383- // that checks are made to see that indentation is used consistently. This logic is in a
1384- // duplicate method to avoid inflicting the overhead of the extra logic when we're not making
1385- // the checks.
1386- private bool ReadNewlineWithChecks ( ) {
1387- // Keep track of the indentation format for the current line
1316+ // Keep track of the indentation format for the current line - may want to optimize in the future
13881317 StringBuilder sb = new StringBuilder ( 80 ) ;
13891318
13901319 int spaces = 0 ;
@@ -1394,7 +1323,7 @@ private bool ReadNewlineWithChecks() {
13941323 switch ( ch ) {
13951324 case ' ' : spaces += 1 ; sb . Append ( ' ' ) ; break ;
13961325 case '\t ' : spaces += 8 - ( spaces % 8 ) ; sb . Append ( '\t ' ) ; break ;
1397- case '\f ' : spaces = 0 ; sb . Append ( ' \f ' ) ; break ;
1326+ case '\f ' : spaces = 0 ; break ;
13981327
13991328 case '#' :
14001329 if ( _verbatim ) {
@@ -1463,24 +1392,21 @@ private void CheckIndent(StringBuilder sb) {
14631392 // We've hit a difference in the way we're indenting, report it.
14641393 _errors . Add ( _sourceUnit , Resources . InconsistentWhitespace ,
14651394 new SourceSpan ( eoln_token_end , eoln_token_end ) , // TODO: we can report better span - starting at the beginning of the line
1466- ErrorCodes . TabError , _indentationInconsistencySeverity
1395+ ErrorCodes . TabError , Severity . Error
14671396 ) ;
1468-
1469- // We only report problems once per module, so switch back to the fast algorithm.
1470- _indentationInconsistencySeverity = Severity . Ignore ;
14711397 }
14721398 }
14731399 }
14741400 }
14751401
1402+
14761403 private void SetIndent ( int spaces , StringBuilder chars ) {
14771404 int current = _state . Indent [ _state . IndentLevel ] ;
14781405 if ( spaces == current ) {
14791406 return ;
14801407 } else if ( spaces > current ) {
14811408 _state . Indent [ ++ _state . IndentLevel ] = spaces ;
1482- if ( _state . IndentFormat != null )
1483- _state . IndentFormat [ _state . IndentLevel ] = chars ;
1409+ _state . IndentFormat [ _state . IndentLevel ] = chars ;
14841410 _state . PendingDedents = - 1 ;
14851411 return ;
14861412 } else {
@@ -1656,8 +1582,6 @@ private struct State : IEquatable<State> {
16561582 public int PendingDedents ;
16571583 public bool LastNewLine ; // true if the last token we emitted was a new line.
16581584 public IncompleteString IncompleteString ;
1659-
1660- // Indentation state used only when we're reporting on inconsistent identation format.
16611585 public StringBuilder [ ] IndentFormat ;
16621586
16631587 // grouping state
@@ -1671,15 +1595,15 @@ public State(State state) {
16711595 BraceLevel = state . BraceLevel ;
16721596 PendingDedents = state . PendingDedents ;
16731597 IndentLevel = state . IndentLevel ;
1674- IndentFormat = ( state . IndentFormat != null ) ? ( StringBuilder [ ] ) state . IndentFormat . Clone ( ) : null ;
1598+ IndentFormat = ( StringBuilder [ ] ) state . IndentFormat . Clone ( ) ;
16751599 IncompleteString = state . IncompleteString ;
16761600 }
16771601
16781602 public State ( object dummy ) {
16791603 Indent = new int [ MaxIndent ] ; // TODO
16801604 LastNewLine = false ;
16811605 BracketLevel = ParenLevel = BraceLevel = PendingDedents = IndentLevel = 0 ;
1682- IndentFormat = null ;
1606+ IndentFormat = new StringBuilder [ MaxIndent ] ;
16831607 IncompleteString = null ;
16841608 }
16851609
0 commit comments