forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSParser.java
More file actions
77 lines (64 loc) · 1.99 KB
/
Copy pathJSParser.java
File metadata and controls
77 lines (64 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.semmle.js.parser;
import com.semmle.js.ast.Comment;
import com.semmle.js.ast.Node;
import com.semmle.js.ast.Token;
import com.semmle.js.extractor.ExtractionMetrics;
import com.semmle.js.extractor.ExtractionMetrics.ExtractionPhase;
import com.semmle.js.extractor.ExtractorConfig;
import com.semmle.js.extractor.ExtractorConfig.SourceType;
import java.util.List;
/** Helper class for invoking the underlying JavaScript parser. */
public class JSParser {
/**
* The result of a parse.
*
* <p>If the parse was successful, {@link #ast} will be non-null. Otherwise, {@link #errors} holds
* a list of parse errors encountered.
*/
public static class Result {
/** The parsed source code. */
private final String source;
/** The root of the parsed AST. */
private final Node ast;
/** The list of parsed tokens. */
private final List<Token> tokens;
/** The list of parsed comments. */
private final List<Comment> comments;
/** The list of parser errors encountered while parsing. */
private final List<ParseError> errors;
public Result(
String source,
Node ast,
List<Token> tokens,
List<Comment> comments,
List<ParseError> errors) {
this.source = source;
this.ast = ast;
this.tokens = tokens;
this.comments = comments;
this.errors = errors;
}
public Node getAST() {
return ast;
}
public String getSource() {
return source;
}
public List<Comment> getComments() {
return comments;
}
public List<Token> getTokens() {
return tokens;
}
public List<ParseError> getErrors() {
return errors;
}
}
public static Result parse(
ExtractorConfig config, SourceType sourceType, String source, ExtractionMetrics metrics) {
metrics.startPhase(ExtractionPhase.JSParser_parse);
Result result = JcornWrapper.parse(config, sourceType, source);
metrics.stopPhase(ExtractionPhase.JSParser_parse);
return result;
}
}