public class OffsetCue extends Object
For example, when "version.as" is included in "Button.as" at offset 10 in
"Button.as", the first character in "version.as" has local offset "0", but
its "absolute" offset in "Button.as" is "10". Suppose keyword var
is
after the include
statement, and its "local" offset is "20", since
"version.as" has 100 characters in it, the "absolute" offset of var
becomes "120".
OffsetCue
objects are markers
on the "absolute" offset axis. It records the adjustment between an "local"
offset and its "absolute" offset.
The formula is:
local = absolute - adjustment
The JFlex-generated lexer sets the local offset when it tokenizes a file.
Meanwhile, IncludeHandler
records the "adjustment" to compute the
"absolute" offset.
Besides offset adjustment, an OffsetCue
also records the name of the
file the character is from.
Imagine the following character stream and the tuples inside parentheses are
OffsetCue
.
---------> -----------> -----------> ------> -----------> (0:main.as)_______(2:A.as)______(4:B.as)______(6:A.as)____(7:main.as)_______ [local] 0 1 0 1 0 1 2 3 2 2 3 [absolute] 0 1 2 3 4 5 6 7 8 9 10 [file] main.as in "A" in "B" back to "A" back to "main"
0:main.as
- the root file.2:A.as
- main.as includes A.as. Local offset "1" in A.as is
absolute offset "3" in parsing main.as, because the adjustment is "2";4:B.as
- A.as includes B.as. Local offset "0" in B.as is absolute
offset "4" in parsing main.as, because the adjustment is "4"6:A.as
- return to A.as from B.as. The adjustments change because
characters in B.as advance absolute offsets.7:main.as
- return to main.as from A.as.OffsetCue
applies to all the characters/tokens after itself
(inclusive) until the next OffsetCue
(exclusive).
OffsetCue
is an immutable class. It is created in
IncludeHandler
.
Modifier and Type | Field and Description |
---|---|
int |
absolute
Absolute offset.
|
int |
adjustment
Adjustment between absolute offset and local offset.
|
String |
filename
File that contains the characters after this cue point until the next cue
point.
|
int |
local
Local offset.
|
public final String filename
public final int adjustment
local = absolute - adjustment
public final int absolute
public final int local
protected OffsetCue(String filename, int absolute, int adjustment)
Copyright © 2016 The Apache Software Foundation. All rights reserved.