- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
compiler plugin source code positions
Fri, 2009-06-26, 01:27
Hi all,
Is there a way to get more source code position information from the compiler -- namely, the range of the given AST node? I am looking at tree.pos, where tree is the argument passed into a Transformer's transform() function.
I tried looking around with Java reflection... no luck. The RangePosition in Position.scala seems to only be used in nsc/interactive/ (I also tried putting a println in it's constructor).
Thanks in advance,
Nicholas
Is there a way to get more source code position information from the compiler -- namely, the range of the given AST node? I am looking at tree.pos, where tree is the argument passed into a Transformer's transform() function.
I tried looking around with Java reflection... no luck. The RangePosition in Position.scala seems to only be used in nsc/interactive/ (I also tried putting a println in it's constructor).
Thanks in advance,
Nicholas
Fri, 2009-06-26, 07:17
#2
Re: compiler plugin source code positions
Nicholas Tung wrote:
> Hi all,
>
> Is there a way to get more source code position information from
> the compiler -- namely, the range of the given AST node? I am looking
> at tree.pos, where tree is the argument passed into a Transformer's
> transform() function.
>
> I tried looking around with Java reflection... no luck. The
> RangePosition in Position.scala seems to only be used in
> nsc/interactive/ (I also tried putting a println in it's constructor).
>
> Thanks in advance,
> Nicholas
Hi all,
I think I found a solution -- to override rangePos in
nsc.util.Global. However, is there a way to integrate this in a plugin
(while keeping it as a plugin versus a top-level Java class?).
Also, I seem to be having problems re-compiling; for example, if I
change rangePos between the two options below, if I don't do "ant
clean", I get this error:
"Exception in thread "main" java.lang.NoSuchMethodError:
scala.tools.nsc.Global.rangePos(Lscala/tools/nsc/util/SourceFile;III)Lscala/tools/nsc/util/RangePosition;
at
scala.tools.nsc.ast.parser.Parsers$UnitParser.r2p(Parsers.scala:73)"
This results in latency for changing anything in the compiler at 9
minutes (after ant clean)... while one can execute $(ant clean) after
syntax is valid, this still seems rather slow.
def rangePos(source: SourceFile, start: Int, mid: Int, end: Int) =
// first compile option: new RangePosition(source, start, mid, end)
// second compile option: OffsetPosition(source, mid)
Thanks so much!
Nicholas
Nicholas Tung wrote:
> Hi all,
>
> Is there a way to get more source code position information from
> the compiler -- namely, the range of the given AST node? I am looking
> at tree.pos, where tree is the argument passed into a Transformer's
> transform() function.
>
> I tried looking around with Java reflection... no luck. The
> RangePosition in Position.scala seems to only be used in
> nsc/interactive/ (I also tried putting a println in it's constructor).
>
> Thanks in advance,
> Nicholas
Hi all,
I think I found a solution -- to override rangePos in
nsc.util.Global. However, is there a way to integrate this in a plugin
(while keeping it as a plugin versus a top-level Java class?).
Also, I seem to be having problems re-compiling; for example, if I
change rangePos between the two options below, if I don't do "ant
clean", I get this error:
"Exception in thread "main" java.lang.NoSuchMethodError:
scala.tools.nsc.Global.rangePos(Lscala/tools/nsc/util/SourceFile;III)Lscala/tools/nsc/util/RangePosition;
at
scala.tools.nsc.ast.parser.Parsers$UnitParser.r2p(Parsers.scala:73)"
This results in latency for changing anything in the compiler at 9
minutes (after ant clean)... while one can execute $(ant clean) after
syntax is valid, this still seems rather slow.
def rangePos(source: SourceFile, start: Int, mid: Int, end: Int) =
// first compile option: new RangePosition(source, start, mid, end)
// second compile option: OffsetPosition(source, mid)
Thanks so much!
Nicholas