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

Labels with contractions fail to render #8

Open
mdiasdev opened this issue Apr 4, 2018 · 3 comments
Open

Labels with contractions fail to render #8

mdiasdev opened this issue Apr 4, 2018 · 3 comments

Comments

@mdiasdev
Copy link

mdiasdev commented Apr 4, 2018

If a UILabel has text that contains an apostrophe the parser fails with:

UNEXPECTED INPUT:
...
EXPECTED:
']'

Example:

(
    "<NSLayoutConstraint:0x600000688070 UIView:0x7fcae969d920.height == 50   (active)>",
    "<NSLayoutConstraint:0x600000688700 V:[MyApp.UIButton:0x7fcae969f500'No Thanks']-(0)-|   (active, names: '|':UIView:0x7fcae969f320 )>",
    "<NSLayoutConstraint:0x6000006887a0 V:|-(0)-[MyApp.UIButton:0x7fcae969f500'No Thanks']   (active, names: '|':UIView:0x7fcae969f320 )>",
    "<NSLayoutConstraint:0x600000688b10 V:|-(10)-[MyApp.UILabel:0x7fcae969ece0'Keep track of your friend's ...']   (active, names: '|':UIView:0x7fcae969eb00 )>",
    "<NSLayoutConstraint:0x600000688bb0 V:[MyApp.UILabel:0x7fcae969ece0'Keep track of your friend's ...']-(15)-[UIView:0x7fcae969f320]   (active)>",
    "<NSLayoutConstraint:0x600000688c00 V:[UIView:0x7fcae969f320]-(15)-|   (active, names: '|':UIView:0x7fcae969eb00 )>",
    "<NSLayoutConstraint:0x600000688e80 V:[UIStackView:0x7fcae969d720]-(0)-|   (active, names: '|':UITableViewCellContentView:0x7fcae969d530 )>",
    "<NSLayoutConstraint:0x600000688f20 V:|-(0)-[UIStackView:0x7fcae969d720]   (active, names: '|':UITableViewCellContentView:0x7fcae969d530 )>",
    "<NSLayoutConstraint:0x600000688f70 'UISV-canvas-connection' UIStackView:0x7fcae969d720.top == UIView:0x7fcae969d920.top   (active)>",
    "<NSLayoutConstraint:0x600000689060 'UISV-canvas-connection' V:[UIView:0x7fcae969eb00]-(0)-|   (active, names: '|':UIStackView:0x7fcae969d720 )>",
    "<NSLayoutConstraint:0x6000006890b0 'UISV-spacing' V:[UIView:0x7fcae969d920]-(0)-[UIView:0x7fcae969eb00]   (active)>",
    "<NSLayoutConstraint:0x60400048fd20 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fcae969d530.height == 50   (active)>"
)

if you change friend's to friends the parser is again able to handle the input

@johnpatrickmorgan
Copy link
Owner

Thanks for raising this issue. This relates to the identifier parser in ConstraintsParser+Instances.swift:

static let identifier = many(identifierCharacter.butNot(sqm), boundedBy: sqm).asString()

Currently it does not allow single-quote marks, which stops it from greedily consuming the whole line as an identifier. It will be a challenge to address this issue within the current limitations of the parsing framework, especially to avoid unrelated errors being reported as bad identifiers (since the framework reports the error furthest along the input stream).

I'll mark this as an enhancement, and give it some thought. Thanks again.

@mdiasdev
Copy link
Author

mdiasdev commented Apr 5, 2018

Thanks @johnpatrickmorgan, that sounds great! Is it possible to detect that there's an odd number of apostrophes and update the error message to reflect that as a short-term fix? Admittedly I have not looked through the source code -- so I don't know if it's possible -- just trying to offer some potential help for other developers scratching their heads as I was yesterday

@johnpatrickmorgan
Copy link
Owner

Thanks, yes that seems like a good short-term approach. As an aside, I think U+2019 is the preferred character for possessive apostrophes, which would avoid the issue in this case at least.

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

No branches or pull requests

2 participants