build: config spotless plugin and reformat code

This commit is contained in:
Frank.R.Wu
2023-06-15 11:08:04 +08:00
parent b60e81e1a1
commit 8e06d0bc81
7 changed files with 51 additions and 52 deletions

View File

@@ -1,23 +1,23 @@
package org.bdware.sc.parser;
import org.antlr.v4.runtime.*;
import java.util.Stack;
public abstract class JavaScriptBaseLexer extends Lexer
{
public abstract class JavaScriptBaseLexer extends Lexer {
/**
* Stores values of nested modes. By default mode is strict or
* defined externally (useStrictDefault)
* Stores values of nested modes. By default mode is strict or defined externally
* (useStrictDefault)
*/
private Stack<Boolean> scopeStrictModes = new Stack<Boolean>();
private Token lastToken = null;
/**
* Default value of strict mode
* Can be defined externally by setUseStrictDefault
* Default value of strict mode Can be defined externally by setUseStrictDefault
*/
private boolean useStrictDefault = false;
/**
* Current value of strict mode
* Can be defined during parsing, see StringFunctions.js and StringGlobal.js samples
* Current value of strict mode Can be defined during parsing, see StringFunctions.js and
* StringGlobal.js samples
*/
private boolean useStrictCurrent = false;
@@ -39,10 +39,9 @@ public abstract class JavaScriptBaseLexer extends Lexer
}
/**
* Return the next token from the character stream and records this last
* token in case it resides on the default channel. This recorded token
* is used to determine when the lexer could possibly match a regex
* literal. Also changes scopeStrictModes stack if tokenize special
* Return the next token from the character stream and records this last token in case it
* resides on the default channel. This recorded token is used to determine when the lexer could
* possibly match a regex literal. Also changes scopeStrictModes stack if tokenize special
* string 'use strict';
*
* @return the next token from the character stream.
@@ -59,24 +58,20 @@ public abstract class JavaScriptBaseLexer extends Lexer
return next;
}
protected void ProcessOpenBrace()
{
useStrictCurrent = scopeStrictModes.size() > 0 && scopeStrictModes.peek() ? true : useStrictDefault;
protected void ProcessOpenBrace() {
useStrictCurrent =
scopeStrictModes.size() > 0 && scopeStrictModes.peek() ? true : useStrictDefault;
scopeStrictModes.push(useStrictCurrent);
}
protected void ProcessCloseBrace()
{
protected void ProcessCloseBrace() {
useStrictCurrent = scopeStrictModes.size() > 0 ? scopeStrictModes.pop() : useStrictDefault;
}
protected void ProcessStringLiteral()
{
if (lastToken == null || lastToken.getType() == JavaScriptLexer.OpenBrace)
{
protected void ProcessStringLiteral() {
if (lastToken == null || lastToken.getType() == JavaScriptLexer.OpenBrace) {
String text = getText();
if (text.equals("\"use strict\"") || text.equals("'use strict'"))
{
if (text.equals("\"use strict\"") || text.equals("'use strict'")) {
if (scopeStrictModes.size() > 0)
scopeStrictModes.pop();
useStrictCurrent = true;
@@ -89,13 +84,13 @@ public abstract class JavaScriptBaseLexer extends Lexer
* Returns {@code true} if the lexer can match a regex literal.
*/
protected boolean IsRegexPossible() {
if (this.lastToken == null) {
// No token has been produced yet: at the start of the input,
// no division is possible, so a regex literal _is_ possible.
return true;
}
switch (this.lastToken.getType()) {
case JavaScriptLexer.Identifier:
case JavaScriptLexer.NullLiteral:
@@ -116,4 +111,4 @@ public abstract class JavaScriptBaseLexer extends Lexer
return true;
}
}
}
}