Skip to content

Commit

Permalink
Fix parsing token components with parenthesis without spaces (#254)
Browse files Browse the repository at this point in the history
* fix parsing token components with brackets without spaces

* handle more edge cases

* do not use force unwrap

* use first/last instead of hasPrefix/hasSuffix

* update CHANGELOG
  • Loading branch information
ilyapuchka authored Sep 30, 2018
1 parent d9f6a82 commit 01afae9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ _None_

### Bug Fixes

_None_
- Fixed using parenthesis in boolean expressions, they now can be used without spaces around them.
[Ilya Puchka](https://github.com/ilyapuchka)
[#254](https://github.com/stencilproject/Stencil/pull/254)

### Internal Changes

Expand Down
6 changes: 6 additions & 0 deletions Sources/Tokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ extension String {
components[components.count-1] += word
} else if specialCharacters.contains(word) {
components[components.count-1] += word
} else if word != "(" && word.first == "(" || word != ")" && word.first == ")" {
components.append(String(word.prefix(1)))
appendWord(String(word.dropFirst()))
} else if word != "(" && word.last == "(" || word != ")" && word.last == ")" {
appendWord(String(word.dropLast()))
components.append(String(word.suffix(1)))
} else {
components.append(word)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/StencilTests/IfNodeSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class IfNodeTests: XCTestCase {

$0.it("can parse an if with complex expression") {
let tokens: [Token] = [
.block(value: "if value == \"test\" and not name", at: .unknown),
.block(value: "if value == \"test\" and (not name or not (name and surname) or( some )and other )", at: .unknown),
.text(value: "true", at: .unknown),
.block(value: "endif", at: .unknown)
]
Expand Down

0 comments on commit 01afae9

Please sign in to comment.