Skip to content

Commit

Permalink
change "import library" syntax slighty
Browse files Browse the repository at this point in the history
bump version number in prepartion for a release
  • Loading branch information
msolo committed Jul 12, 2011
1 parent d3aaa7a commit 7ed093a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion spitfire/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__author__ = 'Mike Solomon'
__author_email__ = '<mas63 @t cornell d0t edu>'
__version__ = '0.7.13'
__version__ = '0.7.14'
__license__ = 'BSD License'
13 changes: 5 additions & 8 deletions spitfire/compiler/parser.g
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ parser _SpitfireParser:
|
'absolute_extends' SPACE modulename CLOSE_DIRECTIVE {{ return AbsoluteExtendsNode(modulename) }}
|
'from' SPACE modulename SPACE importkeyword SPACE identifier CLOSE_DIRECTIVE {{ return FromNode(modulename, identifier, library=importkeyword) }}
'from' SPACE modulename SPACE 'import' SPACE library_keyword identifier CLOSE_DIRECTIVE {{ return FromNode(modulename, identifier, library=library_keyword) }}
|
importkeyword SPACE modulename CLOSE_DIRECTIVE {{ return ImportNode(modulename, library=importkeyword) }}
'import' SPACE library_keyword modulename CLOSE_DIRECTIVE {{ return ImportNode(modulename, library=library_keyword) }}
|
'slurp' CLOSE_DIRECTIVE {{ return CommentNode('slurp') }}
|
Expand All @@ -139,12 +139,9 @@ parser _SpitfireParser:
]
CLOSE_DIRECTIVE {{ return EchoNode(_true_exp, _test_exp, _false_exp) }}

rule importkeyword:
'import'
{{ _library = False }} [
'_library'
{{ _library = True }}
]
rule library_keyword:
{{ _library = False }}
['library' SPACE {{ _library = True }} ]
{{ return _library }}

rule modulename:
Expand Down
26 changes: 14 additions & 12 deletions spitfire/compiler/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class _SpitfireParserScanner(Scanner):
("'def'", re.compile('def')),
("'i18n'", re.compile('i18n')),
("'block'", re.compile('block')),
("'_library'", re.compile('_library')),
("'import'", re.compile('import')),
("'library'", re.compile('library')),
("'else'", re.compile('else')),
("'if'", re.compile('if')),
("'echo'", re.compile('echo')),
Expand All @@ -42,6 +41,7 @@ class _SpitfireParserScanner(Scanner):
("'continue'", re.compile('continue')),
("'break'", re.compile('break')),
("'slurp'", re.compile('slurp')),
("'import'", re.compile('import')),
("'from'", re.compile('from')),
("'absolute_extends'", re.compile('absolute_extends')),
("'extends'", re.compile('extends')),
Expand Down Expand Up @@ -135,7 +135,7 @@ def i18n_goal(self):
return fragment

def statement(self):
_token_ = self._peek("'implements'", "'extends'", "'absolute_extends'", "'from'", "'slurp'", "'break'", "'continue'", "'attr'", "'filter'", "'set'", "'echo'", "'import'")
_token_ = self._peek("'implements'", "'extends'", "'absolute_extends'", "'from'", "'import'", "'slurp'", "'break'", "'continue'", "'attr'", "'filter'", "'set'", "'echo'")
if _token_ == "'implements'":
self._scan("'implements'")
SPACE = self._scan('SPACE')
Expand All @@ -159,17 +159,19 @@ def statement(self):
SPACE = self._scan('SPACE')
modulename = self.modulename()
SPACE = self._scan('SPACE')
importkeyword = self.importkeyword()
self._scan("'import'")
SPACE = self._scan('SPACE')
library_keyword = self.library_keyword()
identifier = self.identifier()
CLOSE_DIRECTIVE = self.CLOSE_DIRECTIVE()
return FromNode(modulename, identifier, library=importkeyword)
return FromNode(modulename, identifier, library=library_keyword)
elif _token_ == "'import'":
importkeyword = self.importkeyword()
self._scan("'import'")
SPACE = self._scan('SPACE')
library_keyword = self.library_keyword()
modulename = self.modulename()
CLOSE_DIRECTIVE = self.CLOSE_DIRECTIVE()
return ImportNode(modulename, library=importkeyword)
return ImportNode(modulename, library=library_keyword)
elif _token_ == "'slurp'":
self._scan("'slurp'")
CLOSE_DIRECTIVE = self.CLOSE_DIRECTIVE()
Expand Down Expand Up @@ -233,11 +235,11 @@ def statement(self):
CLOSE_DIRECTIVE = self.CLOSE_DIRECTIVE()
return EchoNode(_true_exp, _test_exp, _false_exp)

def importkeyword(self):
self._scan("'import'")
def library_keyword(self):
_library = False
if self._peek("'_library'", 'SPACE') == "'_library'":
self._scan("'_library'")
if self._peek("'library'", 'ID') == "'library'":
self._scan("'library'")
SPACE = self._scan('SPACE')
_library = True
return _library

Expand All @@ -253,7 +255,7 @@ def modulename(self):
def directive(self):
START_DIRECTIVE = self._scan('START_DIRECTIVE')
_node_list = NodeList()
_token_ = self._peek('SINGLE_LINE_COMMENT', 'MULTI_LINE_COMMENT', "'block'", "'i18n'", "'def'", "'for[ \\t]*'", "'strip_lines'", "'if'", "'implements'", "'extends'", "'absolute_extends'", "'from'", "'slurp'", "'break'", "'continue'", "'attr'", "'filter'", "'set'", "'echo'", "'import'", 'END', 'LITERAL_DOLLAR_SIGN', 'LITERAL_BACKSLASH', 'START_DIRECTIVE', 'SPACE', 'NEWLINE', 'START_PLACEHOLDER', 'END_DIRECTIVE', "'#elif'", 'TEXT', "'#else'")
_token_ = self._peek('SINGLE_LINE_COMMENT', 'MULTI_LINE_COMMENT', "'block'", "'i18n'", "'def'", "'for[ \\t]*'", "'strip_lines'", "'if'", "'implements'", "'extends'", "'absolute_extends'", "'from'", "'import'", "'slurp'", "'break'", "'continue'", "'attr'", "'filter'", "'set'", "'echo'", 'END', 'LITERAL_DOLLAR_SIGN', 'LITERAL_BACKSLASH', 'START_DIRECTIVE', 'SPACE', 'NEWLINE', 'START_PLACEHOLDER', 'END_DIRECTIVE', "'#elif'", 'TEXT', "'#else'")
if _token_ == 'SINGLE_LINE_COMMENT':
SINGLE_LINE_COMMENT = self._scan('SINGLE_LINE_COMMENT')
_node_list.append(CommentNode(START_DIRECTIVE + SINGLE_LINE_COMMENT))
Expand Down
2 changes: 1 addition & 1 deletion tests/index2.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#extends tests.base
#import_library tests.util
#import library tests.util

#def title() #test index#end def#

Expand Down
4 changes: 2 additions & 2 deletions tests/uses_library.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#from tests import_library some_library
#import_library tests.some_library
#from tests import library some_library
#import library tests.some_library

#def some_fn
$tests.some_library.library_fn($test_y)
Expand Down

0 comments on commit 7ed093a

Please sign in to comment.