Skip to content

Commit 53806a5

Browse files
committed
0.14.1 - Updated dependencies, new parsing strategy from jtext-tokenizer, fixed type parser to better handle C# nullable '?' types
1 parent 07bd715 commit 53806a5

12 files changed

+34
-17
lines changed

CHANGELOG.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/
44

55

66
--------
7-
###[0.14.0](N/A) - 2016-10-30
7+
###[0.14.1](N/A) - 2016-12-03
88
#### Changed
9+
* Updated dependencies to latest versions: jtext-parser@0.11.0, jtext-tokenizer@0.2.0, jparser-primitive@0.2.0
10+
* This includes a new parsing strategy which tries to parse non-compound tokens from start to finish using one parser at a time without passing the characters to compound parser, this improves performance and simplifies some of the compound parsers, but makes some compound parsers more difficult, such as ending conditions that try to keep track of characters between the start and end of the compound parser segment
11+
* GenericTypeTokenizer and IdentifierTokenizer changes to properly parse nullable generic parameters
12+
13+
14+
--------
15+
###[0.14.0](https://github.com/TeamworkGuy2/JParseCode/commit/07bd715ecd29a42d781b663cd3a20c2436e69bff) - 2016-10-30
916
__Reduced library complexity/scope by moving twg2.parser.text conditions/tokenizers to separate [jtext-tokenizer](https://github.com/TeamworkGuy2/JTextTokenizer) library__
17+
#### Changed
1018
* Moved twg2.parser.text package to jtext-tokenizer library
1119
* Moved twg2.parser.Inclusion to jtext-parser library
1220
* Renamed classes *Fragment -> *Token:
@@ -26,12 +34,12 @@ __Reduced library complexity/scope by moving twg2.parser.text conditions/tokeniz
2634

2735
--------
2836
###[0.13.0](https://github.com/TeamworkGuy2/JParseCode/commit/76734b17d16c67a89df7245a2cea2a1133c3b6b0) - 2016-10-26
37+
__Parameter modifier parsing support__ (i.e. 'final' in Java or 'params' in C#):
2938
#### Added
3039
* Added ParameterSig and ParameterSigResolved 'parameterModifiers' field
3140
* Added KeywordUtil parameterModifiers() and isParameterModifier()
3241

3342
#### Changed
34-
__Parameter modifier parsing support__ (i.e. 'final' in Java or 'params' in C#):
3543
* MethodParametersParser.extractParamsFromSignature() to support parameter modifiers
3644
* Renamed CodeTokenizerBuilder addConstParser() -> addParser()
3745
* Added FieldDef.initializerToJson() 'preClosingComma' parameter

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
JParseCode
22
==============
3-
version: 0.14.0
3+
version: 0.14.1
44

55
In progress C#/Java/TypeScript parser tools built atop [JTextParser] (https://github.com/TeamworkGuy2/JTextParser), [Jackson] (https://github.com/FasterXML/jackson-core/) (core, databind, annotations) and half a dozen other utility libraries.
66

bin/jparse_code-with-tests.jar

441 Bytes
Binary file not shown.

bin/jparse_code.jar

179 Bytes
Binary file not shown.

package-lib.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version" : "0.14.0",
2+
"version" : "0.14.1",
33
"name" : "jparse-code",
44
"description" : "An in-progress suite of parsing/transpilation tools for C#, Java, and TypeScript code. Generates simple JSON ASTs.",
55
"homepage" : "https://github.com/TeamworkGuy2/JParseCode",

src/twg2/parser/codeParser/analytics/TokenizeStepLogger.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void toJson(String srcName, boolean includeSurroundingBrackets, Appendabl
118118
if(includeSurroundingBrackets) { dst.append("{\n"); }
119119
if(srcName != null) {
120120
dst.append("\t\"file\": \"");
121-
StringEscapeJson.toJsonString(srcName, 0, srcName.length(), dst);
121+
StringEscapeJson.toJsonString(srcName, dst);
122122
dst.append("\"");
123123
}
124124

src/twg2/parser/codeParser/csharp/CsFileTokenizer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static CodeTokenizerBuilder<CodeLanguageOptions.CSharp> createFileParser(
4444

4545
public static CharParserFactory createAnnotationTokenizer() {
4646
CharParserFactory annotationParser = new StringBoundedParserBuilder("C# annotation")
47-
.addStartEndNotPrecededByMarkers("block [ ]", '[', '[', ']', 1, Inclusion.INCLUDE)
47+
.addStartEndNotPrecededByMarkers("block [ ]", '[', '[', ']', Inclusion.INCLUDE)
4848
.isCompound(true)
4949
.build();
5050
return annotationParser;

src/twg2/parser/tokenizers/CodeTokenizerBuilder.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ public static <D extends TextToken<S, T>, T, S> SimpleTree<D> tokenizeDocument(S
180180

181181
while(input.hasNext()) {
182182
char ch = input.nextChar();
183-
parser.acceptNext(ch, input);
183+
//System.out.println(input.getPositionDisplayText());
184+
parser.parse(ch, input);
184185
}
185186

186187
return tree;

src/twg2/parser/tokenizers/GenericTypeTokenizer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public static CharParserMatchable _createGenericTypeTokenizer(int recursionDepth
3030
// the condition that parses identifiers nested inside the generic type definition
3131
val nestedGenericTypeIdentifierCond = recursionDepth > 1 ? _createGenericTypeTokenizer(recursionDepth - 1, singleIdentifierParserConstructor) : singleIdentifierParserConstructor.get();
3232

33-
val requiredParser = Arrays.asList(singleIdentifierParserConstructor.get());
33+
val typeIdentifierParser = Arrays.asList(singleIdentifierParserConstructor.get());
3434
// TODO only matches generic types in the format '<a, b>', allow whitespace between '<'/'>' and after ','
35-
val optionalParser = Arrays.asList(CharConditionPipe.createPipeOptionalSuffixesAny("generic type and array dimensions", Arrays.asList(
35+
val genericParamsParser = Arrays.asList(CharConditionPipe.createPipeOptionalSuffixesAny("generic type and array dimensions", Arrays.asList(
3636
CharConditionPipe.createPipeAllRequired("generic type signature", Arrays.asList(
3737
new CharConditions.Literal("<", CharArrayList.of('<'), Inclusion.INCLUDE),
3838
CharConditionPipe.createPipeRepeatableSeparator("generic type params",
@@ -45,7 +45,7 @@ public static CharParserMatchable _createGenericTypeTokenizer(int recursionDepth
4545
)
4646
));
4747

48-
return CharConditionPipe.createPipeOptionalSuffix("type parser", requiredParser, optionalParser);
48+
return CharConditionPipe.createPipeOptionalSuffix("type parser", typeIdentifierParser, genericParamsParser);
4949
}
5050

5151
}

src/twg2/parser/tokenizers/IdentifierTokenizer.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public class IdentifierTokenizer {
2323

2424
public static CharParserFactory createIdentifierWithGenericTypeTokenizer() {
2525
val typeStatementCond = GenericTypeTokenizer.createGenericTypeTokenizer(genericTypeDepth, IdentifierTokenizer::createCompoundIdentifierTokenizer);
26-
CharParserFactory identifierWithGenericTypeParser = new CharParserMatchableFactory<>("compound identifier with optional generic type", false, Tuples.of(typeStatementCond.getFirstCharMatcher(), typeStatementCond));
27-
return identifierWithGenericTypeParser;
26+
return new CharParserMatchableFactory<>("compound identifier with optional generic type", false, Tuples.of(typeStatementCond.getFirstCharMatcher(), typeStatementCond));
2827
}
2928

3029

@@ -60,7 +59,10 @@ public static CharConditions.BaseCharParserMatchable newIdentifierTokenizer() {
6059
public static CharParserMatchable createCompoundIdentifierTokenizer() {
6160
val identifierParser = Arrays.asList(newIdentifierTokenizer());
6261
val separatorParser = Arrays.asList(new CharConditions.Literal("identifier namespace separator", CharArrayList.of('.'), Inclusion.INCLUDE));
63-
return CharConditionPipe.createPipeRepeatableSeparator("compound identifier", identifierParser, separatorParser);
62+
return CharConditionPipe.createPipeOptionalSuffix("compound identifier (nullable)",
63+
Arrays.asList(CharConditionPipe.createPipeRepeatableSeparator("compound identifier", identifierParser, separatorParser)),
64+
Arrays.asList(new CharConditions.Literal("nullable '?' type", CharArrayList.of('?'), Inclusion.INCLUDE))
65+
);
6466
}
6567

6668
}

test/twg2/parser/codeParser/test/CsClassParseTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.nio.file.Paths;
55
import java.util.Arrays;
6+
import java.util.List;
67

78
import lombok.val;
89

@@ -31,7 +32,7 @@
3132
* @since 2016-1-1
3233
*/
3334
public class CsClassParseTest {
34-
private static CodeFileAndAst<CsBlock> simpleCs = CodeFileAndAst.<CsBlock>parse(CodeLanguageOptions.C_SHARP, "SimpleCs.cs", "ParserExamples.Samples.SimpleCs", true, Arrays.asList(
35+
private static List<String> srcLines = Arrays.asList(
3536
"namespace ParserExamples.Samples {",
3637
"",
3738
" /// <summary>",
@@ -94,8 +95,10 @@ public class CsClassParseTest {
9495
" }",
9596
"",
9697
"}"
97-
));
98+
);
9899

100+
@Parameter
101+
private CodeFileAndAst<CsBlock> simpleCs = CodeFileAndAst.<CsBlock>parse(CodeLanguageOptions.C_SHARP, "SimpleCs.cs", "ParserExamples.Samples.SimpleCs", true, srcLines);
99102

100103
@Parameter
101104
private CodeFileSrc<CodeLanguage> file = ParseCodeFile.parseFiles(Arrays.asList(Paths.get("rsc/csharp/ParserExamples/Models/TrackInfo.cs")), FileReadUtil.threadLocalInst(), null).get(0);

test/twg2/parser/codeParser/test/JavaClassParseTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.nio.file.Paths;
55
import java.util.Arrays;
6+
import java.util.List;
67

78
import lombok.val;
89

@@ -31,7 +32,7 @@
3132
* @since 2016-1-15
3233
*/
3334
public class JavaClassParseTest {
34-
private static CodeFileAndAst<JavaBlock> simpleJava = CodeFileAndAst.<JavaBlock>parse(CodeLanguageOptions.JAVA, "SimpleJava.java", "ParserExamples.Samples.SimpleJava", true, Arrays.asList(
35+
private static List<String> srcLines = Arrays.asList(
3536
"package ParserExamples.Samples;",
3637
"",
3738
"/** A simple class to test parsing.",
@@ -80,8 +81,10 @@ public class JavaClassParseTest {
8081
" }",
8182
"",
8283
"}"
83-
));
84+
);
8485

86+
@Parameter
87+
private CodeFileAndAst<JavaBlock> simpleJava = CodeFileAndAst.<JavaBlock>parse(CodeLanguageOptions.JAVA, "SimpleJava.java", "ParserExamples.Samples.SimpleJava", true, srcLines);
8588

8689
@Parameter
8790
private CodeFileSrc<CodeLanguage> file = ParseCodeFile.parseFiles(Arrays.asList(Paths.get("rsc/java/ParserExamples/Models/TrackInfo.java")), FileReadUtil.threadLocalInst(), null).get(0);

0 commit comments

Comments
 (0)