Skip to content

Commit

Permalink
Added basic bean-check command
Browse files Browse the repository at this point in the history
  • Loading branch information
norseghost committed Sep 18, 2014
1 parent ea5c7f8 commit 44648db
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 2 deletions.
27 changes: 27 additions & 0 deletions bean_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sublime, sublime_plugin, subprocess, os

class BeanCheckCommand(sublime_plugin.TextCommand):
def run(self, edit):
print("Running!")
self.run_check(edit)

def show_report_buffer(self, report, text, edit):
report_buffer = self.view.window().new_file()
report_buffer.set_scratch(True)
report_buffer.set_syntax_file("Packages/Beancount/beancount.tmLanguage")
report_buffer.set_name("Report: %s" % report)
report_buffer.insert(edit, 0, text)

def show_report_panel(self, text, edit):
output_view = self.view.window().get_output_panel("tests")
self.view.window().run_command("show_panel", {"panel": "output.tests"})
output_view.insert(edit, 0, text)

def run_check(self, edit):
#check = subprocess.Popen([ "bean-check", filename ], universal_newlines=True, stderr=subprocess.STDOUT, stdout=subprocess.STDOUT)
check = subprocess.check_output([ "bean-check", self.view.file_name() ], universal_newlines=True, stderr=subprocess.STDOUT)
#output, errors = check.communicate()
if len(check) == 0:
self.show_report_panel("No errors were found!", edit)
else:
self.show_report_panel(check, edit)
19 changes: 18 additions & 1 deletion beancount.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ patterns:
match: \@


- comment: Lot assignment
- comment: cost assignment
begin: (\{)
beginCaptures:
'1': {name: keyword.operator.assignment.beancount}
Expand Down Expand Up @@ -107,3 +107,20 @@ patterns:
- comment: Illegal
name: invalid.illegal.unrecognized.beancount
match: '[^\s}]'

repository:
numbers:
match: ([\-|\+]?)([\d]+[\.]?[\d]*)
captures:
'1': {name: keyword.operator.modifier.beancount}
'2': {name: constant.numeric.currency.beancount}
account-names:
match: ([A-Z][A-Za-z0-9\-]+)
dates:
match: ([0-9]{4})(\-)([0-9]{2})(\-)([0-9]{2})
captures:
'1': {name: constant.numeric.date.year.beancount}
'2': {name: punctuation.separator.beancount}
'3': {name: constant.numeric.date.month.beancount}
'4': {name: punctuation.separator.beancount}
'5': {name: constant.numeric.date.day.beancount}
61 changes: 60 additions & 1 deletion beancount.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
</dict>
</dict>
<key>comment</key>
<string>Lot assignment</string>
<string>cost assignment</string>
<key>end</key>
<string>(\})</string>
<key>endCaptures</key>
Expand Down Expand Up @@ -302,6 +302,65 @@
<string>invalid.illegal.unrecognized.beancount</string>
</dict>
</array>
<key>repository</key>
<dict>
<key>account-names</key>
<dict>
<key>match</key>
<string>([A-Z][A-Za-z0-9\-]+)</string>
</dict>
<key>dates</key>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>constant.numeric.date.year.beancount</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.separator.beancount</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>constant.numeric.date.month.beancount</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>punctuation.separator.beancount</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>constant.numeric.date.day.beancount</string>
</dict>
</dict>
<key>match</key>
<string>([0-9]{4})(\-)([0-9]{2})(\-)([0-9]{2})</string>
</dict>
<key>numbers</key>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.operator.modifier.beancount</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>constant.numeric.currency.beancount</string>
</dict>
</dict>
<key>match</key>
<string>([\-|\+]?)([\d]+[\.]?[\d]*)</string>
</dict>
</dict>
<key>scopeName</key>
<string>source.beancount</string>
<key>uuid</key>
Expand Down

0 comments on commit 44648db

Please sign in to comment.