Block comments, and fix the line comments :)
This commit is contained in:
		
							parent
							
								
									ceb0d5aaba
								
							
						
					
					
						commit
						15b877a368
					
				
					 2 changed files with 32 additions and 15 deletions
				
			
		|  | @ -50,12 +50,7 @@ public class Lexer { | |||
|             } else if (c == '*') { | ||||
|                 this.handleSimple(TokenType.MULT, line, column); | ||||
|             } else if (c == '/') { | ||||
|                 if (this.content.peekNext().exists(n -> n == '/')) { | ||||
|                     this.content.next(); | ||||
|                     this.handleLineComment(); | ||||
|                 } else { | ||||
|                     this.handleSimple(TokenType.DIV, line, column); | ||||
|                 } | ||||
|                 this.handleForwardSlash(line, column); | ||||
|             } else if (c == '%') { | ||||
|                 this.handleSimple(TokenType.MOD, line, column); | ||||
|             } else if (c == '^') { | ||||
|  | @ -112,6 +107,20 @@ public class Lexer { | |||
|         this.appendToken(new Token(tokenType, line, column)); | ||||
|     } | ||||
| 
 | ||||
|     private void handleForwardSlash(final int line, final int column) { | ||||
|         this.content.next(); | ||||
|         if (this.content.peekNext().exists(n -> n == '/')) { | ||||
|             this.content.next(); | ||||
|             this.handleLineComment(); | ||||
|         } | ||||
|         if (this.content.peekNext().exists(n -> n == '*')) { | ||||
|             this.content.next(); | ||||
|             this.handleBlockComment(); | ||||
|         } else { | ||||
|             this.tokens.append(new Token(TokenType.DIV, line, column)); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private void handleLineComment() { | ||||
|         while (this.content.peekNext().exists(next -> next != '\n')) { | ||||
|             this.content.next(); | ||||
|  | @ -121,6 +130,23 @@ public class Lexer { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private void handleBlockComment() { | ||||
|         // ...*/ | ||||
|         while (this.content.peekNext().exists(next -> next != '*')) { | ||||
|             this.content.next(); | ||||
|         } | ||||
|         if (this.content.peekNext().exists(n -> n == '*')) { | ||||
|             this.content.next(); | ||||
|             if (this.content.peekNext().exists(n -> n == '/')) { | ||||
|                 this.content.next(); | ||||
|                 return; | ||||
|             } | ||||
|             handleBlockComment(); | ||||
|         } else { | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private void appendToken(@NotNull final Token token) { | ||||
|         this.tokens = this.tokens.append(token); | ||||
|     } | ||||
|  |  | |||
|  | @ -1,9 +0,0 @@ | |||
| let x = 1; | ||||
| if (x) { | ||||
| //    x = 99; | ||||
| } else { | ||||
|     x = 12; | ||||
| } | ||||
| // comment | ||||
| exit(x); | ||||
| // comment | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue