How to use the coconut.parser.CoconutSyntaxError function in coconut

To help you get started, we’ve selected a few coconut examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github evhub / coconut / coconut / parser.py View on Github external
current = check
                    line = openstr+line
                elif check in levels:
                    point = levels.index(check)+1
                    line = closestr*(len(levels[point:])+1)+line
                    levels = levels[:point]
                    current = levels.pop()
                elif current != check:
                    raise CoconutSyntaxError("illegal dedent to unused indentation level", line, 0, self.adjust(ln))
                new.append(line)
            count += self.change(line)
        self.skips = skips
        if new:
            last = new[-1].split("#", 1)[0].rstrip()
            if last.endswith("\\"):
                raise CoconutSyntaxError("illegal final backslash continuation", last, len(last), self.adjust(len(new)))
            if count != 0:
                raise CoconutSyntaxError("unclosed parenthetical", new[-1], len(new[-1]), self.adjust(len(new)))
        new.append(closestr*len(levels))
        return linebreak.join(new)
github evhub / coconut / coconut / parser.py View on Github external
if current is None:
                    if check:
                        raise CoconutSyntaxError("illegal initial indent", line, 0, self.adjust(ln))
                    else:
                        current = 0
                elif check > current:
                    levels.append(current)
                    current = check
                    line = openstr+line
                elif check in levels:
                    point = levels.index(check)+1
                    line = closestr*(len(levels[point:])+1)+line
                    levels = levels[:point]
                    current = levels.pop()
                elif current != check:
                    raise CoconutSyntaxError("illegal dedent to unused indentation level", line, 0, self.adjust(ln))
                new.append(line)
            count += self.change(line)
        self.skips = skips
        if new:
            last = new[-1].split("#", 1)[0].rstrip()
            if last.endswith("\\"):
                raise CoconutSyntaxError("illegal final backslash continuation", last, len(last), self.adjust(len(new)))
            if count != 0:
                raise CoconutSyntaxError("unclosed parenthetical", new[-1], len(new[-1]), self.adjust(len(new)))
        new.append(closestr*len(levels))
        return linebreak.join(new)
github evhub / coconut / coconut / parser.py View on Github external
self.value += "^"

class CoconutParseError(CoconutSyntaxError):
    """Coconut ParseError."""
    def __init__(self, line, col, ln):
        """Creates The Coconut ParseError."""
        super(CoconutParseError, self).__init__("parsing failed", line, col-1, ln)

class CoconutStyleError(CoconutSyntaxError):
    """Coconut --strict error."""
    def __init__(self, message, source, point=None, ln=None):
        """Creates the --strict Coconut error."""
        message += " (disable --strict to dismiss)"
        super(CoconutStyleError, self).__init__(message, source, point, ln)

class CoconutTargetError(CoconutSyntaxError):
    """Coconut --target error."""
    def __init__(self, message, source, point=None, ln=None):
        """Creates the --target Coconut error."""
        message += " (enable --target 3 to dismiss)"
        super(CoconutTargetError, self).__init__(message, source, point, ln)

def attach(item, action):
    """Attaches a parse action to an item."""
    return item.copy().addParseAction(action)

def fixto(item, output):
    """Forces an item to result in a specific output."""
    return attach(item, replaceWith(output))

def addspace(item):
    """Condenses and adds space to the tokenized output."""
github evhub / coconut / coconut / parser.py View on Github external
c = inputstring[x]
            if hold is not None:
                if len(hold) == 1: # [_comment]
                    if c == linebreak:
                        out.append(self.wrap_comment(hold[_comment])+c)
                        hold = None
                    else:
                        hold[_comment] += c
                elif hold[_store] is not None:
                    if c == escape:
                        hold[_contents] += hold[_store]+c
                        hold[_store] = None
                    elif c == hold[_start][0]:
                        hold[_store] += c
                    elif len(hold[_store]) > len(hold[_start]):
                        raise CoconutSyntaxError("invalid number of string closes", inputstring, x, self.adjust(lineno(x, inputstring)))
                    elif hold[_store] == hold[_start]:
                        out.append(self.wrap_str(hold[_contents], hold[_start][0], True))
                        hold = None
                        x -= 1
                    else:
                        if c == linebreak:
                            if len(hold[_start]) == 1:
                                raise CoconutSyntaxError("linebreak in non-multiline string", inputstring, x, self.adjust(lineno(x, inputstring)))
                            else:
                                skips = addskip(skips, self.adjust(lineno(x, inputstring)))
                        hold[_contents] += hold[_store]+c
                        hold[_store] = None
                elif hold[_contents].endswith(escape) and not hold[_contents].endswith(escape*2):
                    if c == linebreak:
                        skips = addskip(skips, self.adjust(lineno(x, inputstring)))
                    hold[_contents] += c
github evhub / coconut / coconut / parser.py View on Github external
elif len(found) == 3: # "___"
                    if c == linebreak:
                        skips = addskip(skips, self.adjust(lineno(x, inputstring)))
                    hold = [c, found, None] # [_contents, _start, _store]
                    found = None
                else:
                    raise CoconutSyntaxError("invalid number of string starts", inputstring, x, self.adjust(lineno(x, inputstring)))
            elif c == "#":
                hold = [""] # [_comment]
            elif c in holds:
                found = c
            else:
                out.append(c)
            x += 1
        if hold is not None or found is not None:
            raise CoconutSyntaxError("unclosed string", inputstring, x, self.adjust(lineno(x, inputstring)))
        else:
            self.skips = skips
            return "".join(out)
github evhub / coconut / coconut / parser.py View on Github external
self.value += " (line " + str(ln) + ")"
        if point is None:
            self.value += linebreak + "  " + clean(source)
        else:
            if point >= len(source):
                point = len(source)-1
            part = clean(source.splitlines()[lineno(point, source)-1])
            self.value += linebreak + "  " + part + linebreak + "  "
            for x in range(0, col(point, source)-1):
                if part[x] in white:
                    self.value += part[x]
                else:
                    self.value += " "
            self.value += "^"

class CoconutParseError(CoconutSyntaxError):
    """Coconut ParseError."""
    def __init__(self, line, col, ln):
        """Creates The Coconut ParseError."""
        super(CoconutParseError, self).__init__("parsing failed", line, col-1, ln)

class CoconutStyleError(CoconutSyntaxError):
    """Coconut --strict error."""
    def __init__(self, message, source, point=None, ln=None):
        """Creates the --strict Coconut error."""
        message += " (disable --strict to dismiss)"
        super(CoconutStyleError, self).__init__(message, source, point, ln)

class CoconutTargetError(CoconutSyntaxError):
    """Coconut --target error."""
    def __init__(self, message, source, point=None, ln=None):
        """Creates the --target Coconut error."""
github evhub / coconut / coconut / parser.py View on Github external
else:
                    skips = addskip(skips, self.adjust(ln))
            elif last is not None and last.endswith("\\"):
                if self.strict:
                    raise CoconutStyleError("found backslash continuation", last, len(last), self.adjust(ln-1))
                else:
                    skips = addskip(skips, self.adjust(ln))
                    new[-1] = last[:-1]+" "+line
            elif count < 0:
                skips = addskip(skips, self.adjust(ln))
                new[-1] = last+" "+line
            else:
                check = self.leading(line)
                if current is None:
                    if check:
                        raise CoconutSyntaxError("illegal initial indent", line, 0, self.adjust(ln))
                    else:
                        current = 0
                elif check > current:
                    levels.append(current)
                    current = check
                    line = openstr+line
                elif check in levels:
                    point = levels.index(check)+1
                    line = closestr*(len(levels[point:])+1)+line
                    levels = levels[:point]
                    current = levels.pop()
                elif current != check:
                    raise CoconutSyntaxError("illegal dedent to unused indentation level", line, 0, self.adjust(ln))
                new.append(line)
            count += self.change(line)
        self.skips = skips
github evhub / coconut / coconut / parser.py View on Github external
part = clean(source.splitlines()[lineno(point, source)-1])
            self.value += linebreak + "  " + part + linebreak + "  "
            for x in range(0, col(point, source)-1):
                if part[x] in white:
                    self.value += part[x]
                else:
                    self.value += " "
            self.value += "^"

class CoconutParseError(CoconutSyntaxError):
    """Coconut ParseError."""
    def __init__(self, line, col, ln):
        """Creates The Coconut ParseError."""
        super(CoconutParseError, self).__init__("parsing failed", line, col-1, ln)

class CoconutStyleError(CoconutSyntaxError):
    """Coconut --strict error."""
    def __init__(self, message, source, point=None, ln=None):
        """Creates the --strict Coconut error."""
        message += " (disable --strict to dismiss)"
        super(CoconutStyleError, self).__init__(message, source, point, ln)

class CoconutTargetError(CoconutSyntaxError):
    """Coconut --target error."""
    def __init__(self, message, source, point=None, ln=None):
        """Creates the --target Coconut error."""
        message += " (enable --target 3 to dismiss)"
        super(CoconutTargetError, self).__init__(message, source, point, ln)

def attach(item, action):
    """Attaches a parse action to an item."""
    return item.copy().addParseAction(action)