java-parser
Advanced tools
Comparing version 2.1.0 to 2.2.0
{ | ||
"name": "java-parser", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Java Parser in JavaScript", | ||
@@ -18,3 +18,3 @@ "main": "src/index.js", | ||
}, | ||
"gitHead": "acdd5e7f28d08c4fb0351cfaf43d4ff9524b90ba" | ||
"gitHead": "00a8585d20c56d933ce4c89dcb532d9e98d1a4cf" | ||
} |
@@ -241,3 +241,8 @@ "use strict"; | ||
if (isPrettierIgnoreComment(nodeLeadingComments[i])) { | ||
mostEnclosiveCstNodeByStartOffset[startOffset].ignore = true; | ||
const node = mostEnclosiveCstNodeByStartOffset[startOffset]; | ||
const ignoreNode = | ||
node.name === "blockStatements" | ||
? node.children.blockStatement[0] | ||
: node; | ||
ignoreNode.ignore = true; | ||
break; | ||
@@ -244,0 +249,0 @@ } |
@@ -12,3 +12,3 @@ "use strict"; | ||
function parse(inputText, entryPoint = "compilationUnit") { | ||
function lexAndParse(inputText, entryPoint = "compilationUnit") { | ||
// Lex | ||
@@ -29,3 +29,4 @@ const lexResult = JavaLexer.tokenize(inputText); | ||
parser.input = lexResult.tokens; | ||
const tokens = lexResult.tokens; | ||
parser.input = tokens; | ||
parser.mostEnclosiveCstNodeByStartOffset = {}; | ||
@@ -56,3 +57,3 @@ parser.mostEnclosiveCstNodeByEndOffset = {}; | ||
attachComments( | ||
lexResult.tokens, | ||
tokens, | ||
lexResult.groups.comments, | ||
@@ -63,6 +64,11 @@ parser.mostEnclosiveCstNodeByStartOffset, | ||
return cst; | ||
return { cst, tokens }; | ||
} | ||
function parse(inputText, entryPoint = "compilationUnit") { | ||
return lexAndParse(inputText, entryPoint).cst; | ||
} | ||
module.exports = { | ||
lexAndParse, | ||
parse, | ||
@@ -69,0 +75,0 @@ BaseJavaCstVisitor, |
@@ -210,18 +210,4 @@ "use strict"; | ||
// https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-SwitchLabel | ||
$.RULE("switchLabel", () => { | ||
$.SUBRULE($.caseOrDefaultLabel); | ||
$.MANY({ | ||
GATE: () => | ||
tokenMatcher($.LA(1).tokenType, t.Colon) && | ||
(tokenMatcher($.LA(2).tokenType, t.Case) || | ||
tokenMatcher($.LA(2).tokenType, t.Default)), | ||
DEF: () => { | ||
$.CONSUME(t.Colon); | ||
$.SUBRULE2($.caseOrDefaultLabel); | ||
} | ||
}); | ||
}); | ||
// https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-SwitchLabel | ||
$.RULE("caseOrDefaultLabel", () => { | ||
$.OR([ | ||
@@ -231,35 +217,42 @@ { | ||
$.CONSUME(t.Case); | ||
$.SUBRULE($.caseLabelElement); | ||
$.MANY(() => { | ||
$.CONSUME(t.Comma); | ||
$.SUBRULE2($.caseLabelElement); | ||
}); | ||
$.OR2([ | ||
{ | ||
ALT: () => { | ||
$.CONSUME(t.Null); | ||
$.OPTION2(() => { | ||
$.CONSUME3(t.Comma); | ||
$.CONSUME(t.Default); | ||
}); | ||
} | ||
}, | ||
{ | ||
GATE: () => this.BACKTRACK_LOOKAHEAD($.pattern), | ||
ALT: () => { | ||
$.SUBRULE($.pattern); | ||
$.MANY(() => { | ||
$.CONSUME(t.Comma); | ||
$.SUBRULE2($.pattern); | ||
}); | ||
$.OPTION(() => { | ||
$.SUBRULE($.guard); | ||
}); | ||
} | ||
}, | ||
{ | ||
GATE: () => !tokenMatcher($.LA(1).tokenType, t.Null), | ||
ALT: () => { | ||
$.SUBRULE($.caseConstant); | ||
$.MANY2(() => { | ||
$.CONSUME2(t.Comma); | ||
$.SUBRULE2($.caseConstant); | ||
}); | ||
} | ||
} | ||
]); | ||
} | ||
}, | ||
{ | ||
ALT: () => $.CONSUME(t.Default) | ||
} | ||
{ ALT: () => $.CONSUME2(t.Default) } | ||
]); | ||
}); | ||
$.RULE("caseLabelElement", () => { | ||
$.OR([ | ||
{ ALT: () => $.CONSUME(t.Null) }, | ||
{ ALT: () => $.CONSUME(t.Default) }, | ||
{ | ||
GATE: () => this.BACKTRACK_LOOKAHEAD($.pattern), | ||
ALT: () => { | ||
$.SUBRULE($.pattern); | ||
$.OPTION(() => { | ||
$.SUBRULE($.guard); | ||
}); | ||
} | ||
}, | ||
{ | ||
GATE: () => tokenMatcher($.LA(1).tokenType, t.Null) === false, | ||
ALT: () => $.SUBRULE($.caseConstant) | ||
} | ||
]); | ||
}); | ||
// https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-SwitchRule | ||
@@ -521,10 +514,8 @@ $.RULE("switchRule", () => { | ||
// https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-Resource | ||
// https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-Resource | ||
$.RULE("resource", () => { | ||
$.OR([ | ||
{ | ||
GATE: $.BACKTRACK($.resourceInit), | ||
// Spec Deviation: extracted this alternative to "resourceInit" | ||
// to enable backtracking. | ||
ALT: () => $.SUBRULE($.resourceInit) | ||
GATE: () => $.BACKTRACK_LOOKAHEAD($.isLocalVariableDeclaration), | ||
ALT: () => $.SUBRULE($.localVariableDeclaration) | ||
}, | ||
@@ -535,13 +526,2 @@ { ALT: () => $.SUBRULE($.variableAccess) } | ||
// Spec Deviation: extracted from "resource" | ||
$.RULE("resourceInit", () => { | ||
$.MANY(() => { | ||
$.SUBRULE($.variableModifier); | ||
}); | ||
$.SUBRULE($.localVariableType); | ||
$.CONSUME(t.Identifier); | ||
$.CONSUME(t.Equals); | ||
$.SUBRULE($.expression); | ||
}); | ||
// https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-YieldStatement | ||
@@ -548,0 +528,0 @@ $.RULE("yieldStatement", () => { |
@@ -213,8 +213,15 @@ "use strict"; | ||
// https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-VariableDeclaratorId | ||
// https://docs.oracle.com/javase/specs/jls/se21/html/jls-8.html#jls-VariableDeclaratorId | ||
$.RULE("variableDeclaratorId", () => { | ||
$.CONSUME(t.Identifier); | ||
$.OPTION(() => { | ||
$.SUBRULE($.dims); | ||
}); | ||
$.OR([ | ||
{ | ||
ALT: () => { | ||
$.CONSUME(t.Identifier); | ||
$.OPTION(() => { | ||
$.SUBRULE($.dims); | ||
}); | ||
} | ||
}, | ||
{ ALT: () => $.CONSUME(t.Underscore) } | ||
]); | ||
}); | ||
@@ -221,0 +228,0 @@ |
@@ -24,3 +24,4 @@ "use strict"; | ||
{ ALT: () => $.SUBRULE($.lambdaParametersWithBraces) }, | ||
{ ALT: () => $.CONSUME(t.Identifier) } | ||
{ ALT: () => $.CONSUME(t.Identifier) }, | ||
{ ALT: () => $.CONSUME(t.Underscore) } | ||
]); | ||
@@ -588,3 +589,3 @@ }); | ||
$.OPTION(() => { | ||
$.SUBRULE($.patternList); | ||
$.SUBRULE($.componentPatternList); | ||
}); | ||
@@ -595,10 +596,21 @@ $.CONSUME(t.RBrace); | ||
// https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-PatternList | ||
$.RULE("patternList", () => { | ||
$.SUBRULE($.pattern); | ||
$.RULE("componentPatternList", () => { | ||
$.SUBRULE($.componentPattern); | ||
$.MANY(() => { | ||
$.CONSUME(t.Comma); | ||
$.SUBRULE2($.pattern); | ||
$.SUBRULE2($.componentPattern); | ||
}); | ||
}); | ||
$.RULE("componentPattern", () => { | ||
$.OR([ | ||
{ ALT: () => $.SUBRULE($.pattern) }, | ||
{ ALT: () => $.SUBRULE($.unnamedPattern) } | ||
]); | ||
}); | ||
$.RULE("unnamedPattern", () => { | ||
$.CONSUME(t.Underscore); | ||
}); | ||
// https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-Guard | ||
@@ -649,3 +661,4 @@ $.RULE("guard", () => { | ||
if ( | ||
tokenMatcher(firstTokenType, t.Identifier) && | ||
(tokenMatcher(firstTokenType, t.Identifier) || | ||
tokenMatcher(firstTokenType, t.Underscore)) && | ||
tokenMatcher(secondTokenType, t.Arrow) | ||
@@ -652,0 +665,0 @@ ) { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
283278
8268