Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Commit

Permalink
Use more consistent names for regex constants
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Nov 30, 2016
1 parent 9bf6329 commit 16e91d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions hamlpy/parser/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
from .generic import consume_whitespace, read_symbol, read_number, read_quoted_string, STRING_LITERALS, ParseException

ATTRIBUTE_KEY_REGEX = regex.compile(r'[a-zA-Z0-9-_]+')

re_whitespace = regex.compile(r'([ \t]+)')
re_leading_spaces = regex.compile(r'^\s+', regex.MULTILINE)
re_line = regex.compile(r'.*')
WHITESPACE_REGEX = regex.compile(r'([ \t]+)')
LEADING_SPACES_REGEX = regex.compile(r'^\s+', regex.MULTILINE)
LINE_REGEX = regex.compile(r'.*')


def read_attribute_key(stream):
Expand Down Expand Up @@ -84,22 +83,22 @@ def read_attribute_value_haml(stream):
Reads an attribute value which is a block of indented HAML
"""
def whitespace_length():
r = re_whitespace.match(stream.text, pos=stream.ptr)
r = WHITESPACE_REGEX.match(stream.text, pos=stream.ptr)
return len(r.group(0))

initial_indentation = whitespace_length()
lines = []

while whitespace_length() >= initial_indentation:
line = re_line.match(stream.text, pos=stream.ptr).group(0)
line = LINE_REGEX.match(stream.text, pos=stream.ptr).group(0)
lines.append(line)
stream.ptr += len(line) + 1

stream.ptr -= 1 # un-consume final newline which will act as separator between this and next entry

from ..hamlpy import Compiler
html = Compiler().process_lines(lines)
return regex.sub(re_leading_spaces, ' ', html).replace('\n', '').strip()
return regex.sub(LEADING_SPACES_REGEX, ' ', html).replace('\n', '').strip()


def read_attribute(stream, assignment_symbols, entry_separator, terminator):
Expand Down
2 changes: 1 addition & 1 deletion hamlpy/parser/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, message, stream):

class Stream(object):
def __init__(self, text):
self.text = text.strip()
self.text = text
self.length = len(self.text)
self.ptr = 0

Expand Down

0 comments on commit 16e91d8

Please sign in to comment.