-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Import of "Meta-Interpreter"
- Loading branch information
Showing
22 changed files
with
408 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# This is used to create the interpreter as a singleton object. | ||
# Use this to import the interpreter to ensure you get the same module instance | ||
# as the other files | ||
try: | ||
from ExpandRegion.minterp import interpreter | ||
except: | ||
# different folder name or test cases | ||
print( | ||
"Warning: Rename the folder of ExpandRegion to ExpandRegion.\n" | ||
"Otherwise editing files requires a restart of Sublime Text" | ||
"for the changes to be propagated." | ||
) | ||
try: | ||
from minterp import interpreter | ||
except: | ||
from .minterp import interpreter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,29 @@ | ||
import re | ||
|
||
try: | ||
import utils | ||
from _minterp import interpreter | ||
except: | ||
from . import utils | ||
from ._minterp import interpreter | ||
|
||
def expand_to_line(string, startIndex, endIndex): | ||
linebreakRe = re.compile(r'\n') | ||
|
||
spacesAndTabsRe = re.compile(r'([ \t]+)') | ||
def expand_to_line(string, start, end): | ||
line = utils.get_line(string, start, end) | ||
indent = utils.get_indent(string, line) | ||
lstart = line["start"] + indent | ||
if start < lstart: | ||
lstart = line["start"] | ||
lend = max(end, line["end"]) | ||
if lstart == start and lend == end: | ||
return | ||
return utils.create_return_obj(lstart, lend, string, "line") | ||
|
||
searchIndex = startIndex - 1; | ||
while True: | ||
if searchIndex < 0: | ||
newStartIndex = searchIndex + 1 | ||
break | ||
char = string[searchIndex:searchIndex+1] | ||
if linebreakRe.match(char): | ||
newStartIndex = searchIndex + 1 | ||
break | ||
else: | ||
searchIndex -= 1 | ||
|
||
searchIndex = endIndex; | ||
while True: | ||
if searchIndex > len(string) - 1: | ||
newEndIndex = searchIndex | ||
break | ||
char = string[searchIndex:searchIndex+1] | ||
if linebreakRe.match(char): | ||
newEndIndex = searchIndex | ||
break | ||
else: | ||
searchIndex += 1 | ||
def expand_to_full_line(string, start, end): | ||
line = utils.get_line(string, start, end) | ||
lstart = line["start"] | ||
lend = line["end"] | ||
return utils.create_return_obj(lstart, lend, string, "full_line") | ||
|
||
s = string[newStartIndex:newEndIndex] | ||
r = spacesAndTabsRe.match(s) | ||
if r and r.end() <= startIndex: | ||
newStartIndex = newStartIndex + r.end(); | ||
|
||
try: | ||
if startIndex == newStartIndex and endIndex == newEndIndex: | ||
return None | ||
else: | ||
return utils.create_return_obj(newStartIndex, newEndIndex, string, "line") | ||
except NameError: | ||
return None | ||
interpreter.register_command("line", expand_to_line) | ||
interpreter.register_command("full_line", expand_to_full_line) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.