@@ -149,7 +149,7 @@ private diagram make_nfa(string pattern)
149149 break ; 
150150
151151 case  ')' : 
152-  if  ( opstack . Peek ( )  !=  '(' ) 
152+  if  ( opstack . Count == 0 || opstack . Peek ( )  !=  '(' ) 
153153 { 
154154 build_errors . Add ( $ "[regex] { i }  no opener!") ; 
155155 return  null ; 
@@ -896,6 +896,8 @@ public class Scanner
896896 bool  err  =  false ; 
897897 int  latest_pos ; 
898898 List < int >  err_pos ; 
899+  int  current_line ; 
900+  int  current_column ; 
899901
900902 public  Scanner ( int [ ] [ ]  transition_table ,  string [ ]  accept_table ) 
901903 { 
@@ -907,6 +909,8 @@ public void AllocateTarget(string literal)
907909 { 
908910 target  =  literal ; 
909911 pos  =  0 ; 
912+  current_line  =  0 ; 
913+  current_column  =  0 ; 
910914 err_pos  =  new  List < int > ( ) ; 
911915 err  =  false ; 
912916 } 
@@ -923,12 +927,15 @@ public bool Error()
923927
924928 public  int  Position  {  get  {  return  latest_pos ;  }  } 
925929
926-  public  Tuple < string ,  string >  Next ( ) 
930+  public  Tuple < string ,  string , int , int >  Next ( ) 
927931 { 
928932 var  builder  =  new  StringBuilder ( ) ; 
929933 var  node_pos  =  0 ; 
930934 latest_pos  =  pos ; 
931935
936+  int  cur_line  =  current_line ; 
937+  int  cur_column  =  current_column ; 
938+ 932939 for  ( ;  pos  <  target . Length ;  pos ++ ) 
933940 { 
934941 int  next_transition  =  transition_table [ node_pos ] [ target [ pos ] ] ; 
@@ -944,6 +951,9 @@ public Tuple<string, string> Next()
944951 latest_pos  =  pos ; 
945952 pos -- ; 
946953 node_pos  =  0 ; 
954+  current_column -- ; 
955+  cur_line  =  current_line ; 
956+  cur_column  =  current_column ; 
947957 continue ; 
948958 } 
949959 if  ( accept_table [ node_pos ]  ==  null ) 
@@ -952,20 +962,21 @@ public Tuple<string, string> Next()
952962 err_pos . Add ( pos ) ; 
953963 continue ; 
954964 } 
955-  return  new  Tuple < string ,  string > ( accept_table [ node_pos ] ,  builder . ToString ( ) ) ; 
965+  return  new  Tuple < string ,  string , int , int > ( accept_table [ node_pos ] ,  builder . ToString ( ) , cur_line + 1 , cur_column + 1 ) ; 
956966
957967 default : 
968+  if  ( target [ pos ]  ==  '\n ' )  {  current_line ++ ;  current_column  =  1 ;  }  else  current_column ++ ; 
958969 builder . Append ( target [ pos ] ) ; 
959970 break ; 
960971 } 
961972
962973 node_pos  =  next_transition ; 
963974 } 
964975
965-  return  new  Tuple < string ,  string > ( accept_table [ node_pos ] ,  builder . ToString ( ) ) ; 
976+  return  new  Tuple < string ,  string , int , int > ( accept_table [ node_pos ] ,  builder . ToString ( ) , cur_line + 1 , cur_column + 1 ) ; 
966977 } 
967978
968-  public  Tuple < string ,  string >  Lookahead ( ) 
979+  public  Tuple < string ,  string , int , int >  Lookahead ( ) 
969980 { 
970981 var  npos  =  pos ; 
971982 var  result  =  Next ( ) ; 
0 commit comments