Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rejects block comments with content after special character #161

Closed
krivard opened this issue Oct 26, 2022 · 2 comments
Closed

Rejects block comments with content after special character #161

krivard opened this issue Oct 26, 2022 · 2 comments
Assignees

Comments

@krivard
Copy link

krivard commented Oct 26, 2022

Describe the bug
Block comments can end with a special character (any of |&?;) but if you put anything after the special character it crashes with

Traceback (most recent call last):
  File "env/bin/sdp", line 8, in <module>
    sys.exit(main())
  File "env/lib/python3.9/site-packages/simple_ddl_parser/cli.py", line 75, in main
    run_for_file(args)
  File "env/lib/python3.9/site-packages/simple_ddl_parser/cli.py", line 44, in run_for_file
    result = parse_from_file(
  File "env/lib/python3.9/site-packages/simple_ddl_parser/ddl_parser.py", line 232, in parse_from_file
    return DDLParser(df.read()).run(file_path=file_path, **kwargs)
  File "env/lib/python3.9/site-packages/simple_ddl_parser/parser.py", line 302, in run
    self.tables = self.parse_data()
  File "env/lib/python3.9/site-packages/simple_ddl_parser/parser.py", line 215, in parse_data
    self.process_line(num != len(lines) - 1)
  File "env/lib/python3.9/site-packages/simple_ddl_parser/parser.py", line 245, in process_line
    self.process_statement()
  File "env/lib/python3.9/site-packages/simple_ddl_parser/parser.py", line 249, in process_statement
    self.parse_statement()
  File "env/lib/python3.9/site-packages/simple_ddl_parser/parser.py", line 257, in parse_statement
    _parse_result = yacc.parse(self.statement)
  File "env/lib/python3.9/site-packages/ply/yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "env/lib/python3.9/site-packages/ply/yacc.py", line 1063, in parseopt_notrack
    lookahead = get_token()     # Get the next token
  File "env/lib/python3.9/site-packages/ply/lex.py", line 386, in token
    newtok = self.lexerrorf(tok)
  File "env/lib/python3.9/site-packages/simple_ddl_parser/ddl_parser.py", line 222, in t_error
    raise DDLParserError("Unknown symbol %r" % (t.value[0],))
simple_ddl_parser.ddl_parser.DDLParserError: Unknown symbol '|'

To Reproduce
Steps to reproduce the behavior:

Succeeds:

/* 
xyz|
*/

CREATE TABLE `test` (
  `id` INT NOT NULL AUTO_INCREMENT
);

Fails:

/* 
|xyz
*/

CREATE TABLE `test` (
  `id` INT NOT NULL AUTO_INCREMENT
);

Expected behavior
Position of |&?; characters within a block comment should not affect whether the file parses or not

Additional context

  • Python v3.9.6
  • sdp v0.27.0
  • ply v3.11
@xnuinside
Copy link
Owner

@krivard hi! thanks for opening the issue, I will release the fix on Sunday

@xnuinside xnuinside self-assigned this Oct 30, 2022
@xnuinside
Copy link
Owner

@krivard I just released version 0.28.0 with fix, now your sample will be parsed validly & produces resul:

{'comments': [' ', 'xyz|'], 'ddl_properties': [], 'domains': [], 'schemas': [], 'sequences': [], 'tables': [{'alter': {}, 'checks': [], 'columns': [{'autoincrement': True, 'check': None, 'default': None, 'name': 'id', 'nullable': False, 'references': None, 'size': None, 'type': 'INT', 'unique': False}], 'index': [], 'partitioned_by': [], 'primary_key': [], 'schema': None, 'table_name': 'test', 'tablespace': None}], 'types': []}

if you want to remove '' symbols near names, you can run parser with setting 'normalize_names=True' like: DDLParser(
"""/*
xyz|
*/

CREATE TABLE test (
id INT NOT NULL AUTO_INCREMENT
);
""", normalize_names=True).run(group_by_type=True)`

if will be any issues - feel free to open new. And thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants