mirror of
https://gitee.com/BDWare/genparser
synced 2025-04-27 14:32:15 +00:00
build: config spotless plugin and reformat code
This commit is contained in:
parent
b60e81e1a1
commit
8e06d0bc81
@ -3,6 +3,8 @@ plugins {
|
|||||||
id 'java-library'
|
id 'java-library'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply from: '../spotless.gradle'
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
java {
|
java {
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
package org.bdware.sc.parser;
|
package org.bdware.sc.parser;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.*;
|
import org.antlr.v4.runtime.*;
|
||||||
import java.util.Stack;
|
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
|
* Stores values of nested modes. By default mode is strict or defined externally
|
||||||
* defined externally (useStrictDefault)
|
* (useStrictDefault)
|
||||||
*/
|
*/
|
||||||
private Stack<Boolean> scopeStrictModes = new Stack<Boolean>();
|
private Stack<Boolean> scopeStrictModes = new Stack<Boolean>();
|
||||||
|
|
||||||
private Token lastToken = null;
|
private Token lastToken = null;
|
||||||
/**
|
/**
|
||||||
* Default value of strict mode
|
* Default value of strict mode Can be defined externally by setUseStrictDefault
|
||||||
* Can be defined externally by setUseStrictDefault
|
|
||||||
*/
|
*/
|
||||||
private boolean useStrictDefault = false;
|
private boolean useStrictDefault = false;
|
||||||
/**
|
/**
|
||||||
* Current value of strict mode
|
* Current value of strict mode Can be defined during parsing, see StringFunctions.js and
|
||||||
* Can be defined during parsing, see StringFunctions.js and StringGlobal.js samples
|
* StringGlobal.js samples
|
||||||
*/
|
*/
|
||||||
private boolean useStrictCurrent = false;
|
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
|
* Return the next token from the character stream and records this last token in case it
|
||||||
* token in case it resides on the default channel. This recorded token
|
* resides on the default channel. This recorded token is used to determine when the lexer could
|
||||||
* is used to determine when the lexer could possibly match a regex
|
* possibly match a regex literal. Also changes scopeStrictModes stack if tokenize special
|
||||||
* literal. Also changes scopeStrictModes stack if tokenize special
|
|
||||||
* string 'use strict';
|
* string 'use strict';
|
||||||
*
|
*
|
||||||
* @return the next token from the character stream.
|
* @return the next token from the character stream.
|
||||||
@ -59,24 +58,20 @@ public abstract class JavaScriptBaseLexer extends Lexer
|
|||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ProcessOpenBrace()
|
protected void ProcessOpenBrace() {
|
||||||
{
|
useStrictCurrent =
|
||||||
useStrictCurrent = scopeStrictModes.size() > 0 && scopeStrictModes.peek() ? true : useStrictDefault;
|
scopeStrictModes.size() > 0 && scopeStrictModes.peek() ? true : useStrictDefault;
|
||||||
scopeStrictModes.push(useStrictCurrent);
|
scopeStrictModes.push(useStrictCurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ProcessCloseBrace()
|
protected void ProcessCloseBrace() {
|
||||||
{
|
|
||||||
useStrictCurrent = scopeStrictModes.size() > 0 ? scopeStrictModes.pop() : useStrictDefault;
|
useStrictCurrent = scopeStrictModes.size() > 0 ? scopeStrictModes.pop() : useStrictDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ProcessStringLiteral()
|
protected void ProcessStringLiteral() {
|
||||||
{
|
if (lastToken == null || lastToken.getType() == JavaScriptLexer.OpenBrace) {
|
||||||
if (lastToken == null || lastToken.getType() == JavaScriptLexer.OpenBrace)
|
|
||||||
{
|
|
||||||
String text = getText();
|
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)
|
if (scopeStrictModes.size() > 0)
|
||||||
scopeStrictModes.pop();
|
scopeStrictModes.pop();
|
||||||
useStrictCurrent = true;
|
useStrictCurrent = true;
|
||||||
|
@ -3,8 +3,8 @@ package org.bdware.sc.parser;
|
|||||||
import org.antlr.v4.runtime.*;
|
import org.antlr.v4.runtime.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All parser methods that used in grammar (p, prev, notLineTerminator, etc.)
|
* All parser methods that used in grammar (p, prev, notLineTerminator, etc.) should start with
|
||||||
* should start with lower case char similar to parser rules.
|
* lower case char similar to parser rules.
|
||||||
*/
|
*/
|
||||||
public abstract class JavaScriptBaseParser extends Parser {
|
public abstract class JavaScriptBaseParser extends Parser {
|
||||||
public JavaScriptBaseParser(TokenStream input) {
|
public JavaScriptBaseParser(TokenStream input) {
|
||||||
@ -53,12 +53,12 @@ public abstract class JavaScriptBaseParser extends Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns {@code true} iff on the current index of the parser's token stream a
|
* Returns {@code true} iff on the current index of the parser's token stream a token of the
|
||||||
* token of the given {@code type} exists on the {@code HIDDEN} channel.
|
* given {@code type} exists on the {@code HIDDEN} channel.
|
||||||
*
|
*
|
||||||
* @param type the type of the token on the {@code HIDDEN} channel to check.
|
* @param type the type of the token on the {@code HIDDEN} channel to check.
|
||||||
* @return {@code true} iff on the current index of the parser's token stream a
|
* @return {@code true} iff on the current index of the parser's token stream a token of the
|
||||||
* token of the given {@code type} exists on the {@code HIDDEN} channel.
|
* given {@code type} exists on the {@code HIDDEN} channel.
|
||||||
*/
|
*/
|
||||||
private boolean here(final int type) {
|
private boolean here(final int type) {
|
||||||
|
|
||||||
@ -72,14 +72,13 @@ public abstract class JavaScriptBaseParser extends Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns {@code true} iff on the current index of the parser's token stream a
|
* Returns {@code true} iff on the current index of the parser's token stream a token exists on
|
||||||
* token exists on the {@code HIDDEN} channel which either is a line terminator,
|
* the {@code HIDDEN} channel which either is a line terminator, or is a multi line comment that
|
||||||
* or is a multi line comment that contains a line terminator.
|
* contains a line terminator.
|
||||||
*
|
*
|
||||||
* @return {@code true} iff on the current index of the parser's token stream a
|
* @return {@code true} iff on the current index of the parser's token stream a token exists on
|
||||||
* token exists on the {@code HIDDEN} channel which either is a line
|
* the {@code HIDDEN} channel which either is a line terminator, or is a multi line
|
||||||
* terminator, or is a multi line comment that contains a line
|
* comment that contains a line terminator.
|
||||||
* terminator.
|
|
||||||
*/
|
*/
|
||||||
protected boolean lineTerminatorAhead() {
|
protected boolean lineTerminatorAhead() {
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ public class AntlrGenLexerTool {
|
|||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
processLexer();
|
processLexer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void processLexer() {
|
private static void processLexer() {
|
||||||
String g5 = "JavaScriptLexer.g4";
|
String g5 = "JavaScriptLexer.g4";
|
||||||
String pkg = "org.bdware.sc.parser";
|
String pkg = "org.bdware.sc.parser";
|
||||||
@ -16,8 +17,8 @@ public class AntlrGenLexerTool {
|
|||||||
out.delete();
|
out.delete();
|
||||||
try {
|
try {
|
||||||
Files.copy(from.toPath(), out.toPath());
|
Files.copy(from.toPath(), out.toPath());
|
||||||
Tool.main(new String[]{g5, "-package", pkg, "-o", "./common/src/main/gen/" +
|
Tool.main(new String[] {g5, "-package", pkg, "-o",
|
||||||
pkg.replaceAll("\\.", "/"), "-visitor"});
|
"./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"});
|
||||||
new File(g5).delete();
|
new File(g5).delete();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -28,6 +28,7 @@ public class AntlrGenParserTool {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Tool.main(new String[]{g4, "-package", pkg, "-o", "./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"});
|
Tool.main(new String[] {g4, "-package", pkg, "-o",
|
||||||
|
"./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import org.antlr.v4.gui.TestRig;
|
import org.antlr.v4.gui.TestRig;
|
||||||
|
|
||||||
public class AntlrTest {
|
public class AntlrTest {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
TestRig.main(new String[] {});
|
TestRig.main(new String[] {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,10 @@ public class AntlrTool {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
// Tool.main(new String[] {});
|
// Tool.main(new String[] {});
|
||||||
Tool.main(new String[]{g4, "-package", pkg, "-o", "./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"});
|
Tool.main(new String[] {g4, "-package", pkg, "-o",
|
||||||
// Tool.main(new String[] { g5, "-package", pkg, "-o", "./gen/" +
|
"./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"});
|
||||||
// pkg.replaceAll("\\.", "/"), "-visitor" });
|
// Tool.main(new String[] { g5, "-package", pkg, "-o", "./gen/" +
|
||||||
|
// pkg.replaceAll("\\.", "/"), "-visitor" });
|
||||||
|
|
||||||
System.out.println("DeleteFiles!");
|
System.out.println("DeleteFiles!");
|
||||||
out.delete();
|
out.delete();
|
||||||
@ -48,8 +49,8 @@ public class AntlrTool {
|
|||||||
out.delete();
|
out.delete();
|
||||||
try {
|
try {
|
||||||
Files.copy(from.toPath(), out.toPath());
|
Files.copy(from.toPath(), out.toPath());
|
||||||
Tool.main(new String[]{g5, "-package", pkg, "-o", "./common/src/main/gen/" +
|
Tool.main(new String[] {g5, "-package", pkg, "-o",
|
||||||
pkg.replaceAll("\\.", "/"), "-visitor"});
|
"./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"});
|
||||||
new File(g5).delete();
|
new File(g5).delete();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user