The first version of the language server is pretty much ready to go, but I'm trying to apply
@heeheehee 's advices, and will try to split this as much as possible.
Here is the first step.
This patch is about introducing two new classes to Parser.java: the
Line, and the
Token.
Currently, everything is just Strings. The line we are currently at is represented by a simple string, and the token we are currently at is represented by a simple string.
This patch replaces these by
Line and
Token, respectively.
The purpose of the
Line is to save, and allow access to, the file as parsed. It holds reference to every other line, as well as the tokens that are inside of itself.
The purpose of the
Token is to hold information relative to it. Namely, the index at which it starts and ends. (Those are not included in this patch. They will be added later.)
These information are crucial to the language server, as it is what allows the language server to tell the client where to put the red squiggles marking errors, for instance.
This patch 3300 lines long.
Q. That's big.
A. That's not a question.
Q. Why is it so big?
(pompous assh--)
A. Did you mutter something? Anyway, yes, it's big. This is because, currently, Parser.java uses a lot of this:
Java:
"exampleStringLiteral".equals( this.currentToken() )
This is a null-safe way to call the `String.equals( String )` method.
However, since the `currentToken()` method now returns a
Token, they need to be reversed. (The method
cannot return null, so it's still null-safe)
Since these are peppered across Parser.java, and since .patch files add context lines above and below the changed line(s), it bloats the patch file.
Besides this, this patch only contains 3 major changes.
- Parser( File, InputStream, Map<File, Long> ) - Parser.parse() - Parser.importFile( String, Scope )
The closing of the InputStream now happens inside the contructor, rather than after the parsing. This means that there no longer is a need to surround Parser.parseScope( Scope, Type, VariableList, BasicScope, boolean, boolean ) with a try-finally block.
- Sections that handled strings character-by-character: Parser.parseBasicScript() - Parser.parseString() - Parser.parseEscapeSequence( StringBuilder, int ) - Parser.parseTypedConstant( BasicScope ) - Parser.parsePluralConstant( BasicScope, Type ) - Parser.parseDirective( String )
It was not possible to leave those out of this patch, given how they were interacting with fields that are no longer here.
Most notable changes:
- Handling of escape sequences was previously in Parser.parseString( BasicScope, Type ). This caused Parser.parseTypedConstant( BasicScope ) to call it to parse plural constants.
This is no longer the case. Parser.parseString( BasicScope ) and Parser.parsePluralConstant( BasicScope, Type ) are now two different methods.
- Handling of escape sequences is now in its own method, Parser.parseEscapeSequence( StringBuilder, int ), which is called by the two aforementioned methods when required.
- Methods in the "Tokenizer" section: Parser.currentToken() - Parser.nextToken() and the Line + Token classes.
Obviously, that had to go somewhere...