Skip to content

Commit

Permalink
Use RE2/J instead of JsRegExp in JsfileParser.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=260039477
  • Loading branch information
tjgq authored and rishipal committed Jul 26, 2019
1 parent dff3a5c commit 2c94c36
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
29 changes: 29 additions & 0 deletions README.md
Expand Up @@ -378,6 +378,35 @@ an encoding of structured data.</td>
</tr>
</table>

### RE2/J

<table>
<tr>
<td>URL</td>
<td>https://github.com/google/re2j</td>
</tr>

<tr>
<td>Version</td>
<td>1.3</td>
</tr>

<tr>
<td>License</td>
<td>New BSD License</td>
</tr>

<tr>
<td>Description</td>
<td>Linear time regular expression matching in Java.</td>
</tr>

<tr>
<td>Local Modifications</td>
<td>None</td>
</tr>
</table>

### Truth

<table>
Expand Down
7 changes: 7 additions & 0 deletions pom-gwt.xml
Expand Up @@ -166,6 +166,13 @@
<artifactId>elemental2-core</artifactId>
<version>1.0.0-beta-1</version>
</dependency>

<dependency>
<groupId>com.google.re2j</groupId>
<artifactId>re2j</artifactId>
<version>1.3</version>
<classifier>sources</classifier>
</dependency>
</dependencies>

<build>
Expand Down
1 change: 1 addition & 0 deletions src/com/google/JsComp.gwt.xml
Expand Up @@ -19,6 +19,7 @@
<inherits name="com.google.common.escape.Escape"/>
<inherits name="com.google.common.io.Io"/>
<inherits name="com.google.gwt.json.JSON"/>
<inherits name="com.google.re2j.RE2J"/>
<inherits name="elemental2.core.Core"/>
<source path="debugging/sourcemap"/>
<source path="javascript/jscomp" excludes=".svn,.git,**/ant/**,**/refactoring/**,**/webservice/**,**/testing/**,**/transpile/**,**/linker/**,**/j2cl/**"/>
Expand Down
19 changes: 9 additions & 10 deletions src/com/google/javascript/jscomp/gwt/client/JsfileParser.java
Expand Up @@ -34,7 +34,6 @@
import com.google.javascript.jscomp.deps.ModuleLoader.ResolutionMode;
import com.google.javascript.jscomp.gwt.client.Util.JsArray;
import com.google.javascript.jscomp.gwt.client.Util.JsObject;
import com.google.javascript.jscomp.gwt.client.Util.JsRegExp;
import com.google.javascript.jscomp.modules.ModuleMetadataMap.ModuleMetadata;
import com.google.javascript.jscomp.parsing.Config;
import com.google.javascript.jscomp.parsing.ParserRunner;
Expand All @@ -43,6 +42,8 @@
import com.google.javascript.rhino.InputId;
import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.Token;
import com.google.re2j.Matcher;
import com.google.re2j.Pattern;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -184,23 +185,21 @@ static List<CommentAnnotation> parse(String comment) {
// 2. Support custom annotations (may already be done?)
// 3. Fix up existing code so that all these annotations are in @fileoverview
// 4. Change this code to simply inspect the script's JSDocInfo instead of re-parsing
JsRegExp re = new JsRegExp(
ANNOTATION_RE,
"g");
JsRegExp.Match match;
List<CommentAnnotation> out = new ArrayList<>();
while ((match = re.exec(comment)) != null) {
String name = match.get(ANNOTATION_NAME_GROUP);
String value = Strings.nullToEmpty(match.get(ANNOTATION_VALUE_GROUP));
Matcher matcher = ANNOTATION_RE.matcher(comment);
while (matcher.find()) {
String name = matcher.group(ANNOTATION_NAME_GROUP);
String value = Strings.nullToEmpty(matcher.group(ANNOTATION_VALUE_GROUP));
out.add(new CommentAnnotation(name, value));
}
return out;
}

// Regex for a JSDoc annotation with an `@name` and an optional brace-delimited `{value}`.
// The `@` should not match the middle of a word.
private static final String ANNOTATION_RE =
"(?:[^a-zA-Z0-9_$]|^)(@[a-zA-Z]+)(?:\\s*\\{\\s*([^}\\t\\n\\v\\f\\r ]+)\\s*\\})?";
private static final Pattern ANNOTATION_RE =
Pattern.compile(
"(?:[^a-zA-Z0-9_$]|^)(@[a-zA-Z]+)(?:\\s*\\{\\s*([^}\\t\\n\\v\\f\\r ]+)\\s*\\})?");
private static final int ANNOTATION_NAME_GROUP = 1;
private static final int ANNOTATION_VALUE_GROUP = 2;
}
Expand Down

0 comments on commit 2c94c36

Please sign in to comment.