16.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit b416a402 authored by eckhart's avatar eckhart
Browse files

- - compile.Compiler.compile: None-test can be turned off object variable, not config var needed!

parent 3335167d
......@@ -43,7 +43,7 @@ from DHParser.transform import TransformationFunc
from DHParser.parse import Grammar
from DHParser.error import adjust_error_locations, is_error, Error
from DHParser.log import log_parsing_history, log_ST, is_logging, logfile_basename
from DHParser.toolkit import load_if_file, get_config_value
from DHParser.toolkit import load_if_file
__all__ = ('CompilerError', 'Compiler', 'compile_source', 'visitor_name')
......@@ -111,7 +111,7 @@ class Compiler:
self.source = ''
self.tree = ROOTNODE_PLACEHOLDER # type: RootNode
self.context = [] # type: List[Node]
self._None_check = get_config_value('raise_error_on_None_return')
self._None_check = True # type: bool
self._dirty_flag = False
def __call__(self, root: RootNode, source: str = '') -> Any:
......@@ -173,10 +173,12 @@ class Compiler:
self.context.append(node)
result = compiler(node)
self.context.pop()
if result is None and self._None_check and \
compiler.__annotations__['return'] not in (None, 'None'):
raise CompilerError('Method on_%s returned `None` instead of a '
'valid compilation result!' % elem)
if result is None and self._None_check:
raise CompilerError('Method on_%s returned `None` instead of a valid compilation '
'compilation result! Turn this check of by adding '
'"self._None_check = False" to the _reset()-Method of your'
'compiler class, in case on_%s actually SHOULD return None.'
% elem)
return result
......
......@@ -111,21 +111,6 @@ CONFIG_PRESET['default_serialization'] = SXPRESSION_SERIALIZATION
CONFIG_PRESET['flatten_sxpr_threshold'] = 120
########################################################################
#
# compiler configuration
#
########################################################################
# Turn checks for None-return of compiler-methods (a common mistake) in
# the compile.Compiler class on. This can lead to problems in cases
# where compile functions legitimately return `None` as value. See the
# examples/json for an example. In this case the configuration variable
# 'raise_error_on_None_return' should be set to False.
# Possible values: True, False Default value: True
CONFIG_PRESET['raise_error_on_None_return'] = True
########################################################################
#
# ebnf compiler configuration
......
......@@ -68,7 +68,7 @@ Match test "entry" for parser "entry" failed:
organization = {Wikipedia}
}
6:68: Error (1010): '}' ~ expected, "%E2\%80\%9" found!
6:68: Error (1010): '}' ~ expected, "%E2\%80\%9..." found!
6:69: Error (1040): Parser stopped before end! trying to recover but stopping history recording at this point.
7:1: Error (1020): Parser did not match!
Most advanced: 6, 68: entry->:ZeroOrMore->:Series->content->:Series->text->:Alternative->CONTENT_STRING->:Alternative->:Series->:Lookahead->/(?i)%/; MATCH; "%"
......
......@@ -59,7 +59,7 @@ class EBNFGrammar(Grammar):
r"""Parser for an EBNF source file.
"""
expression = Forward()
source_hash__ = "0a4657b403c537e8305c9ff3d3c90472"
source_hash__ = "9a341fad79f7e8eb46f1a657b553bec7"
static_analysis_pending__ = [True]
parser_initialization__ = ["upon instantiation"]
resume_rules__ = {}
......@@ -70,7 +70,7 @@ class EBNFGrammar(Grammar):
EOF = NegativeLookahead(RegExp('.'))
whitespace = Series(RegExp('~'), dwsp__)
regexp = Series(RegExp('/(?:(?<!\\\\)\\\\(?:/)|[^/])*?/'), dwsp__)
plaintext = Series(RegExp('`(?:(?<!\\\\)\\\\`|[^"])*?`'), dwsp__)
plaintext = Series(RegExp('`(?:(?<!\\\\)\\\\`|[^`])*?`'), dwsp__)
literal = Alternative(Series(RegExp('"(?:(?<!\\\\)\\\\"|[^"])*?"'), dwsp__), Series(RegExp("'(?:(?<!\\\\)\\\\'|[^'])*?'"), dwsp__))
symbol = Series(RegExp('(?!\\d)\\w+'), dwsp__)
option = Series(Series(Token("["), dwsp__), expression, Series(Token("]"), dwsp__), mandatory=1)
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment