Skip to content

Commit

Permalink
Escape token, tokens and keyword, issue cesbit#16
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen van der Heijden committed Dec 1, 2020
1 parent a81ecf6 commit 4faf9fb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pyleri/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
__author__ = 'Jeroen van der Heijden'
__maintainer__ = 'Jeroen van der Heijden'
__email__ = '[email protected]'
__version__ = '1.3.2'
__version__ = '1.3.3'
10 changes: 5 additions & 5 deletions pyleri/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,32 @@ def _get_node_result(self, root, tree, rule, s, node):

def _run_export_js(self, js_indent, indent, classes, cname):
return 'Keyword(\'{}\'{})'.format(
self._keyword,
self._keyword.replace('\'', '\\\''),
', true' if self._ign_case else '')

def _run_export_py(self, py_indent, indent, classes):
return 'Keyword(\'{}\'{})'.format(
self._keyword,
self._keyword.replace('\'', '\\\''),
', True' if self._ign_case else '')

@c_export
def _run_export_c(self, c_indent, indent, enums, gid):
return 'cleri_keyword({}, "{}", {})'.format(
gid,
self._keyword,
self._keyword.replace('"', '\\"'),
'CLERI_CASE_INSENSITIVE'
if self._ign_case else 'CLERI_CASE_SENSITIVE')

@go_export
def _run_export_go(self, go_indent, indent, enums, gid):
return 'goleri.NewKeyword({}, "{}", {})'.format(
gid,
self._keyword,
self._keyword.replace('"', '\\"'),
'true' if self._ign_case else 'false')

@java_export
def _run_export_java(self, c_indent, indent, enums, classes, gid):
return 'new Keyword({}"{}", {})'.format(
'' if gid is None else 'Ids.{}, '.format(gid),
self._keyword,
self._keyword.replace('"', '\\"'),
'true' if self._ign_case else 'false')
10 changes: 5 additions & 5 deletions pyleri/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ def _get_node_result(self, root, tree, rule, s, node):
return is_valid, node.end or node.start

def _run_export_js(self, js_indent, indent, classes, cname):
return 'Token(\'{}\')'.format(self._token)
return 'Token(\'{}\')'.format(self._token.replace('\'', '\\\''))

def _run_export_py(self, py_indent, indent, classes):
return 'Token(\'{}\')'.format(self._token)
return 'Token(\'{}\')'.format(self._token.replace('\'', '\\\''))

@c_export
def _run_export_c(self, js_indent, indent, enums, gid):
return 'cleri_token({}, "{}")'.format(
gid,
self._token)
self._token.replace('"', '\\"'))

@go_export
def _run_export_go(self, go_indent, indent, enums, gid):
return 'goleri.NewToken({}, "{}")'.format(
gid,
self._token)
self._token.replace('"', '\\"'))

@java_export
def _run_export_java(self, java_indent, indent, enums, classes, gid):
return 'new Token({}"{}")'.format(
'' if gid is None else 'Ids.{}, '.format(gid),
self._token)
self._token.replace('"', '\\"'))
12 changes: 7 additions & 5 deletions pyleri/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,27 @@ def _get_node_result(self, root, tree, rule, s, node):
return False, node.start

def _run_export_js(self, js_indent, indent, classes, cname):
return 'Tokens(\'{}\')'.format(' '.join(self._tokens))
return 'Tokens(\'{}\')'.format(
' '.join(self._tokens).replace('\'', '\\\''))

def _run_export_py(self, py_indent, indent, classes):
return 'Tokens(\'{}\')'.format(' '.join(self._tokens))
return 'Tokens(\'{}\')'.format(
' '.join(self._tokens).replace('\'', '\\\''))

@c_export
def _run_export_c(self, c_indent, indent, enums, gid):
return 'cleri_tokens({}, "{}")'.format(
gid,
' '.join(self._tokens))
' '.join(self._tokens).replace('"', '\\"'))

@go_export
def _run_export_go(self, go_indent, indent, enums, gid):
return 'goleri.NewTokens({}, "{}")'.format(
gid,
' '.join(self._tokens))
' '.join(self._tokens).replace('"', '\\"'))

@java_export
def _run_export_java(self, java_indent, indent, enums, classes, gid):
return 'new Tokens({}"{}")'.format(
'' if gid is None else 'Ids.{}, '.format(gid),
' '.join(self._tokens))
' '.join(self._tokens).replace('"', '\\"'))
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
python3 setup.py sdist
twine upload --repository pypitest dist/pyleri-x.x.x.tar.gz
twine upload --repository pypi dist/pyleri-x.x.x.tar.gz
"""
from setuptools import setup
from pyleri import __version__ as version
Expand Down

0 comments on commit 4faf9fb

Please sign in to comment.