Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QueryR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Lopez
QueryR
Commits
d60eea3c
Commit
d60eea3c
authored
7 years ago
by
Florian Angerer
Browse files
Options
Downloads
Patches
Plain Diff
Modified parser to detect and handle file delimiters.
parent
155f8b3c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g
+54
-6
54 additions, 6 deletions
...acle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g
with
54 additions
and
6 deletions
com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g
+
54
−
6
View file @
d60eea3c
...
...
@@ -28,6 +28,7 @@ package com.oracle.truffle.r.parser;
import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.frame.MaterializedFrame;
...
...
@@ -39,6 +40,7 @@ import com.oracle.truffle.r.runtime.RInternalError;
import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.data.RComplex;
import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.RSource;
import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.env.REnvironment;
import com.oracle.truffle.r.runtime.nodes.RCodeBuilder;
...
...
@@ -60,7 +62,9 @@ import com.oracle.truffle.r.runtime.RError;
@members {
private Source source;
private Source initialSource;
private RCodeBuilder<T> builder;
private int fileStartOffset = 0;
/**
* Always use this constructor to initialize the R specific fields.
...
...
@@ -69,6 +73,7 @@ import com.oracle.truffle.r.runtime.RError;
super(new CommonTokenStream(new RLexer(new ANTLRStringStream(source.getCode()))));
assert source != null && builder != null;
this.source = source;
this.initialSource = source;
this.builder = builder;
}
...
...
@@ -101,8 +106,13 @@ import com.oracle.truffle.r.runtime.RError;
*/
private SourceSection src(Token t) {
CommonToken token = (CommonToken) t;
int startIndex = token.getStartIndex();
return source.createSection(startIndex, token.getStopIndex() - startIndex + 1);
try {
return source.createSection(token.getStartIndex() - fileStartOffset, token.getStopIndex() - token.getStartIndex() + 1);
} catch(IllegalArgumentException e) {
// fall back and use the initial source (the file being parsed)
resetSource();
return source.createSection(token.getStartIndex(), token.getStopIndex() - token.getStartIndex() + 1);
}
}
/**
...
...
@@ -114,8 +124,43 @@ import com.oracle.truffle.r.runtime.RError;
int startIndex = cstart.getStartIndex();
int stopIndex = cstop.getStopIndex();
int length = stopIndex - startIndex + (cstop.getType() == Token.EOF ? 0 : 1);
return source.createSection(startIndex, length);
try {
return source.createSection(startIndex - fileStartOffset, length);
} catch(IllegalArgumentException e) {
// fall back and use the initial source (the file being parsed)
resetSource();
return source.createSection(startIndex, length);
}
}
/**
* Checks if the token is a comment token indicating that the following part of the source file was
* pasted from another file.
* The format of this file delimiter is '#line 1 "filename"'
*/
private void checkFileDelim(CommonToken commentToken) {
String commentLine = commentToken.getText();
if(commentLine.startsWith("#line 1")) {
int q0 = commentLine.indexOf("\"");
int q1 = commentLine.indexOf("\"", q0+1);
if(q0 != -1 && q1 != -1) {
String path = commentLine.substring(q0+1, q1);
try {
source = RSource.fromFileName(path, false);
fileStartOffset = commentToken.getStopIndex() + 1;
} catch (IOException e) {
}
} else {
// fall back and use the initial source (the file being parsed)
resetSource();
}
}
}
private void resetSource() {
source = initialSource;
fileStartOffset = 0;
}
// without this override, the parser will not throw exceptions if it can recover
@Override
...
...
@@ -205,9 +250,12 @@ statement returns [T v]
: e=expr_or_assign n_one { $v = $e.v; }
;
n_ : (NEWLINE | COMMENT)*;
n_one : (NEWLINE | COMMENT)+ | EOF | SEMICOLON n_;
n_multi : (NEWLINE | COMMENT | SEMICOLON)+ | EOF;
n_ : (NEWLINE | COMMENT { checkFileDelim((CommonToken)last()); }
)*;
n_one : (NEWLINE | COMMENT { checkFileDelim((CommonToken)last()); }
)+ | EOF | SEMICOLON n_;
n_multi : (NEWLINE | COMMENT { checkFileDelim((CommonToken)last()); }
| SEMICOLON)+ | EOF;
expr_wo_assign returns [T v]
: w=while_expr { $v = $w.v; }
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment