mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre into master
This commit is contained in:
commit
be6ce66ed1
@ -195,7 +195,8 @@ The syntax of the language is shown by the following grammar. For a discussion o
|
||||
function ::= identifier '(' expression [ ',' expression ]* ')'
|
||||
compare ::= expression compare_op expression
|
||||
compare_op ::= '==' | '!=' | '>=' | '>' | '<=' | '<' | '==#' | '!=#' | '>=#' | '>#' | '<=#' | '<#'
|
||||
if_expression ::= 'if' expression 'then' expression_list ['else' statement] 'fi'
|
||||
if_expression ::= 'if' expression 'then' expression_list [elif_expression] ['else' expression_list] 'fi'
|
||||
elif_expression ::= 'elif' expression 'then' expression_list elif_expression | ''
|
||||
assignment ::= identifier '=' expression
|
||||
constant ::= " string " | ' string ' | number
|
||||
identifier ::= sequence of letters or ``_`` characters
|
||||
|
@ -44,7 +44,7 @@ class TemplateHighlighter(QSyntaxHighlighter):
|
||||
Formats = {}
|
||||
BN_FACTOR = 1000
|
||||
|
||||
KEYWORDS = ["program", 'if', 'then', 'else', 'fi']
|
||||
KEYWORDS = ["program", 'if', 'then', 'else', 'elif', 'fi']
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super(TemplateHighlighter, self).__init__(parent)
|
||||
|
@ -233,6 +233,13 @@ class _Parser(object):
|
||||
except:
|
||||
return False
|
||||
|
||||
def token_is_elif(self):
|
||||
try:
|
||||
token = self.prog[self.lex_pos]
|
||||
return token[1] == 'elif' and token[0] == self.LEX_KEYWORD
|
||||
except:
|
||||
return False
|
||||
|
||||
def token_is_fi(self):
|
||||
try:
|
||||
token = self.prog[self.lex_pos]
|
||||
@ -282,6 +289,8 @@ class _Parser(object):
|
||||
self.error(_("Missing 'then' in if statement"))
|
||||
self.consume()
|
||||
then_part = self.expression_list()
|
||||
if self.token_is_elif():
|
||||
return IfNode(condition, then_part, [self.if_expression(),])
|
||||
if self.token_is_else():
|
||||
self.consume()
|
||||
else_part = self.expression_list()
|
||||
@ -609,7 +618,7 @@ class TemplateFormatter(string.Formatter):
|
||||
lex_scanner = re.Scanner([
|
||||
(r'(==#|!=#|<=#|<#|>=#|>#)', lambda x,t: (_Parser.LEX_NUMERIC_INFIX, t)),
|
||||
(r'(==|!=|<=|<|>=|>)', lambda x,t: (_Parser.LEX_STRING_INFIX, t)), # noqa
|
||||
(r'(if|then|else|fi)\b', lambda x,t: (_Parser.LEX_KEYWORD, t)), # noqa
|
||||
(r'(if|then|else|elif|fi)\b',lambda x,t: (_Parser.LEX_KEYWORD, t)), # noqa
|
||||
(r'[(),=;]', lambda x,t: (_Parser.LEX_OP, t)), # noqa
|
||||
(r'-?[\d\.]+', lambda x,t: (_Parser.LEX_CONST, t)), # noqa
|
||||
(r'\$', lambda x,t: (_Parser.LEX_ID, t)), # noqa
|
||||
|
Loading…
x
Reference in New Issue
Block a user