Skip to content

Commit 5ae0793

Browse files
committed
0.6.0 - Added numeric literal and access modifier parsing.
1 parent eea353c commit 5ae0793

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1430
-747
lines changed

.classpath

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/TestUtil"/>
88
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Lombok"/>
99
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/TemplateUtil"/>
10-
<classpathentry kind="output" path="bin"/>
1110
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/data-transfer/jar/data_transfer.jar"/>
1211
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jackson/jar/jackson-annotations-2.5.0.jar"/>
1312
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jackson/jar/jackson-core-2.5.0.jar"/>
1413
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jackson/jar/jackson-databind-2.5.4.jar"/>
1514
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jarray-util/jar/jarray_util.jar" sourcepath="/JArrayUtil"/>
1615
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jcollection-util/jar/jcollection_util.jar" sourcepath="/JCollectionUtil"/>
1716
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jdata-util/jar/jdata_util.jar" sourcepath="/JDataUtil"/>
18-
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jfile-io/jar/jfile_io.jar" sourcepath="/JFileIo"/>
1917
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jfunc/jar/jfunc.jar" sourcepath="/JFunc"/>
2018
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jinterfaces/jar/jinterfaces.jar" sourcepath="/JInterfaces"/>
2119
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jparser-data-type-like/jar/jparser_data_type_like.jar" sourcepath="/JParserDataTypeLike"/>
@@ -27,4 +25,6 @@
2725
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jtext-parser/jar/jtext_parser.jar" sourcepath="/JTextParser/src"/>
2826
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jtext-util/jar/jtext_util.jar" sourcepath="/JTextUtil"/>
2927
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jtree-walker/jar/jtree_walker.jar" sourcepath="/JTreeWalker"/>
28+
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jfile-io/jar/jfile_io.jar" sourcepath="/JFileIo"/>
29+
<classpathentry kind="output" path="bin"/>
3030
</classpath>

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ParserToolsTmp
22
==============
3-
version: 0.5.0
3+
version: 0.6.0
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

package-lib.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version" : "0.5.0",
2+
"version" : "0.6.0",
33
"name" : "jparser-tools",
44
"description" : "An in-progress suite of parsing tools for C#, Java, and TypeScript source code",
55
"homepage" : "https://github.com/TeamworkGuy2/JFileIo",

src/twg2/parser/baseAst/AstTypeChecker.java

+9
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22

33
import twg2.parser.codeParser.CodeFragmentType;
44
import twg2.parser.documentParser.DocumentFragmentText;
5+
import twg2.treeLike.simpleTree.SimpleTree;
56

67
/**
78
* @author TeamworkGuy2
89
* @since 2016-1-3
910
*/
1011
public interface AstTypeChecker<T_KEYWORD> {
1112

13+
/** Check if a code fragment is a block of code following a possible field definition.<br>
14+
* Best understood by example, a C# property like <code>{ get; set; }</code><br>
15+
* or <code>{ get { return _a; }; set { _a = value; }; }</code>
16+
* @param tokenNode the document code fragment
17+
* @return true if the token represents a field block, false if not
18+
*/
19+
public boolean isFieldBlock(SimpleTree<DocumentFragmentText<CodeFragmentType>> tokenNode);
20+
1221
public boolean isKeyword(DocumentFragmentText<CodeFragmentType> node, T_KEYWORD keyword1);
1322

1423
public boolean isKeyword(DocumentFragmentText<CodeFragmentType> node, T_KEYWORD keyword1, T_KEYWORD keyword2);

src/twg2/parser/baseAst/csharp/CsAstUtil.java

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package twg2.parser.baseAst.csharp;
22

3+
import lombok.val;
34
import twg2.parser.baseAst.AccessModifierEnum;
45
import twg2.parser.baseAst.AccessModifierParser;
56
import twg2.parser.baseAst.AstTypeChecker;
@@ -10,6 +11,7 @@
1011
import twg2.parser.codeParser.csharp.CsBlock;
1112
import twg2.parser.codeParser.csharp.CsKeyword;
1213
import twg2.parser.documentParser.DocumentFragmentText;
14+
import twg2.treeLike.simpleTree.SimpleTree;
1315
import dataUtils.EnumUtil;
1416

1517
/**
@@ -107,19 +109,46 @@ public final AccessModifierEnum tryFromLanguageSrc(String src) {
107109

108110
@Override
109111
public boolean isKeyword(DocumentFragmentText<CodeFragmentType> node, CsKeyword keyword1) {
110-
return node != null && (node.getFragmentType() == CodeFragmentType.KEYWORD && keyword1.getSrcName().equals(node.getText()));
112+
return node != null && (node.getFragmentType() == CodeFragmentType.KEYWORD && keyword1.toSrc().equals(node.getText()));
111113
}
112114

113115

114116
@Override
115117
public boolean isKeyword(DocumentFragmentText<CodeFragmentType> node, CsKeyword keyword1, CsKeyword keyword2) {
116-
return node != null && (node.getFragmentType() == CodeFragmentType.KEYWORD && (keyword1.getSrcName().equals(node.getText()) || keyword2.getSrcName().equals(node.getText())));
118+
return node != null && (node.getFragmentType() == CodeFragmentType.KEYWORD && (keyword1.toSrc().equals(node.getText()) || keyword2.toSrc().equals(node.getText())));
117119
}
118120

119121

120122
@Override
121123
public boolean isKeyword(DocumentFragmentText<CodeFragmentType> node, CsKeyword keyword1, CsKeyword keyword2, CsKeyword keyword3) {
122-
return node != null && (node.getFragmentType() == CodeFragmentType.KEYWORD && (keyword1.getSrcName().equals(node.getText()) || keyword2.getSrcName().equals(node.getText()) || keyword3.getSrcName().equals(node.getText())));
124+
return node != null && (node.getFragmentType() == CodeFragmentType.KEYWORD && (keyword1.toSrc().equals(node.getText()) || keyword2.toSrc().equals(node.getText()) || keyword3.toSrc().equals(node.getText())));
125+
}
126+
127+
128+
@Override
129+
public boolean isFieldBlock(SimpleTree<DocumentFragmentText<CodeFragmentType>> block) {
130+
if(block == null) { return true; }
131+
val childs = block.getChildren();
132+
// properties must have at-least one indexer
133+
if(childs.size() == 0) { return false; }
134+
135+
boolean prevWasGetOrSet = false;
136+
for(val child : childs) {
137+
val frag = child.getData();
138+
val fragType = frag.getFragmentType();
139+
if(fragType == CodeFragmentType.COMMENT) {
140+
continue;
141+
}
142+
val isGetOrSet = fragType == CodeFragmentType.IDENTIFIER && ("get".equals(frag.getText()) || "set".equals(frag.getText()));
143+
if(isGetOrSet || (prevWasGetOrSet && (fragType == CodeFragmentType.BLOCK || fragType == CodeFragmentType.SEPARATOR))) {
144+
// allow
145+
}
146+
else {
147+
return false;
148+
}
149+
prevWasGetOrSet = isGetOrSet;
150+
}
151+
return true;
123152
}
124153

125154
}

src/twg2/parser/baseAst/java/JavaAstUtil.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import twg2.parser.codeParser.java.JavaBlock;
1111
import twg2.parser.codeParser.java.JavaKeyword;
1212
import twg2.parser.documentParser.DocumentFragmentText;
13+
import twg2.treeLike.simpleTree.SimpleTree;
1314
import dataUtils.EnumUtil;
1415

1516
/**
@@ -110,19 +111,27 @@ public final AccessModifierEnum tryFromLanguageSrc(String src) {
110111

111112
@Override
112113
public boolean isKeyword(DocumentFragmentText<CodeFragmentType> node, JavaKeyword keyword1) {
113-
return node != null && (node.getFragmentType() == CodeFragmentType.KEYWORD && keyword1.getSrcName().equals(node.getText()));
114+
return node != null && (node.getFragmentType() == CodeFragmentType.KEYWORD && keyword1.toSrc().equals(node.getText()));
114115
}
115116

116117

117118
@Override
118119
public boolean isKeyword(DocumentFragmentText<CodeFragmentType> node, JavaKeyword keyword1, JavaKeyword keyword2) {
119-
return node != null && (node.getFragmentType() == CodeFragmentType.KEYWORD && (keyword1.getSrcName().equals(node.getText()) || keyword2.getSrcName().equals(node.getText())));
120+
return node != null && (node.getFragmentType() == CodeFragmentType.KEYWORD && (keyword1.toSrc().equals(node.getText()) || keyword2.toSrc().equals(node.getText())));
120121
}
121122

122123

123124
@Override
124125
public boolean isKeyword(DocumentFragmentText<CodeFragmentType> node, JavaKeyword keyword1, JavaKeyword keyword2, JavaKeyword keyword3) {
125-
return node != null && (node.getFragmentType() == CodeFragmentType.KEYWORD && (keyword1.getSrcName().equals(node.getText()) || keyword2.getSrcName().equals(node.getText()) || keyword3.getSrcName().equals(node.getText())));
126+
return node != null && (node.getFragmentType() == CodeFragmentType.KEYWORD && (keyword1.toSrc().equals(node.getText()) || keyword2.toSrc().equals(node.getText()) || keyword3.toSrc().equals(node.getText())));
127+
}
128+
129+
130+
/** Java does not have a field block
131+
*/
132+
@Override
133+
public boolean isFieldBlock(SimpleTree<DocumentFragmentText<CodeFragmentType>> tokenNode) {
134+
return false;
126135
}
127136

128137
}

src/twg2/parser/baseAst/tools/AstFragType.java

+28
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package twg2.parser.baseAst.tools;
22

3+
import java.util.function.BiPredicate;
4+
5+
import lombok.val;
6+
import twg2.arrays.ArrayUtil;
37
import twg2.parser.codeParser.CodeFragmentType;
48
import twg2.parser.documentParser.DocumentFragment;
59
import twg2.parser.documentParser.DocumentFragmentText;
10+
import twg2.treeLike.simpleTree.SimpleTree;
611

712
/**
813
* @author TeamworkGuy2
@@ -72,4 +77,27 @@ public static final boolean isBlock(DocumentFragmentText<CodeFragmentType> node,
7277
return node != null && node.getFragmentType().isCompound() && node.getText().startsWith(blockSymbol);
7378
}
7479

80+
81+
// TODO unused
82+
public static final boolean blockContainsOnly(SimpleTree<DocumentFragmentText<CodeFragmentType>> block, BiPredicate<DocumentFragmentText<CodeFragmentType>, CodeFragmentType> cond, boolean emptyTreeValid, CodeFragmentType... optionalAllows) {
83+
if(block == null) {
84+
return emptyTreeValid;
85+
}
86+
if(optionalAllows == null) {
87+
optionalAllows = new CodeFragmentType[0];
88+
}
89+
val childs = block.getChildren();
90+
if(childs.size() == 0) {
91+
return false;
92+
}
93+
94+
for(val child : childs) {
95+
val frag = child.getData();
96+
if(ArrayUtil.indexOf(optionalAllows, frag.getFragmentType()) < 0 && !cond.test(frag, frag.getFragmentType())) {
97+
return false;
98+
}
99+
}
100+
return true;
101+
}
102+
75103
}

src/twg2/parser/baseAst/tools/AstUtil.java

-182
This file was deleted.

0 commit comments

Comments
 (0)