Skip to content

Commit

Permalink
Removes Coconut console highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub committed Feb 12, 2016
1 parent 565283a commit 17899f2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 63 deletions.
4 changes: 2 additions & 2 deletions HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Now that you've got Coconut installed, the obvious first thing to do is to play
coconut
```
and you should see something like
```coconutcon
```coconut
Coconut Interpreter:
(type "exit()" or press Ctrl-D to end)
>>>
Expand Down Expand Up @@ -135,7 +135,7 @@ Compiling Coconut files and projects with the Coconut command-line utility is in
coconut /directory/to/hello_world.coc
```
where `/directory/to/` is the path from the current working directory to `hello_world.coc`. Running this command should yield the output
```coconutcon
```bash
Coconut: Compiling /directory/to/hello_world.coc ...
Coconut: Compiled to /directory/to/hello_world.py .
```
Expand Down
61 changes: 2 additions & 59 deletions coconut/highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,64 +61,7 @@ class coclexer(pylexer):

tokens["keywords"] = [
(words(keywords + reserved_vars, suffix=r"\b"), Keyword),
(words(const_vars, suffix=r"\b"), Keyword.Constant),
(words(const_vars, suffix=r"\b"), Keyword.Constant)
]
tokens["backtick"] = [("`.*?`", String.Backtick)]
tokens["name"].append((r"[$\\]", Operator))

class cocconlexer(pyconlexer):
"""Coconut console syntax highlighter."""
name = "coconutcon"
aliases = ["coccon", "coconutcon", "force_coccon", "force_coconutcon"]
filenames = []

def get_tokens_unprocessed(self, text):
if not self.python3:
raise CoconutException("Coconut code is always Python 3")
pylexer = coclexer(**self.options)
tblexer = Python3TracebackLexer(**self.options)

# taken with modifications from pygments/lexers/python.py under the BSD
curcode = ""
insertions = []
curtb = ""
tbindex = 0
tb = 0
for match in line_re.finditer(text):
line = match.group()
if line.startswith(default_prompt) or line.startswith(default_moreprompt):
tb = 0
insertions.append((len(curcode), [(0, Generic.Prompt, line[:4])]))
curcode += line[4:]
elif not line.rstrip() and not tb:
curcode += line[3:]
else:
if curcode:
for item in do_insertions(insertions, pylexer.get_tokens_unprocessed(curcode)):
yield item
curcode = ""
insertions = []
if line.startswith("Coconut"):
yield match.start(), Name, line
elif (line.startswith("Traceback (most recent call last):")
or re.match(' File "[^"]+", line \\d+\\n$', line)):
tb = 1
curtb = line
tbindex = match.start()
elif line == "KeyboardInterrupt\n":
yield match.start(), Name.Class, line
elif tb:
curtb += line
if not line.startswith(" "):
tb = 0
for i, t, v in tblexer.get_tokens_unprocessed(curtb):
yield tbindex+i, t, v
curtb = ""
else:
yield match.start(), Generic.Output, line
if curcode:
for item in do_insertions(insertions, pylexer.get_tokens_unprocessed(curcode)):
yield item
if curtb:
for i, t, v in tblexer.get_tokens_unprocessed(curtb):
yield tbindex+i, t, v
tokens["name"] = tokens["name"] + [(r"[$\\]", Operator)]
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@
"pygments.lexers": [
"force_python = coconut.highlighter:pylexer",
"force_pycon = coconut.highlighter:pyconlexer",
"coconut = coconut.highlighter:coclexer",
"coconutcon = coconut.highlighter:cocconlexer"
"coconut = coconut.highlighter:coclexer"
]
}
)

0 comments on commit 17899f2

Please sign in to comment.