| @@ -1,10 +1,9 @@ | |||
| from .utils import logger | |||
| from .tree import Tree | |||
| from .visitors import Transformer, Visitor, v_args, Discard, Transformer_NonRecursive | |||
| from .visitors import InlineTransformer, inline_args # XXX Deprecated | |||
| from .exceptions import (ParseError, LexError, GrammarError, UnexpectedToken, | |||
| UnexpectedInput, UnexpectedCharacters, UnexpectedEOF, LarkError) | |||
| from .lexer import Token | |||
| from .lark import Lark | |||
| __version__ = "0.11.4" | |||
| __version__ = "1.0.0a" | |||
| @@ -1,5 +1,3 @@ | |||
| from warnings import warn | |||
| from .utils import Serialize | |||
| from .lexer import TerminalDef | |||
| @@ -23,11 +21,6 @@ class LexerConf(Serialize): | |||
| self.use_bytes = use_bytes | |||
| self.lexer_type = None | |||
| @property | |||
| def tokens(self): | |||
| warn("LexerConf.tokens is deprecated. Use LexerConf.terminals instead", DeprecationWarning) | |||
| return self.terminals | |||
| def _deserialize(self): | |||
| self.terminals_by_name = {t.name: t for t in self.terminals} | |||
| @@ -1,5 +1,3 @@ | |||
| from warnings import warn | |||
| from .utils import logger, NO_VALUE | |||
| @@ -193,7 +191,7 @@ class UnexpectedToken(ParseError, UnexpectedInput): | |||
| # TODO considered_rules and expected can be figured out using state | |||
| self.line = getattr(token, 'line', '?') | |||
| self.column = getattr(token, 'column', '?') | |||
| self.pos_in_stream = getattr(token, 'pos_in_stream', None) | |||
| self.pos_in_stream = getattr(token, 'start_pos', None) | |||
| self.state = state | |||
| self.token = token | |||
| @@ -220,11 +218,6 @@ class UnexpectedToken(ParseError, UnexpectedInput): | |||
| return message | |||
| @property | |||
| def puppet(self): | |||
| warn("UnexpectedToken.puppet attribute has been renamed to interactive_parser", DeprecationWarning) | |||
| return self.interactive_parser | |||
| class VisitError(LarkError): | |||
| @@ -4,7 +4,6 @@ from abc import ABC, abstractmethod | |||
| import sys, os, pickle, hashlib | |||
| from io import open | |||
| import tempfile | |||
| from warnings import warn | |||
| from .exceptions import ConfigurationError, assert_config | |||
| from .utils import Serialize, SerializeMemoizer, FS, isascii, logger | |||
| @@ -568,23 +567,5 @@ class Lark(Serialize): | |||
| """ | |||
| return self.parser.parse(text, start=start, on_error=on_error) | |||
| @property | |||
| def source(self): | |||
| warn("Attribute Lark.source was renamed to Lark.source_path", DeprecationWarning) | |||
| return self.source_path | |||
| @source.setter | |||
| def source(self, value): | |||
| self.source_path = value | |||
| @property | |||
| def grammar_source(self): | |||
| warn("Attribute Lark.grammar_source was renamed to Lark.source_grammar", DeprecationWarning) | |||
| return self.source_grammar | |||
| @grammar_source.setter | |||
| def grammar_source(self, value): | |||
| self.source_grammar = value | |||
| ###} | |||
| @@ -7,7 +7,6 @@ from .utils import classify, get_regexp_width, Py36, Serialize | |||
| from .exceptions import UnexpectedCharacters, LexError, UnexpectedToken | |||
| ###{standalone | |||
| from warnings import warn | |||
| from copy import copy | |||
| @@ -121,18 +120,18 @@ class Token(str): | |||
| Attributes: | |||
| type: Name of the token (as specified in grammar) | |||
| value: Value of the token (redundant, as ``token.value == token`` will always be true) | |||
| pos_in_stream: The index of the token in the text | |||
| start_pos: The index of the token in the text | |||
| line: The line of the token in the text (starting with 1) | |||
| column: The column of the token in the text (starting with 1) | |||
| end_line: The line where the token ends | |||
| end_column: The next column after the end of the token. For example, | |||
| if the token is a single character with a column value of 4, | |||
| end_column will be 5. | |||
| end_pos: the index where the token ends (basically ``pos_in_stream + len(token)``) | |||
| end_pos: the index where the token ends (basically ``start_pos + len(token)``) | |||
| """ | |||
| __slots__ = ('type', 'start_pos', 'value', 'line', 'column', 'end_line', 'end_column', 'end_pos') | |||
| def __new__(cls, type_, value, start_pos=None, line=None, column=None, end_line=None, end_column=None, end_pos=None, pos_in_stream=None): | |||
| def __new__(cls, type_, value, start_pos=None, line=None, column=None, end_line=None, end_column=None, end_pos=None): | |||
| try: | |||
| self = super(Token, cls).__new__(cls, value) | |||
| except UnicodeDecodeError: | |||
| @@ -140,7 +139,7 @@ class Token(str): | |||
| self = super(Token, cls).__new__(cls, value) | |||
| self.type = type_ | |||
| self.start_pos = start_pos if start_pos is not None else pos_in_stream | |||
| self.start_pos = start_pos | |||
| self.value = value | |||
| self.line = line | |||
| self.column = column | |||
| @@ -149,11 +148,6 @@ class Token(str): | |||
| self.end_pos = end_pos | |||
| return self | |||
| @property | |||
| def pos_in_stream(self): | |||
| warn("Attribute Token.pos_in_stream was renamed to Token.start_pos", DeprecationWarning) | |||
| return self.start_pos | |||
| def update(self, type_=None, value=None): | |||
| return Token.new_borrow_pos( | |||
| type_ if type_ is not None else self.type, | |||
| @@ -1,7 +1,6 @@ | |||
| from .exceptions import GrammarError, ConfigurationError | |||
| from .lexer import Token | |||
| from .tree import Tree | |||
| from .visitors import InlineTransformer # XXX Deprecated | |||
| from .visitors import Transformer_InPlace | |||
| from .visitors import _vargs_meta, _vargs_meta_inline | |||
| @@ -297,12 +296,6 @@ class AmbiguousIntermediateExpander: | |||
| return self.node_builder(children) | |||
| def ptb_inline_args(func): | |||
| @wraps(func) | |||
| def f(children): | |||
| return func(*children) | |||
| return f | |||
| def inplace_transformer(func): | |||
| @wraps(func) | |||
| @@ -358,15 +351,11 @@ class ParseTreeBuilder: | |||
| user_callback_name = rule.alias or rule.options.template_source or rule.origin.name | |||
| try: | |||
| f = getattr(transformer, user_callback_name) | |||
| # XXX InlineTransformer is deprecated! | |||
| wrapper = getattr(f, 'visit_wrapper', None) | |||
| if wrapper is not None: | |||
| f = apply_visit_wrapper(f, user_callback_name, wrapper) | |||
| else: | |||
| if isinstance(transformer, InlineTransformer): | |||
| f = ptb_inline_args(f) | |||
| elif isinstance(transformer, Transformer_InPlace): | |||
| f = inplace_transformer(f) | |||
| elif isinstance(transformer, Transformer_InPlace): | |||
| f = inplace_transformer(f) | |||
| except AttributeError: | |||
| f = partial(self.tree_class, user_callback_name) | |||
| @@ -126,7 +126,3 @@ class ImmutableInteractiveParser(InteractiveParser): | |||
| p = copy(self) | |||
| return InteractiveParser(p.parser, p.parser_state, p.lexer_state) | |||
| # Deprecated class names for the interactive parser | |||
| ParserPuppet = InteractiveParser | |||
| ImmutableParserPuppet = ImmutableInteractiveParser | |||
| @@ -1,3 +0,0 @@ | |||
| # Deprecated | |||
| from .lalr_interactive_parser import ParserPuppet, ImmutableParserPuppet | |||
| @@ -6,7 +6,7 @@ import codecs | |||
| import argparse | |||
| from lark import Lark, InlineTransformer | |||
| from lark import Lark, Transformer, v_args | |||
| nearley_grammar = r""" | |||
| start: (ruledef|directive)+ | |||
| @@ -50,7 +50,8 @@ def _get_rulename(name): | |||
| name = {'_': '_ws_maybe', '__':'_ws'}.get(name, name) | |||
| return 'n_' + name.replace('$', '__DOLLAR__').lower() | |||
| class NearleyToLark(InlineTransformer): | |||
| @v_args(inline=True) | |||
| class NearleyToLark(Transformer): | |||
| def __init__(self): | |||
| self._count = 0 | |||
| self.extra_rules = {} | |||
| @@ -37,7 +37,6 @@ from os import path | |||
| from collections import defaultdict | |||
| from functools import partial | |||
| from argparse import ArgumentParser, SUPPRESS | |||
| from warnings import warn | |||
| import lark | |||
| from lark import Lark | |||
| @@ -119,11 +118,6 @@ def strip_docstrings(line_gen): | |||
| return ''.join(res) | |||
| def main(fobj, start, print=print): | |||
| warn('`lark.tools.standalone.main` is being redesigned. Use `gen_standalone`', DeprecationWarning) | |||
| lark_inst = Lark(fobj, parser="lalr", lexer="contextual", start=start) | |||
| gen_standalone(lark_inst, print) | |||
| def gen_standalone(lark_inst, output=None, out=sys.stdout, compress=False): | |||
| if output is None: | |||
| output = partial(print, file=out) | |||
| @@ -186,9 +180,6 @@ def main(): | |||
| parser.print_help(sys.stderr) | |||
| sys.exit(1) | |||
| ns = parser.parse_args() | |||
| if ns.old_start is not None: | |||
| warn('The syntax `python -m lark.tools.standalone <grammar-file> <start>` is deprecated. Use the -s option') | |||
| ns.start.append(ns.old_start) | |||
| lark_inst, out = build_lalr(ns) | |||
| gen_standalone(lark_inst, out=out, compress=ns.compress) | |||
| @@ -147,22 +147,6 @@ class Tree(object): | |||
| self.data = data | |||
| self.children = children | |||
| # XXX Deprecated! Here for backwards compatibility <0.6.0 | |||
| @property | |||
| def line(self): | |||
| return self.meta.line | |||
| @property | |||
| def column(self): | |||
| return self.meta.column | |||
| @property | |||
| def end_line(self): | |||
| return self.meta.end_line | |||
| @property | |||
| def end_column(self): | |||
| return self.meta.end_column | |||
| class SlottedTree(Tree): | |||
| @@ -149,18 +149,6 @@ class Transformer(_Decoratable): | |||
| return token | |||
| class InlineTransformer(Transformer): # XXX Deprecated | |||
| def _call_userfunc(self, tree, new_children=None): | |||
| # Assumes tree is already transformed | |||
| children = new_children if new_children is not None else tree.children | |||
| try: | |||
| f = getattr(self, tree.data) | |||
| except AttributeError: | |||
| return self.__default__(tree.data, children, tree.meta) | |||
| else: | |||
| return f(*children) | |||
| class TransformerChain(object): | |||
| def __init__(self, *transformers): | |||
| self.transformers = transformers | |||
| @@ -363,10 +351,6 @@ def _inline_args__func(func): | |||
| return smart_decorator(func, create_decorator) | |||
| def inline_args(obj): # XXX Deprecated | |||
| return _apply_decorator(obj, _inline_args__func) | |||
| def _visitor_args_func_dec(func, visit_wrapper=None, static=False): | |||
| def create_decorator(_f, with_self): | |||
| if with_self: | |||