diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 12f40c0..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "vendor/CoreParse"] - path = vendor/CoreParse - url = https://github.com/beelsebob/CoreParse.git diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3212e0a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +rvm: 2.2.3 +language: objective-c +before_script: + - export LANG=en_US.UTF-8 + - gem install xcpretty cocoapods + - pod install +script: xcodebuild -workspace CSSSelectorConverter.xcworkspace -scheme CSSSelectorConverter -sdk iphonesimulator test | xcpretty -c; exit ${PIPESTATUS[0]} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..df37db5 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,28 @@ +Changelog +--------- + +1.2.1 +----- + +- Added [CSSSelectorToXPathConverter sharedConverter]. + +1.2.0 +----- + +- Update podspec to only expose minimal files. + +1.1.2 +----- + +- Use NUIParse. + +1.1.0 (28/01/2014) +------------------ + +- Fix #1, properly handle selector sequence. +* Use [CoreParse](https://github.com/beelsebob/CoreParse) instead of [ParseKit](https://github.com/itod/parsekit) as parser generator. + +1.0.0 (09/01/2014) +-------------- + ++ Initial version. \ No newline at end of file diff --git a/CSSSelectorConverter.podspec b/CSSSelectorConverter.podspec index 3df04d3..27d9fa6 100644 --- a/CSSSelectorConverter.podspec +++ b/CSSSelectorConverter.podspec @@ -1,25 +1,27 @@ Pod::Spec.new do |s| s.name = 'CSSSelectorConverter' - s.version = '1.0.0' + s.version = '1.2.3' s.license = 'MIT' s.summary = 'Objective-C/Cocoa String Tokenizer and Parser toolkit. Supports Grammars.' - s.homepage = 'https://github.com/siuying/CSSToXPathConverter' + s.homepage = 'https://github.com/siuying/CSSSelectorConverter' s.author = { 'Francis Chong' => 'francis@ignition.hk' } - s.source = { :git => 'https://github.com/siuying/CSSSelectorConverter.git', :tag => '1.0.0'} + s.source = { :git => 'https://github.com/siuying/CSSSelectorConverter.git', :tag => s.version.to_s } s.description = %{ A CSS Selector to XPath Selector for Objective-C. Support mostly used subset of CSS Selector Level 3. } - s.source_files = 'CSSSelectorConverter/CSS*.{m,h}' - s.prefix_header_contents = "#import \"CSSSelectorConverter.h\"" - s.ios.deployment_target = '6.0' s.osx.deployment_target = '10.8' - s.dependency 'ParseKit', '~> 0.7' - s.dependency 'CocoaLumberjack', '>= 1.6.4' - s.library = 'icucore' - s.requires_arc = true -end \ No newline at end of file + s.dependency 'CocoaLumberjack', '~> 2.0.0' + s.dependency 'NUIParse' + s.requires_arc = true + + s.public_header_files = "CSSSelectorConverter/CSSSelectorConverter.h", "CSSSelectorConverter/CSSSelectorToXPathConverter.h" + s.source_files = 'CSSSelectorConverter/CSS*.{m,h}' + s.prefix_header_contents = "#import \"CSSSelectorConverter.h\"" + s.requires_arc = true + s.resources = ['CSSSelectorConverter/*.{txt}', 'CSSSelectorConverter/CSSSelectorParser.plist'] +end diff --git a/CSSSelectorConverter.xcodeproj/project.pbxproj b/CSSSelectorConverter.xcodeproj/project.pbxproj index 93bff64..6fdcadc 100644 --- a/CSSSelectorConverter.xcodeproj/project.pbxproj +++ b/CSSSelectorConverter.xcodeproj/project.pbxproj @@ -23,49 +23,31 @@ 540AA36F187BC5F70012AA44 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 540AA34B187BC5F60012AA44 /* Foundation.framework */; }; 540AA370187BC5F70012AA44 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 540AA34F187BC5F60012AA44 /* UIKit.framework */; }; 540AA378187BC5F70012AA44 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 540AA376187BC5F70012AA44 /* InfoPlist.strings */; }; - 541971F1188ED2A3004240B4 /* libCoreParse.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 541971ED188ED293004240B4 /* libCoreParse.a */; }; - 541971F2188ED36A004240B4 /* libCoreParse.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 541971ED188ED293004240B4 /* libCoreParse.a */; }; 5419722F188FB97E004240B4 /* CSSSelectorXPathVisitor.m in Sources */ = {isa = PBXBuildFile; fileRef = 5419722E188FB97E004240B4 /* CSSSelectorXPathVisitor.m */; }; 54197231188FBAF0004240B4 /* CSSSelectorXPathVisitorSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 54197230188FBAF0004240B4 /* CSSSelectorXPathVisitorSpec.m */; }; - 54197232188FBBA6004240B4 /* CSSSelectorXPathVisitor.m in Sources */ = {isa = PBXBuildFile; fileRef = 5419722E188FB97E004240B4 /* CSSSelectorXPathVisitor.m */; }; 5433BA57188D0C5B006C5F59 /* CSSSelectorTokeniser.m in Sources */ = {isa = PBXBuildFile; fileRef = 5433BA56188D0C5B006C5F59 /* CSSSelectorTokeniser.m */; }; - 5433BA58188D0C5B006C5F59 /* CSSSelectorTokeniser.m in Sources */ = {isa = PBXBuildFile; fileRef = 5433BA56188D0C5B006C5F59 /* CSSSelectorTokeniser.m */; }; 5433BA5B188D0D71006C5F59 /* CSSSelectorTokeniserSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5433BA59188D0D71006C5F59 /* CSSSelectorTokeniserSpec.m */; }; 5433BA5E188D136A006C5F59 /* CSSSelectorGrammar.m in Sources */ = {isa = PBXBuildFile; fileRef = 5433BA5D188D136A006C5F59 /* CSSSelectorGrammar.m */; }; - 5433BA5F188D136A006C5F59 /* CSSSelectorGrammar.m in Sources */ = {isa = PBXBuildFile; fileRef = 5433BA5D188D136A006C5F59 /* CSSSelectorGrammar.m */; }; 5433BA61188D1450006C5F59 /* CSSSelectorGrammar.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5433BA60188D1450006C5F59 /* CSSSelectorGrammar.txt */; }; 5433BA63188D1629006C5F59 /* CSSSelectorParserSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5433BA62188D1629006C5F59 /* CSSSelectorParserSpec.m */; }; 5433BA64188D17CE006C5F59 /* CSSSelectorGrammar.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5433BA60188D1450006C5F59 /* CSSSelectorGrammar.txt */; }; - 5433BA65188D1807006C5F59 /* CSSUniversalSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3A1187BEF380012AA44 /* CSSUniversalSelector.m */; }; 5433BA66188D1808006C5F59 /* CSSUniversalSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3A1187BEF380012AA44 /* CSSUniversalSelector.m */; }; - 5433BA6D188D1905006C5F59 /* CSSBaseSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3B5187BF2D60012AA44 /* CSSBaseSelector.m */; }; - 5433BA6E188D1907006C5F59 /* CSSNamedSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3B1187BF1660012AA44 /* CSSNamedSelector.m */; }; 5433BA6F188D1940006C5F59 /* CSSNamedSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3B1187BF1660012AA44 /* CSSNamedSelector.m */; }; 5433BA70188D1949006C5F59 /* CSSBaseSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3B5187BF2D60012AA44 /* CSSBaseSelector.m */; }; - 5433BA71188D1D9C006C5F59 /* CSSTypeSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3A5187BEF8B0012AA44 /* CSSTypeSelector.m */; }; 5433BA72188D1D9E006C5F59 /* CSSTypeSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3A5187BEF8B0012AA44 /* CSSTypeSelector.m */; }; 54BC925B188E736000443230 /* CSSSelectors.m in Sources */ = {isa = PBXBuildFile; fileRef = 543F5AA6187C0A1D00F3CC22 /* CSSSelectors.m */; }; - 54BC925C188E736000443230 /* CSSSelectors.m in Sources */ = {isa = PBXBuildFile; fileRef = 543F5AA6187C0A1D00F3CC22 /* CSSSelectors.m */; }; 54BC925D188E770A00443230 /* CSSSelectorGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D62F26187D06150075A755 /* CSSSelectorGroup.m */; }; - 54BC925E188E770A00443230 /* CSSSelectorGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 54D62F26187D06150075A755 /* CSSSelectorGroup.m */; }; 54D41BAA188E7A9D00D8521A /* CSSPseudoClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 541EC707187D589000F08D19 /* CSSPseudoClass.m */; }; - 54D41BAB188E7A9D00D8521A /* CSSPseudoClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 541EC707187D589000F08D19 /* CSSPseudoClass.m */; }; - 54FA2F70188D76A90065B628 /* CSSClassSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3AD187BF1510012AA44 /* CSSClassSelector.m */; }; + 54ECE0CF1890F23500C2A4ED /* CSSSelectorParser.plist in Resources */ = {isa = PBXBuildFile; fileRef = 54ECE0CE1890F23500C2A4ED /* CSSSelectorParser.plist */; }; + 54ECE0D01890F23500C2A4ED /* CSSSelectorParser.plist in Resources */ = {isa = PBXBuildFile; fileRef = 54ECE0CE1890F23500C2A4ED /* CSSSelectorParser.plist */; }; 54FA2F71188D76AA0065B628 /* CSSClassSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3AD187BF1510012AA44 /* CSSClassSelector.m */; }; 54FA2F72188D7AEB0065B628 /* CSSSelectorParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA39C187BEE660012AA44 /* CSSSelectorParser.m */; }; - 54FA2F73188D7AEB0065B628 /* CSSSelectorParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA39C187BEE660012AA44 /* CSSSelectorParser.m */; }; 54FA2F74188D7C650065B628 /* CSSSelectorToXPathConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA397187BE4900012AA44 /* CSSSelectorToXPathConverter.m */; }; - 54FA2F75188D7C660065B628 /* CSSSelectorToXPathConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA397187BE4900012AA44 /* CSSSelectorToXPathConverter.m */; }; 54FA2F76188D7CDD0065B628 /* CSSToXPathConverterSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA388187BDD5B0012AA44 /* CSSToXPathConverterSpec.m */; }; 54FA2F79188D826F0065B628 /* CSSIDSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3A9187BF1460012AA44 /* CSSIDSelector.m */; }; - 54FA2F7A188D826F0065B628 /* CSSIDSelector.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3A9187BF1460012AA44 /* CSSIDSelector.m */; }; 54FA2F7D188D867F0065B628 /* CSSSelectorAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 548A92A0187D1CF70045D4CA /* CSSSelectorAttribute.m */; }; - 54FA2F7E188D867F0065B628 /* CSSSelectorAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 548A92A0187D1CF70045D4CA /* CSSSelectorAttribute.m */; }; - 54FA2F7F188D88B90065B628 /* CSSSelectorAttributeOperator.m in Sources */ = {isa = PBXBuildFile; fileRef = 541EC6FF187D34AB00F08D19 /* CSSSelectorAttributeOperator.m */; }; 54FA2F80188D88BA0065B628 /* CSSSelectorAttributeOperator.m in Sources */ = {isa = PBXBuildFile; fileRef = 541EC6FF187D34AB00F08D19 /* CSSSelectorAttributeOperator.m */; }; - 54FA2F81188D8E6C0065B628 /* CSSCombinator.m in Sources */ = {isa = PBXBuildFile; fileRef = 541EC703187D43A300F08D19 /* CSSCombinator.m */; }; 54FA2F82188D8E6C0065B628 /* CSSCombinator.m in Sources */ = {isa = PBXBuildFile; fileRef = 541EC703187D43A300F08D19 /* CSSCombinator.m */; }; - 54FA2F83188D8F610065B628 /* CSSSelectorSequence.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3B9187BF3630012AA44 /* CSSSelectorSequence.m */; }; 54FA2F84188D8F610065B628 /* CSSSelectorSequence.m in Sources */ = {isa = PBXBuildFile; fileRef = 540AA3B9187BF3630012AA44 /* CSSSelectorSequence.m */; }; /* End PBXBuildFile section */ @@ -77,45 +59,13 @@ remoteGlobalIDString = 540AA347187BC5F60012AA44; remoteInfo = CSSSelectorConverter; }; - 541971E6188ED293004240B4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 541971DE188ED293004240B4 /* CoreParse.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 1F0E88F6130462F300537D04; - remoteInfo = CoreParse; - }; - 541971E8188ED293004240B4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 541971DE188ED293004240B4 /* CoreParse.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 1F0E890B130462F300537D04; - remoteInfo = CoreParseTests; - }; - 541971EA188ED293004240B4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 541971DE188ED293004240B4 /* CoreParse.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 1FE77D821375EA8F00879A41; - remoteInfo = "CoreParse Documentation"; - }; - 541971EC188ED293004240B4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 541971DE188ED293004240B4 /* CoreParse.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 1F92817F145C11050033BC34; - remoteInfo = iOSCoreParse; - }; - 541971EE188ED293004240B4 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 541971DE188ED293004240B4 /* CoreParse.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 1F92818C145C11050033BC34; - remoteInfo = iOSCoreParseTests; - }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 120C8E845AC74187B385721E /* Pods-CSSSelectorConverterTests.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CSSSelectorConverterTests.xcconfig"; path = "Pods/Pods-CSSSelectorConverterTests.xcconfig"; sourceTree = ""; }; + 2FA369A0A3C034B1BA4E570B /* Pods-CSSSelectorConverterTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CSSSelectorConverterTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-CSSSelectorConverterTests/Pods-CSSSelectorConverterTests.release.xcconfig"; sourceTree = ""; }; + 31A43E848921BC4A334A76A7 /* Pods-CSSSelectorConverterTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CSSSelectorConverterTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CSSSelectorConverterTests/Pods-CSSSelectorConverterTests.debug.xcconfig"; sourceTree = ""; }; + 4654C27EDB914CB3303D3F76 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; + 48679CA62B498976F68DA0ED /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 540AA348187BC5F60012AA44 /* CSSSelectorConverter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CSSSelectorConverter.app; sourceTree = BUILT_PRODUCTS_DIR; }; 540AA34B187BC5F60012AA44 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 540AA34D187BC5F60012AA44 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -155,7 +105,6 @@ 540AA3B5187BF2D60012AA44 /* CSSBaseSelector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSBaseSelector.m; sourceTree = ""; }; 540AA3B8187BF3630012AA44 /* CSSSelectorSequence.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSSelectorSequence.h; sourceTree = ""; }; 540AA3B9187BF3630012AA44 /* CSSSelectorSequence.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSSelectorSequence.m; sourceTree = ""; }; - 541971DE188ED293004240B4 /* CoreParse.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = CoreParse.xcodeproj; path = vendor/CoreParse/CoreParse.xcodeproj; sourceTree = ""; }; 5419722D188FB97E004240B4 /* CSSSelectorXPathVisitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSSelectorXPathVisitor.h; sourceTree = ""; }; 5419722E188FB97E004240B4 /* CSSSelectorXPathVisitor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSSelectorXPathVisitor.m; sourceTree = ""; }; 54197230188FBAF0004240B4 /* CSSSelectorXPathVisitorSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSSelectorXPathVisitorSpec.m; sourceTree = ""; }; @@ -174,17 +123,16 @@ 5433BA62188D1629006C5F59 /* CSSSelectorParserSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSSelectorParserSpec.m; sourceTree = ""; }; 543F5AA5187C0A1D00F3CC22 /* CSSSelectors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSSelectors.h; sourceTree = ""; }; 543F5AA6187C0A1D00F3CC22 /* CSSSelectors.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSSelectors.m; sourceTree = ""; }; - 5454C0D3187D79AA005C034F /* CSSNthChild.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSNthChild.h; sourceTree = ""; }; - 5454C0D4187D79AA005C034F /* CSSNthChild.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSNthChild.m; sourceTree = ""; }; - 547F4955187C021C0041264E /* css_selector.grammar */ = {isa = PBXFileReference; lastKnownFileType = text; path = css_selector.grammar; sourceTree = ""; }; 548A929F187D1CF70045D4CA /* CSSSelectorAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSSelectorAttribute.h; sourceTree = ""; }; 548A92A0187D1CF70045D4CA /* CSSSelectorAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSSelectorAttribute.m; sourceTree = ""; }; 54D62F25187D06150075A755 /* CSSSelectorGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSSelectorGroup.h; sourceTree = ""; }; 54D62F26187D06150075A755 /* CSSSelectorGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSSSelectorGroup.m; sourceTree = ""; }; 54D62F29187D0B0E0075A755 /* CSSSelectorConverter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSSSelectorConverter.h; sourceTree = ""; }; + 54ECE09A1890D30000C2A4ED /* libPods.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libPods.a; path = "Pods/build/Debug-iphoneos/libPods.a"; sourceTree = ""; }; + 54ECE0B81890D5C700C2A4ED /* CSSSelectorParserGenerator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CSSSelectorParserGenerator.m; sourceTree = ""; }; + 54ECE0CE1890F23500C2A4ED /* CSSSelectorParser.plist */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = CSSSelectorParser.plist; sourceTree = ""; }; 645CC76B14924389A7C750E3 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; C89C0A8F74244B1F8AECA338 /* libPods-CSSSelectorConverterTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CSSSelectorConverterTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - CE2CA43EDD52451AA75BA409 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -192,7 +140,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 541971F1188ED2A3004240B4 /* libCoreParse.a in Frameworks */, 540AA34E187BC5F60012AA44 /* CoreGraphics.framework in Frameworks */, 540AA350187BC5F60012AA44 /* UIKit.framework in Frameworks */, 540AA34C187BC5F60012AA44 /* Foundation.framework in Frameworks */, @@ -204,7 +151,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 541971F2188ED36A004240B4 /* libCoreParse.a in Frameworks */, 540AA36E187BC5F70012AA44 /* XCTest.framework in Frameworks */, 540AA370187BC5F70012AA44 /* UIKit.framework in Frameworks */, 540AA36F187BC5F70012AA44 /* Foundation.framework in Frameworks */, @@ -215,15 +161,26 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 4E499CA610DCD32F6D114FC8 /* Pods */ = { + isa = PBXGroup; + children = ( + 48679CA62B498976F68DA0ED /* Pods.debug.xcconfig */, + 4654C27EDB914CB3303D3F76 /* Pods.release.xcconfig */, + 31A43E848921BC4A334A76A7 /* Pods-CSSSelectorConverterTests.debug.xcconfig */, + 2FA369A0A3C034B1BA4E570B /* Pods-CSSSelectorConverterTests.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; 540AA33F187BC5F60012AA44 = { isa = PBXGroup; children = ( + 54ECE0B71890D5C700C2A4ED /* bin */, 540AA351187BC5F60012AA44 /* CSSSelectorConverter */, 540AA373187BC5F70012AA44 /* CSSSelectorConverterTests */, 540AA34A187BC5F60012AA44 /* Frameworks */, 540AA349187BC5F60012AA44 /* Products */, - CE2CA43EDD52451AA75BA409 /* Pods.xcconfig */, - 120C8E845AC74187B385721E /* Pods-CSSSelectorConverterTests.xcconfig */, + 4E499CA610DCD32F6D114FC8 /* Pods */, ); sourceTree = ""; }; @@ -239,7 +196,7 @@ 540AA34A187BC5F60012AA44 /* Frameworks */ = { isa = PBXGroup; children = ( - 541971DE188ED293004240B4 /* CoreParse.xcodeproj */, + 54ECE09A1890D30000C2A4ED /* libPods.a */, 540AA34B187BC5F60012AA44 /* Foundation.framework */, 540AA34D187BC5F60012AA44 /* CoreGraphics.framework */, 540AA34F187BC5F60012AA44 /* UIKit.framework */, @@ -282,7 +239,7 @@ 540AA352187BC5F60012AA44 /* Supporting Files */ = { isa = PBXGroup; children = ( - 547F4955187C021C0041264E /* css_selector.grammar */, + 54ECE0CE1890F23500C2A4ED /* CSSSelectorParser.plist */, 540AA353187BC5F60012AA44 /* CSSSelectorConverter-Info.plist */, 540AA354187BC5F60012AA44 /* InfoPlist.strings */, 540AA357187BC5F60012AA44 /* main.m */, @@ -341,22 +298,16 @@ 541EC703187D43A300F08D19 /* CSSCombinator.m */, 541EC706187D589000F08D19 /* CSSPseudoClass.h */, 541EC707187D589000F08D19 /* CSSPseudoClass.m */, - 5454C0D3187D79AA005C034F /* CSSNthChild.h */, - 5454C0D4187D79AA005C034F /* CSSNthChild.m */, ); name = Selector; sourceTree = ""; }; - 541971DF188ED293004240B4 /* Products */ = { + 54ECE0B71890D5C700C2A4ED /* bin */ = { isa = PBXGroup; children = ( - 541971E7188ED293004240B4 /* CoreParse.framework */, - 541971E9188ED293004240B4 /* CoreParseTests.octest */, - 541971EB188ED293004240B4 /* CoreParse Documentation */, - 541971ED188ED293004240B4 /* libCoreParse.a */, - 541971EF188ED293004240B4 /* CoreParseTests.octest */, + 54ECE0B81890D5C700C2A4ED /* CSSSelectorParserGenerator.m */, ); - name = Products; + path = bin; sourceTree = ""; }; /* End PBXGroup section */ @@ -371,6 +322,7 @@ 540AA345187BC5F60012AA44 /* Frameworks */, 540AA346187BC5F60012AA44 /* Resources */, D4177FD04A764743819E8D91 /* Copy Pods Resources */, + CCBB5AE69B0EE716A45BE69F /* Embed Pods Frameworks */, ); buildRules = ( ); @@ -390,6 +342,7 @@ 540AA369187BC5F70012AA44 /* Frameworks */, 540AA36A187BC5F70012AA44 /* Resources */, B54882A65CA547AA967484DE /* Copy Pods Resources */, + 36C248A9A97CC7EC8A6F38F8 /* Embed Pods Frameworks */, ); buildRules = ( ); @@ -427,12 +380,6 @@ mainGroup = 540AA33F187BC5F60012AA44; productRefGroup = 540AA349187BC5F60012AA44 /* Products */; projectDirPath = ""; - projectReferences = ( - { - ProductGroup = 541971DF188ED293004240B4 /* Products */; - ProjectRef = 541971DE188ED293004240B4 /* CoreParse.xcodeproj */; - }, - ); projectRoot = ""; targets = ( 540AA347187BC5F60012AA44 /* CSSSelectorConverter */, @@ -441,49 +388,12 @@ }; /* End PBXProject section */ -/* Begin PBXReferenceProxy section */ - 541971E7188ED293004240B4 /* CoreParse.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = CoreParse.framework; - remoteRef = 541971E6188ED293004240B4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 541971E9188ED293004240B4 /* CoreParseTests.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = CoreParseTests.octest; - remoteRef = 541971E8188ED293004240B4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 541971EB188ED293004240B4 /* CoreParse Documentation */ = { - isa = PBXReferenceProxy; - fileType = "compiled.mach-o.executable"; - path = "CoreParse Documentation"; - remoteRef = 541971EA188ED293004240B4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 541971ED188ED293004240B4 /* libCoreParse.a */ = { - isa = PBXReferenceProxy; - fileType = archive.ar; - path = libCoreParse.a; - remoteRef = 541971EC188ED293004240B4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 541971EF188ED293004240B4 /* CoreParseTests.octest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = CoreParseTests.octest; - remoteRef = 541971EE188ED293004240B4 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - /* Begin PBXResourcesBuildPhase section */ 540AA346187BC5F60012AA44 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 54ECE0CF1890F23500C2A4ED /* CSSSelectorParser.plist in Resources */, 540AA367187BC5F70012AA44 /* Images.xcassets in Resources */, 5433BA61188D1450006C5F59 /* CSSSelectorGrammar.txt in Resources */, 540AA356187BC5F60012AA44 /* InfoPlist.strings in Resources */, @@ -495,6 +405,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 54ECE0D01890F23500C2A4ED /* CSSSelectorParser.plist in Resources */, 540AA378187BC5F70012AA44 /* InfoPlist.strings in Resources */, 5433BA64188D17CE006C5F59 /* CSSSelectorGrammar.txt in Resources */, ); @@ -518,6 +429,21 @@ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; + 36C248A9A97CC7EC8A6F38F8 /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CSSSelectorConverterTests/Pods-CSSSelectorConverterTests-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; B54882A65CA547AA967484DE /* Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -530,7 +456,22 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Pods-CSSSelectorConverterTests-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CSSSelectorConverterTests/Pods-CSSSelectorConverterTests-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + CCBB5AE69B0EE716A45BE69F /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; D4177FD04A764743819E8D91 /* Copy Pods Resources */ = { @@ -545,7 +486,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; showEnvVarsInLog = 0; }; E9DFBE05A0034D26B921C88E /* Check Pods Manifest.lock */ = { @@ -599,28 +540,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 54BC925C188E736000443230 /* CSSSelectors.m in Sources */, - 54D41BAB188E7A9D00D8521A /* CSSPseudoClass.m in Sources */, 54FA2F76188D7CDD0065B628 /* CSSToXPathConverterSpec.m in Sources */, - 54FA2F73188D7AEB0065B628 /* CSSSelectorParser.m in Sources */, - 54FA2F75188D7C660065B628 /* CSSSelectorToXPathConverter.m in Sources */, - 54BC925E188E770A00443230 /* CSSSelectorGroup.m in Sources */, - 54FA2F7F188D88B90065B628 /* CSSSelectorAttributeOperator.m in Sources */, - 5433BA71188D1D9C006C5F59 /* CSSTypeSelector.m in Sources */, - 54FA2F81188D8E6C0065B628 /* CSSCombinator.m in Sources */, - 5433BA58188D0C5B006C5F59 /* CSSSelectorTokeniser.m in Sources */, - 54FA2F83188D8F610065B628 /* CSSSelectorSequence.m in Sources */, - 54197232188FBBA6004240B4 /* CSSSelectorXPathVisitor.m in Sources */, - 5433BA6D188D1905006C5F59 /* CSSBaseSelector.m in Sources */, - 54FA2F7E188D867F0065B628 /* CSSSelectorAttribute.m in Sources */, - 5433BA5F188D136A006C5F59 /* CSSSelectorGrammar.m in Sources */, - 54FA2F70188D76A90065B628 /* CSSClassSelector.m in Sources */, 54197231188FBAF0004240B4 /* CSSSelectorXPathVisitorSpec.m in Sources */, 5433BA5B188D0D71006C5F59 /* CSSSelectorTokeniserSpec.m in Sources */, - 5433BA6E188D1907006C5F59 /* CSSNamedSelector.m in Sources */, - 54FA2F7A188D826F0065B628 /* CSSIDSelector.m in Sources */, 5433BA63188D1629006C5F59 /* CSSSelectorParserSpec.m in Sources */, - 5433BA65188D1807006C5F59 /* CSSUniversalSelector.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -736,16 +659,13 @@ }; 540AA37E187BC5F70012AA44 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = CE2CA43EDD52451AA75BA409 /* Pods.xcconfig */; + baseConfigurationReference = 48679CA62B498976F68DA0ED /* Pods.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "CSSSelectorConverter/CSSSelectorConverter-Prefix.pch"; - HEADER_SEARCH_PATHS = ( - "vendor/CoreParse/CoreParse/**", - "$(inherited)", - ); + HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = "CSSSelectorConverter/CSSSelectorConverter-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; @@ -754,16 +674,13 @@ }; 540AA37F187BC5F70012AA44 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = CE2CA43EDD52451AA75BA409 /* Pods.xcconfig */; + baseConfigurationReference = 4654C27EDB914CB3303D3F76 /* Pods.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "CSSSelectorConverter/CSSSelectorConverter-Prefix.pch"; - HEADER_SEARCH_PATHS = ( - "vendor/CoreParse/CoreParse/**", - "$(inherited)", - ); + HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = "CSSSelectorConverter/CSSSelectorConverter-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; @@ -772,9 +689,10 @@ }; 540AA381187BC5F70012AA44 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 120C8E845AC74187B385721E /* Pods-CSSSelectorConverterTests.xcconfig */; + baseConfigurationReference = 31A43E848921BC4A334A76A7 /* Pods-CSSSelectorConverterTests.debug.xcconfig */; buildSettings = { ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; + BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/CSSSelectorConverter.app/CSSSelectorConverter"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", @@ -792,15 +710,17 @@ ); INFOPLIST_FILE = "CSSSelectorConverterTests/CSSSelectorConverterTests-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUNDLE_LOADER)"; WRAPPER_EXTENSION = xctest; }; name = Debug; }; 540AA382187BC5F70012AA44 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 120C8E845AC74187B385721E /* Pods-CSSSelectorConverterTests.xcconfig */; + baseConfigurationReference = 2FA369A0A3C034B1BA4E570B /* Pods-CSSSelectorConverterTests.release.xcconfig */; buildSettings = { ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; + BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/CSSSelectorConverter.app/CSSSelectorConverter"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", @@ -814,6 +734,7 @@ ); INFOPLIST_FILE = "CSSSelectorConverterTests/CSSSelectorConverterTests-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUNDLE_LOADER)"; WRAPPER_EXTENSION = xctest; }; name = Release; diff --git a/CSSSelectorConverter.xcodeproj/xcshareddata/xcschemes/CSSSelectorConverter.xcscheme b/CSSSelectorConverter.xcodeproj/xcshareddata/xcschemes/CSSSelectorConverter.xcscheme new file mode 100644 index 0000000..a96ce86 --- /dev/null +++ b/CSSSelectorConverter.xcodeproj/xcshareddata/xcschemes/CSSSelectorConverter.xcscheme @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CSSSelectorConverter.xcworkspace/xcshareddata/CSSSelectorConverter.xccheckout b/CSSSelectorConverter.xcworkspace/xcshareddata/CSSSelectorConverter.xccheckout index aefc0aa..e0edd19 100644 --- a/CSSSelectorConverter.xcworkspace/xcshareddata/CSSSelectorConverter.xccheckout +++ b/CSSSelectorConverter.xcworkspace/xcshareddata/CSSSelectorConverter.xccheckout @@ -10,33 +10,33 @@ CSSSelectorConverter IDESourceControlProjectOriginsDictionary - 36A6D4CA-6BB3-414E-BFBE-97B75EEBBCA3 + 122DB07625ACCDABC9818C06D3A839B56B29D4FD ssh://github.com/siuying/CSSSelectorConverter.git - 933D72C4-BB34-468B-8A2A-F9A5F6A06A65 + 20B5E220B44D3958A2219B13999BCD96DC9444FE https://github.com/beelsebob/CoreParse.git IDESourceControlProjectPath CSSSelectorConverter.xcworkspace IDESourceControlProjectRelativeInstallPathDictionary - 36A6D4CA-6BB3-414E-BFBE-97B75EEBBCA3 + 122DB07625ACCDABC9818C06D3A839B56B29D4FD .. - 933D72C4-BB34-468B-8A2A-F9A5F6A06A65 + 20B5E220B44D3958A2219B13999BCD96DC9444FE ../vendor/CoreParse IDESourceControlProjectURL ssh://github.com/siuying/CSSSelectorConverter.git IDESourceControlProjectVersion - 110 + 111 IDESourceControlProjectWCCIdentifier - 36A6D4CA-6BB3-414E-BFBE-97B75EEBBCA3 + 122DB07625ACCDABC9818C06D3A839B56B29D4FD IDESourceControlProjectWCConfigurations IDESourceControlRepositoryExtensionIdentifierKey public.vcs.git IDESourceControlWCCIdentifierKey - 933D72C4-BB34-468B-8A2A-F9A5F6A06A65 + 20B5E220B44D3958A2219B13999BCD96DC9444FE IDESourceControlWCCName CoreParse @@ -44,7 +44,7 @@ IDESourceControlRepositoryExtensionIdentifierKey public.vcs.git IDESourceControlWCCIdentifierKey - 36A6D4CA-6BB3-414E-BFBE-97B75EEBBCA3 + 122DB07625ACCDABC9818C06D3A839B56B29D4FD IDESourceControlWCCName CSSSelectorConverter diff --git a/CSSSelectorConverter.xcworkspace/xcshareddata/CSSSelectorConverter.xcscmblueprint b/CSSSelectorConverter.xcworkspace/xcshareddata/CSSSelectorConverter.xcscmblueprint new file mode 100644 index 0000000..3d5c2ff --- /dev/null +++ b/CSSSelectorConverter.xcworkspace/xcshareddata/CSSSelectorConverter.xcscmblueprint @@ -0,0 +1,30 @@ +{ + "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "122DB07625ACCDABC9818C06D3A839B56B29D4FD", + "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { + + }, + "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { + "20B5E220B44D3958A2219B13999BCD96DC9444FE" : 0, + "122DB07625ACCDABC9818C06D3A839B56B29D4FD" : 0 + }, + "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "F3C80365-7344-4DF4-8217-F1266652B9AD", + "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { + "20B5E220B44D3958A2219B13999BCD96DC9444FE" : "CSSSelectorConverter\/vendor\/CoreParse", + "122DB07625ACCDABC9818C06D3A839B56B29D4FD" : "CSSSelectorConverter" + }, + "DVTSourceControlWorkspaceBlueprintNameKey" : "CSSSelectorConverter", + "DVTSourceControlWorkspaceBlueprintVersion" : 204, + "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "CSSSelectorConverter.xcworkspace", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "ssh:\/\/github.com\/siuying\/CSSSelectorConverter.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "122DB07625ACCDABC9818C06D3A839B56B29D4FD" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/beelsebob\/CoreParse.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "20B5E220B44D3958A2219B13999BCD96DC9444FE" + } + ] +} \ No newline at end of file diff --git a/CSSSelectorConverter/CSSClassSelector.h b/CSSSelectorConverter/CSSClassSelector.h index 585e4d9..c31a99b 100644 --- a/CSSSelectorConverter/CSSClassSelector.h +++ b/CSSSelectorConverter/CSSClassSelector.h @@ -8,7 +8,8 @@ #import #import "CSSNamedSelector.h" +#import "NUIPParser.h" -@interface CSSClassSelector : CSSNamedSelector +@interface CSSClassSelector : CSSNamedSelector @end diff --git a/CSSSelectorConverter/CSSClassSelector.m b/CSSSelectorConverter/CSSClassSelector.m index 26fdc89..fcb0dae 100644 --- a/CSSSelectorConverter/CSSClassSelector.m +++ b/CSSSelectorConverter/CSSClassSelector.m @@ -7,15 +7,16 @@ // #import "CSSClassSelector.h" +#import "NUIParse.h" @implementation CSSClassSelector -- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree { +- (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree { self = [self init]; if (self) { NSArray *components = [syntaxTree children]; if ([components count] == 2) { - CPIdentifierToken* token = components[1]; + NUIPIdentifierToken* token = components[1]; if ([token isIdentifierToken]) { self.name = [token identifier]; } diff --git a/CSSSelectorConverter/CSSCombinator.h b/CSSSelectorConverter/CSSCombinator.h index 475387d..f33fd46 100644 --- a/CSSSelectorConverter/CSSCombinator.h +++ b/CSSSelectorConverter/CSSCombinator.h @@ -7,6 +7,7 @@ // #import "CSSBaseSelector.h" +#import "NUIPParser.h" typedef NS_ENUM(NSInteger, CSSCombinatorType) { CSSCombinatorTypeNone = 0, @@ -15,7 +16,7 @@ typedef NS_ENUM(NSInteger, CSSCombinatorType) { CSSCombinatorTypeGeneralSibling }; -@interface CSSCombinator : CSSBaseSelector +@interface CSSCombinator : CSSBaseSelector @property (nonatomic, assign) CSSCombinatorType type; diff --git a/CSSSelectorConverter/CSSCombinator.m b/CSSSelectorConverter/CSSCombinator.m index bca0484..18355b7 100644 --- a/CSSSelectorConverter/CSSCombinator.m +++ b/CSSSelectorConverter/CSSCombinator.m @@ -7,14 +7,11 @@ // #import "CSSCombinator.h" -#import "DDLog.h" -#undef LOG_LEVEL_DEF -#define LOG_LEVEL_DEF cssSelectorLogLevel -static const int cssSelectorLogLevel = LOG_LEVEL_WARN; +#import "NUIParse.h" @implementation CSSCombinator -- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree { +- (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree { self = [self init]; NSArray *components = [syntaxTree children]; if ([components count] >= 1) { diff --git a/CSSSelectorConverter/CSSIDSelector.h b/CSSSelectorConverter/CSSIDSelector.h index 8833b04..4b15538 100644 --- a/CSSSelectorConverter/CSSIDSelector.h +++ b/CSSSelectorConverter/CSSIDSelector.h @@ -8,7 +8,8 @@ #import #import "CSSNamedSelector.h" +#import "NUIPParser.h" -@interface CSSIDSelector : CSSNamedSelector +@interface CSSIDSelector : CSSNamedSelector @end diff --git a/CSSSelectorConverter/CSSIDSelector.m b/CSSSelectorConverter/CSSIDSelector.m index 17c6460..a2742be 100644 --- a/CSSSelectorConverter/CSSIDSelector.m +++ b/CSSSelectorConverter/CSSIDSelector.m @@ -7,15 +7,16 @@ // #import "CSSIDSelector.h" +#import "NUIParse.h" @implementation CSSIDSelector -- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree { +- (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree { self = [self init]; if (self) { NSArray *components = [syntaxTree children]; if ([components count] == 2) { - CPIdentifierToken* token = components[1]; + NUIPIdentifierToken* token = components[1]; if ([token isIdentifierToken]) { self.name = [token identifier]; } diff --git a/CSSSelectorConverter/CSSNthChild.h b/CSSSelectorConverter/CSSNthChild.h deleted file mode 100644 index 6617ba6..0000000 --- a/CSSSelectorConverter/CSSNthChild.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// CSSNthChild.h -// CSSSelectorConverter -// -// Created by Chong Francis on 14年1月8日. -// Copyright (c) 2014年 Ignition Soft. All rights reserved. -// - -#import "CSSPseudoClass.h" - -/** - nth-child pseudo class. - - it support: nth-child(an+b), nth-child(a), nth-child(odd), nth-child(even) - */ -@interface CSSNthChild : CSSPseudoClass - -// nth-child: an + b -@property (nonatomic, assign) NSInteger constantA; - -// nth-child: an + b -@property (nonatomic, assign) NSInteger constantB; - -@end diff --git a/CSSSelectorConverter/CSSNthChild.m b/CSSSelectorConverter/CSSNthChild.m deleted file mode 100644 index c0e35d6..0000000 --- a/CSSSelectorConverter/CSSNthChild.m +++ /dev/null @@ -1,100 +0,0 @@ -// -// CSSNthChild.m -// CSSSelectorConverter -// -// Created by Chong Francis on 14年1月8日. -// Copyright (c) 2014年 Ignition Soft. All rights reserved. -// -#import "DDLog.h" -#undef LOG_LEVEL_DEF -#define LOG_LEVEL_DEF cssSelectorLogLevel -static const int cssSelectorLogLevel = LOG_LEVEL_WARN; - -#import "CSSNthChild.h" - -static const NSInteger CSSNthChildUnassigned = NSIntegerMax; - -@interface CSSNthChild() -@property (nonatomic, assign) BOOL nAssigned; -@end - -@implementation CSSNthChild - --(instancetype) init { - self = [super init]; - self.constantA = CSSNthChildUnassigned; - self.constantB = CSSNthChildUnassigned; - self.nAssigned = NO; - return self; -} - --(NSString*) description { - return [NSString stringWithFormat:@"", self.constantA, self.constantB]; -} - --(NSString*) toXPath { - NSString* parentName = self.parent ? self.parent.name : @"*"; - NSString* positionSign = self.constantA > 0 ? @">=" : @"<="; - if (self.constantB == 0) { - return [NSString stringWithFormat:@"%@[(position() mod %d) = 0]", parentName, self.constantA]; - } else { - if (self.constantB > 0) { - return [NSString stringWithFormat:@"%@[(position() %@ %d) and (((position()-%d) mod %d) = 0)]", parentName, positionSign, - self.constantB, self.constantB, self.constantA]; - } else { - return [NSString stringWithFormat:@"%@[(position() %@ %d) and (((position()-%d) mod %d) = 0)]", parentName, positionSign, - self.constantA + self.constantB, self.constantA + self.constantB, self.constantA]; - } - } -} - -+(void) pushPseudoClass:(PKAssembly*)assembly { - CSSNthChild* nthChild = [[CSSNthChild alloc] init]; - id token = nil; - while ((token = [assembly pop])) { - if ([token isKindOfClass:[PKToken class]]) { - PKToken* pkToken = token; - NSString* stringValue = [pkToken stringValue]; - if ([stringValue isEqualToString:@"nth"]) { - if (nthChild.constantA == CSSNthChildUnassigned) { - nthChild.constantA = nthChild.constantB; - nthChild.constantB = CSSNthChildUnassigned; - } - [assembly push:nthChild]; - DDLogVerbose(@"Pushed: %@", nthChild); - return; - } else if ([stringValue isEqualToString:@"-"] || [stringValue isEqualToString:@"+"] || [stringValue isEqualToString:@"child"]) { - // do nothing - - } else if ([stringValue isEqualToString:@"odd"]) { - nthChild.constantA = 2; - nthChild.constantB = 1; - - } else if ([stringValue isEqualToString:@"even"]) { - nthChild.constantA = 2; - nthChild.constantB = 0; - - } else if ([stringValue isEqualToString:@"even"]) { - nthChild.constantA = 2; - nthChild.constantB = 0; - - } else if ([stringValue isEqualToString:@"n"]) { - nthChild.nAssigned = YES; - - } else if ([token isNumber]) { - NSInteger intVal = [@([pkToken floatValue]) integerValue]; - if (nthChild.nAssigned) { - nthChild.constantA = intVal; - } else { - nthChild.constantB = intVal; - } - } - } else { - [assembly push:token]; - [assembly push:nthChild]; - return; - } - } -} - -@end diff --git a/CSSSelectorConverter/CSSPseudoClass.h b/CSSSelectorConverter/CSSPseudoClass.h index 06efff8..8e70067 100644 --- a/CSSSelectorConverter/CSSPseudoClass.h +++ b/CSSSelectorConverter/CSSPseudoClass.h @@ -7,8 +7,9 @@ // #import "CSSNamedSelector.h" +#import "NUIPParser.h" -@interface CSSPseudoClass : CSSNamedSelector +@interface CSSPseudoClass : CSSNamedSelector @property (nonatomic, weak) CSSNamedSelector* parent; diff --git a/CSSSelectorConverter/CSSPseudoClass.m b/CSSSelectorConverter/CSSPseudoClass.m index 3244ab0..6214c8e 100644 --- a/CSSSelectorConverter/CSSPseudoClass.m +++ b/CSSSelectorConverter/CSSPseudoClass.m @@ -5,17 +5,12 @@ // Created by Chong Francis on 14年1月8日. // Copyright (c) 2014年 Ignition Soft. All rights reserved. // -#import "DDLog.h" -#undef LOG_LEVEL_DEF -#define LOG_LEVEL_DEF cssSelectorLogLevel -static const int cssSelectorLogLevel = LOG_LEVEL_WARN; - #import "CSSPseudoClass.h" -#import "CSSNthChild.h" +#import "NUIParse.h" @implementation CSSPseudoClass -- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree { +- (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree { self = [self init]; id token = [syntaxTree valueForTag:@"className"]; diff --git a/CSSSelectorConverter/CSSSelectorAttribute.h b/CSSSelectorConverter/CSSSelectorAttribute.h index 3a21458..6261818 100644 --- a/CSSSelectorConverter/CSSSelectorAttribute.h +++ b/CSSSelectorConverter/CSSSelectorAttribute.h @@ -8,8 +8,9 @@ #import "CSSBaseSelector.h" #import "CSSSelectorAttributeOperator.h" +#import "NUIPParser.h" -@interface CSSSelectorAttribute : CSSBaseSelector +@interface CSSSelectorAttribute : CSSBaseSelector @property (nonatomic, strong) CSSSelectorAttributeOperator* attributeOperator; @property (nonatomic, copy) NSString* name; diff --git a/CSSSelectorConverter/CSSSelectorAttribute.m b/CSSSelectorConverter/CSSSelectorAttribute.m index f091556..389260d 100644 --- a/CSSSelectorConverter/CSSSelectorAttribute.m +++ b/CSSSelectorConverter/CSSSelectorAttribute.m @@ -8,15 +8,11 @@ #import "CSSSelectorParser.h" #import "CSSSelectorAttribute.h" -#import "DDLog.h" - -#undef LOG_LEVEL_DEF -#define LOG_LEVEL_DEF cssSelectorLogLevel -static const int cssSelectorLogLevel = LOG_LEVEL_VERBOSE; +#import "NUIParse.h" @implementation CSSSelectorAttribute -- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree { +- (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree { self = [self init]; if (self) { self.attributeOperator = [syntaxTree valueForTag:@"op"]; diff --git a/CSSSelectorConverter/CSSSelectorAttributeOperator.h b/CSSSelectorConverter/CSSSelectorAttributeOperator.h index dbe87ce..71edbd4 100644 --- a/CSSSelectorConverter/CSSSelectorAttributeOperator.h +++ b/CSSSelectorConverter/CSSSelectorAttributeOperator.h @@ -7,6 +7,7 @@ // #import "CSSNamedSelector.h" +#import "NUIPParser.h" typedef NS_ENUM(NSInteger, CSSSelectorAttributeOperatorType) { CSSSelectorAttributeOperatorTypeNone = 0, @@ -15,7 +16,7 @@ typedef NS_ENUM(NSInteger, CSSSelectorAttributeOperatorType) { CSSSelectorAttributeOperatorTypeDash }; -@interface CSSSelectorAttributeOperator : CSSNamedSelector +@interface CSSSelectorAttributeOperator : CSSNamedSelector @property (nonatomic, assign) CSSSelectorAttributeOperatorType attributeOperator; diff --git a/CSSSelectorConverter/CSSSelectorAttributeOperator.m b/CSSSelectorConverter/CSSSelectorAttributeOperator.m index c80f6dc..4039546 100644 --- a/CSSSelectorConverter/CSSSelectorAttributeOperator.m +++ b/CSSSelectorConverter/CSSSelectorAttributeOperator.m @@ -9,17 +9,18 @@ #undef LOG_LEVEL_DEF #define LOG_LEVEL_DEF cssSelectorLogLevel static const int cssSelectorLogLevel = LOG_LEVEL_VERBOSE; +#import "NUIParse.h" #import "CSSSelectorAttributeOperator.h" @implementation CSSSelectorAttributeOperator -- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree { +- (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree { self = [self init]; if (self) { NSArray *components = [syntaxTree children]; if ([components count] == 1) { - CPKeywordToken* token = [components[0] children][0]; + NUIPKeywordToken* token = [components[0] children][0]; if ([token isKeywordToken]) { self.name = [token keyword]; self.attributeOperator = [[self class] operatorWithString:[token keyword]]; diff --git a/CSSSelectorConverter/CSSSelectorConverter-Prefix.pch b/CSSSelectorConverter/CSSSelectorConverter-Prefix.pch index c3ced0f..4412bec 100644 --- a/CSSSelectorConverter/CSSSelectorConverter-Prefix.pch +++ b/CSSSelectorConverter/CSSSelectorConverter-Prefix.pch @@ -13,5 +13,4 @@ #ifdef __OBJC__ #import #import - #import "CoreParse.h" #endif \ No newline at end of file diff --git a/CSSSelectorConverter/CSSSelectorConverter.h b/CSSSelectorConverter/CSSSelectorConverter.h index 9e13e4b..53f6605 100644 --- a/CSSSelectorConverter/CSSSelectorConverter.h +++ b/CSSSelectorConverter/CSSSelectorConverter.h @@ -9,21 +9,5 @@ #ifndef _CSSSelectorConverter_ #define _CSSSelectorConverter_ -#import "CSSUniversalSelector.h" -#import "CSSNamedSelector.h" -#import "CSSTypeSelector.h" -#import "CSSIDSelector.h" -#import "CSSClassSelector.h" -#import "CSSSelectorSequence.h" -#import "CSSSelectors.h" -#import "CSSSelectorGroup.h" -#import "CSSSelectorParser.h" #import "CSSSelectorToXPathConverter.h" -#import "CSSSelectorAttribute.h" -#import "CSSNamedSelector.h" -#import "CSSCombinator.h" -#import "CSSNamedSelector.h" -#import "CSSPseudoClass.h" -#import "CSSNthChild.h" - #endif diff --git a/CSSSelectorConverter/CSSSelectorGrammar.h b/CSSSelectorConverter/CSSSelectorGrammar.h index 44dbc10..7ceffc4 100644 --- a/CSSSelectorConverter/CSSSelectorGrammar.h +++ b/CSSSelectorConverter/CSSSelectorGrammar.h @@ -6,8 +6,19 @@ // Copyright (c) 2014 Ignition Soft. All rights reserved. // -#import "CPGrammar.h" +#import "NUIPGrammar.h" -@interface CSSSelectorGrammar : CPGrammar +@interface CSSSelectorGrammar : NUIPGrammar + +/** + * Create a Grammar object using the grammar file in the bundle. + */ +-(instancetype) init; + +/** + * Create a Grammar object using the grammar file supplied. + * @param path Path to the grammar defintion + */ +-(instancetype) initWithPath:(NSString*)path; @end diff --git a/CSSSelectorConverter/CSSSelectorGrammar.m b/CSSSelectorConverter/CSSSelectorGrammar.m index 1c01888..d7f22f2 100644 --- a/CSSSelectorConverter/CSSSelectorGrammar.m +++ b/CSSSelectorConverter/CSSSelectorGrammar.m @@ -10,20 +10,36 @@ #import "CSSTypeSelector.h" #import "CSSUniversalSelector.h" +#import "DDLog.h" +#undef LOG_LEVEL_DEF +#define LOG_LEVEL_DEF cssSelectorLogLevel +static const int cssSelectorLogLevel = LOG_LEVEL_VERBOSE; + @implementation CSSSelectorGrammar -(instancetype) init { - NSError* error; NSString* path = [[NSBundle bundleForClass:[self class]] pathForResource:@"CSSSelectorGrammar" ofType:@"txt"]; - NSString* grammar = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; + return [self initWithPath:path]; +} + +-(instancetype) initWithPath:(NSString*)path +{ + NSError* error; + NSString* grammar = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error]; if (!grammar) { - [NSException raise:NSInvalidArgumentException format:@"missing grammar file CSSSelectorGrammar.txt"]; + if (error) { + DDLogError(@"missing grammar file %@, error: %@", path, error); + [NSException raise:NSInvalidArgumentException format:@"missing grammar file %@, error: %@", path, error]; + } else { + DDLogError(@"missing grammar file %@", path); + [NSException raise:NSInvalidArgumentException format:@"missing grammar file %@", path]; + } } self = [super initWithStart:@"CSSSelectorGroup" backusNaurForm:grammar error:&error]; if (!self) { if (error) { - NSLog(@"error compile language = %@", error); + DDLogError(@"error compile language = %@", error); } } return self; diff --git a/CSSSelectorConverter/CSSSelectorGrammar.txt b/CSSSelectorConverter/CSSSelectorGrammar.txt index 40e6c6b..e076655 100644 --- a/CSSSelectorConverter/CSSSelectorGrammar.txt +++ b/CSSSelectorConverter/CSSSelectorGrammar.txt @@ -10,12 +10,10 @@ CSSIDSelector ::= '#' idName@'Identifier'; CSSTypeSelector ::= typeName@'Identifier'; CSSUniversalSelector ::= '*'; CSSPseudoExpression ::= (( '+' | '-' | 'Number' 'Identifier' | 'Number' | 'Identifier' ) 'Whitespace'* )+; - QuotedString ::= 'String'; Dashmatch ::= '|='; Includes ::= '~='; Equal ::= '='; - Comma ::= ','; Plus ::= '+'; Greater ::= '>'; diff --git a/CSSSelectorConverter/CSSSelectorGroup.h b/CSSSelectorConverter/CSSSelectorGroup.h index 6a0dd11..3561181 100644 --- a/CSSSelectorConverter/CSSSelectorGroup.h +++ b/CSSSelectorConverter/CSSSelectorGroup.h @@ -8,8 +8,9 @@ #import "CSSBaseSelector.h" #import "CSSSelectors.h" +#import "NUIPParser.h" -@interface CSSSelectorGroup : CSSBaseSelector +@interface CSSSelectorGroup : CSSBaseSelector @property (nonatomic, strong) NSMutableArray* selectors; diff --git a/CSSSelectorConverter/CSSSelectorGroup.m b/CSSSelectorConverter/CSSSelectorGroup.m index 1b5fef9..b89fb40 100644 --- a/CSSSelectorConverter/CSSSelectorGroup.m +++ b/CSSSelectorConverter/CSSSelectorGroup.m @@ -7,14 +7,11 @@ // #import "CSSSelectorGroup.h" -#import "DDLog.h" -#undef LOG_LEVEL_DEF -#define LOG_LEVEL_DEF cssSelectorLogLevel -static const int cssSelectorLogLevel = LOG_LEVEL_VERBOSE; +#import "NUIParse.h" @implementation CSSSelectorGroup -- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree { +- (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree { self = [self init]; if (self) { CSSSelectors* selector = [syntaxTree valueForTag:@"firstSelector"]; diff --git a/CSSSelectorConverter/CSSSelectorParser+FixWhitespace.h b/CSSSelectorConverter/CSSSelectorParser+FixWhitespace.h deleted file mode 100644 index 9340ba8..0000000 --- a/CSSSelectorConverter/CSSSelectorParser+FixWhitespace.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// CSSSelectorParser+FixWhitespace.h -// CSSSelectorConverter -// -// Created by Francis Chong on 1/20/14. -// Copyright (c) 2014 Ignition Soft. All rights reserved. -// - -#import "CSSSelectorParser.h" - -/** - workaround for whitespace parsing (https://github.com/itod/parsekit/issues/29) - */ - - -enum { - TOKEN_KIND_BUILTIN_S = TOKEN_KIND_BUILTIN_WHITESPACE -}; - -@interface CSSSelectorParser (FixWhitespace) - -- (void) matchS:(BOOL)discard; - -@end diff --git a/CSSSelectorConverter/CSSSelectorParser+FixWhitespace.m b/CSSSelectorConverter/CSSSelectorParser+FixWhitespace.m deleted file mode 100644 index 3c6dba4..0000000 --- a/CSSSelectorConverter/CSSSelectorParser+FixWhitespace.m +++ /dev/null @@ -1,17 +0,0 @@ -// -// CSSSelectorParser+FixWhitespace.m -// CSSSelectorConverter -// -// Created by Francis Chong on 1/20/14. -// Copyright (c) 2014 Ignition Soft. All rights reserved. -// - -#import "CSSSelectorParser+FixWhitespace.h" - -@implementation CSSSelectorParser (FixWhitespace) - -- (void) matchS:(BOOL)discard { - [self matchWhitespace:discard]; -} - -@end diff --git a/CSSSelectorConverter/CSSSelectorParser.h b/CSSSelectorConverter/CSSSelectorParser.h index 779f7e9..88e44c5 100644 --- a/CSSSelectorConverter/CSSSelectorParser.h +++ b/CSSSelectorConverter/CSSSelectorParser.h @@ -1,13 +1,41 @@ #import #import "CSSSelectorGroup.h" +#import "NUIPParser.h" +#import "NUIPTokeniser.h" extern NSString* const CSSSelectorParserException; +extern NSString* const CSSSelectorParserErrorDomain; +extern NSString* const CSSSelectorParserErrorInputStreamKey; +extern NSString* const CSSSelectorParserErrorAcceptableTokenKey; @class CSSSelectorGroup; -@interface CSSSelectorParser : NSObject +/** + * CSSSelectorParser parse a CSS Selector and return a CSSSelectorGroup. + * + * Use ``CSSSelectorXPathVisitor`` to convert the returned tree into a XPath. + * @see CSSSelectorParser + */ +@interface CSSSelectorParser : NSObject -- (CSSSelectorGroup*)parse:(NSString *)css; +/** + Last error encountered by the parser. + */ +@property (nonatomic, strong) NSError* lastError; + +-(instancetype) init; + +-(instancetype) initWithParser:(NUIPParser*)parser; + +/** + * Parse a CSS Selector and return a CSSSelectorGroup object. + * + * + * @param css The css selector + * @param error If the parse failed and parser return nil, error is set to last known error. + * @return CSSSelectorGroup the parsed selector. Or nil if error occurred. + */ +- (CSSSelectorGroup*)parse:(NSString *)css error:(NSError**)error; @end diff --git a/CSSSelectorConverter/CSSSelectorParser.m b/CSSSelectorConverter/CSSSelectorParser.m index 0cc0814..c43bb3b 100644 --- a/CSSSelectorConverter/CSSSelectorParser.m +++ b/CSSSelectorConverter/CSSSelectorParser.m @@ -1,7 +1,7 @@ #import "CSSSelectorParser.h" #import "CSSSelectorGrammar.h" #import "CSSSelectorTokeniser.h" - +#import "NUIParse.h" #import "DDLog.h" #undef LOG_LEVEL_DEF @@ -9,38 +9,53 @@ static const int cssSelectorLogLevel = LOG_LEVEL_ERROR; NSString* const CSSSelectorParserException = @"CSSSelectorParserException"; +NSString* const CSSSelectorParserErrorDomain = @"CSSSelectorParserErrorDomain"; +NSString* const CSSSelectorParserErrorInputStreamKey = @"input stream"; +NSString* const CSSSelectorParserErrorAcceptableTokenKey = @"acceptable token"; enum { CSSSelectorParserRuleQuotedString = 1 }; @interface CSSSelectorParser () -@property (nonatomic, strong) CSSSelectorGrammar* grammar; @property (nonatomic, strong) CSSSelectorTokeniser *tokeniser; -@property (nonatomic, strong) CPParser* parser; +@property (nonatomic, strong) NUIPParser* parser; @end @implementation CSSSelectorParser - (id)init { + NUIPLALR1Parser* parser = [NUIPLALR1Parser parserWithGrammar:[[CSSSelectorGrammar alloc] initWithPath:[[NSBundle bundleForClass:[self class]] pathForResource:@"CSSSelectorGrammar" ofType:@"txt"]]]; + return [self initWithParser:parser]; +} + +-(instancetype) initWithParser:(NUIPParser*)parser +{ self = [super init]; self.tokeniser = [[CSSSelectorTokeniser alloc] init]; self.tokeniser.delegate = self; - self.grammar = [[CSSSelectorGrammar alloc] init]; - self.parser = [CPLALR1Parser parserWithGrammar:self.grammar]; + self.parser = parser; self.parser.delegate = self; return self; } -- (CSSSelectorGroup*)parse:(NSString *)css +- (CSSSelectorGroup*)parse:(NSString *)css error:(NSError*__autoreleasing*)error { - CPTokenStream *tokenStream = [self.tokeniser tokenise:css]; - return [self.parser parse:tokenStream]; + NUIPTokenStream *tokenStream = [self.tokeniser tokenise:css]; + CSSSelectorGroup* result = [self.parser parse:tokenStream]; + if (!result) { + if (error) { + *error = self.lastError; + } else { + DDLogError(@"CSSSelectorParser: parse error: %@", self.lastError); + } + } + return result; } #pragma mark - CPParserDelegate -- (id)parser:(CPParser *)parser didProduceSyntaxTree:(CPSyntaxTree *)syntaxTree +- (id)parser:(NUIPParser *)parser didProduceSyntaxTree:(NUIPSyntaxTree *)syntaxTree { switch ([[syntaxTree rule] tag]) { case CSSSelectorParserRuleQuotedString: { @@ -48,7 +63,8 @@ - (id)parser:(CPParser *)parser didProduceSyntaxTree:(CPSyntaxTree *)syntaxTree if ([children count] == 1 && [children[0] isQuotedToken]) { return [children[0] content]; } else { - [NSException raise:CSSSelectorParserException format:@"unexpected token: should be a quoted token, now: %@", syntaxTree]; + [NSException raise:CSSSelectorParserException + format:@"unexpected token: should be a quoted token, now: %@", syntaxTree]; } } break; @@ -59,17 +75,18 @@ - (id)parser:(CPParser *)parser didProduceSyntaxTree:(CPSyntaxTree *)syntaxTree return syntaxTree; } -- (CPRecoveryAction *)parser:(CPParser *)parser didEncounterErrorOnInput:(CPTokenStream *)inputStream expecting:(NSSet *)acceptableTokens +- (NUIPRecoveryAction *)parser:(NUIPParser *)parser didEncounterErrorOnInput:(NUIPTokenStream *)inputStream expecting:(NSSet *)acceptableTokens { - DDLogError(@"Error parsing input: %@ tokens: %@", - [inputStream description], - [acceptableTokens description]); - return [CPRecoveryAction recoveryActionStop]; + NSError* error = [NSError errorWithDomain:CSSSelectorParserErrorDomain + code:1 + userInfo:@{CSSSelectorParserErrorInputStreamKey: inputStream, CSSSelectorParserErrorAcceptableTokenKey: acceptableTokens}]; + self.lastError = error; + return [NUIPRecoveryAction recoveryActionStop]; } #pragma mark - CPTokeniserDelegate -- (BOOL)tokeniser:(CPTokeniser *)tokeniser shouldConsumeToken:(CPToken *)token +- (BOOL)tokeniser:(NUIPTokeniser *)tokeniser shouldConsumeToken:(NUIPToken *)token { return YES; } diff --git a/CSSSelectorConverter/CSSSelectorParser.plist b/CSSSelectorConverter/CSSSelectorParser.plist new file mode 100644 index 0000000..3041ede Binary files /dev/null and b/CSSSelectorConverter/CSSSelectorParser.plist differ diff --git a/CSSSelectorConverter/CSSSelectorSequence.h b/CSSSelectorConverter/CSSSelectorSequence.h index 97cdc46..b51496c 100644 --- a/CSSSelectorConverter/CSSSelectorSequence.h +++ b/CSSSelectorConverter/CSSSelectorSequence.h @@ -8,12 +8,13 @@ #import #import "CSSBaseSelector.h" +#import "NUIPParser.h" @class CSSCombinator; @class CSSPseudoClass; @class CSSTypeSelector; -@interface CSSSelectorSequence : CSSBaseSelector +@interface CSSSelectorSequence : CSSBaseSelector @property (nonatomic, strong) CSSPseudoClass* pseudoClass; diff --git a/CSSSelectorConverter/CSSSelectorSequence.m b/CSSSelectorConverter/CSSSelectorSequence.m index 57016ad..975d91b 100644 --- a/CSSSelectorConverter/CSSSelectorSequence.m +++ b/CSSSelectorConverter/CSSSelectorSequence.m @@ -7,6 +7,7 @@ // #import "DDLog.h" +#import "NUIParse.h" #undef LOG_LEVEL_DEF #define LOG_LEVEL_DEF cssSelectorLogLevel @@ -24,7 +25,7 @@ @implementation CSSSelectorSequence -- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree { +- (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree { self = [self init]; if (self) { NSArray* selectors = nil; @@ -49,7 +50,7 @@ - (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree { [self addSelector:selector]; }]; } else { - [NSException raise:NSInvalidArgumentException format:@"expected NSArray, receive: %@", selectors]; + [NSException raise:NSInvalidArgumentException format:@"expected NSArray, receive: %@", syntaxTree]; } } return self; diff --git a/CSSSelectorConverter/CSSSelectorToXPathConverter.h b/CSSSelectorConverter/CSSSelectorToXPathConverter.h index 3194978..279560f 100644 --- a/CSSSelectorConverter/CSSSelectorToXPathConverter.h +++ b/CSSSelectorConverter/CSSSelectorToXPathConverter.h @@ -7,16 +7,33 @@ // #import -#import "CSSSelectorParser.h" +@class CSSSelectorParser; + +/** + * Convert a CSS Selector to XPath. + * + * @see CSSSelectorParser + * @see CSSSelectorXPathVisitor + */ @interface CSSSelectorToXPathConverter : NSObject @property (nonatomic, strong) CSSSelectorParser* parser; ++(instancetype) sharedConverter; + -(id) init; -(id) initWithParser:(CSSSelectorParser*)parser; --(NSString*)xpathWithCSS:(NSString*)css ; +/** + * Parse a CSS Selector and return a XPath string. + * + * + * @param css The css selector + * @param error If the parse failed and parser return nil, error is set to last known error. + * @return XPath representation of the given CSS Selector. + */ +-(NSString*)xpathWithCSS:(NSString*)css error:(NSError*__autoreleasing*)error; @end diff --git a/CSSSelectorConverter/CSSSelectorToXPathConverter.m b/CSSSelectorConverter/CSSSelectorToXPathConverter.m index 15cc042..1ca0309 100644 --- a/CSSSelectorConverter/CSSSelectorToXPathConverter.m +++ b/CSSSelectorConverter/CSSSelectorToXPathConverter.m @@ -5,17 +5,23 @@ // Created by Francis Chong on 7/1/14. // Copyright (c) 2014 Ignition Soft. All rights reserved. // -#import "DDLog.h" -#undef LOG_LEVEL_DEF -#define LOG_LEVEL_DEF cssSelectorLogLevel -static const int cssSelectorLogLevel = LOG_LEVEL_VERBOSE; - +#import "CSSSelectorParser.h" #import "CSSSelectorToXPathConverter.h" #import "CSSBaseSelector.h" #import "CSSSelectorXPathVisitor.h" @implementation CSSSelectorToXPathConverter ++(instancetype) sharedConverter +{ + static dispatch_once_t onceToken; + static CSSSelectorToXPathConverter* _converter; + dispatch_once(&onceToken, ^{ + _converter = [[self alloc] init]; + }); + return _converter; +} + -(id) initWithParser:(CSSSelectorParser*)parser { self = [super init]; self.parser = parser; @@ -26,11 +32,15 @@ -(id) init { return [self initWithParser:[[CSSSelectorParser alloc] init]]; } --(NSString*)xpathWithCSS:(NSString*)css { - CSSSelectorGroup* group = [self.parser parse:css]; - CSSSelectorXPathVisitor* visitor = [[CSSSelectorXPathVisitor alloc] init]; - [visitor visit:group]; - return [visitor xpathString]; +-(NSString*)xpathWithCSS:(NSString*)css error:(NSError*__autoreleasing*)error{ + CSSSelectorGroup* group = [self.parser parse:css error:error]; + if (group) { + CSSSelectorXPathVisitor* visitor = [[CSSSelectorXPathVisitor alloc] init]; + [visitor visit:group]; + return [visitor xpathString]; + } else { + return nil; + } } @end diff --git a/CSSSelectorConverter/CSSSelectorTokeniser.h b/CSSSelectorConverter/CSSSelectorTokeniser.h index 65c2558..64c9490 100644 --- a/CSSSelectorConverter/CSSSelectorTokeniser.h +++ b/CSSSelectorConverter/CSSSelectorTokeniser.h @@ -6,8 +6,13 @@ // Copyright (c) 2014 Ignition Soft. All rights reserved. // -#import "CPTokeniser.h" +#import "NUIPTokeniser.h" -@interface CSSSelectorTokeniser : CPTokeniser +/** + * Tokenize the CSS Selector for the CSSSelectorGrammar to consume. + * + * @see CSSSelectorGrammar + */ +@interface CSSSelectorTokeniser : NUIPTokeniser @end diff --git a/CSSSelectorConverter/CSSSelectorTokeniser.m b/CSSSelectorConverter/CSSSelectorTokeniser.m index 4a7908e..d29f6a0 100644 --- a/CSSSelectorConverter/CSSSelectorTokeniser.m +++ b/CSSSelectorConverter/CSSSelectorTokeniser.m @@ -7,57 +7,58 @@ // #import "CSSSelectorTokeniser.h" -#import "CPNumberRecogniser.h" -#import "CPWhiteSpaceRecogniser.h" -#import "CPQuotedRecogniser.h" -#import "CPKeywordRecogniser.h" -#import "CPIdentifierRecogniser.h" +#import "NUIPNumberRecogniser.h" +#import "NUIPWhiteSpaceRecogniser.h" +#import "NUIPQuotedRecogniser.h" +#import "NUIPKeywordRecogniser.h" +#import "NUIPIdentifierRecogniser.h" +#import "NUIPRegexpRecogniser.h" @implementation CSSSelectorTokeniser -(id) init { self = [super init]; - [self addTokenRecogniser:[CPIdentifierRecogniser identifierRecogniser]]; - [self addTokenRecogniser:[CPNumberRecogniser numberRecogniser]]; - [self addTokenRecogniser:[CPQuotedRecogniser quotedRecogniserWithStartQuote:@"\"" + [self addTokenRecogniser:[NUIPIdentifierRecogniser identifierRecogniser]]; + [self addTokenRecogniser:[NUIPNumberRecogniser numberRecogniser]]; + [self addTokenRecogniser:[NUIPQuotedRecogniser quotedRecogniserWithStartQuote:@"\"" endQuote:@"\"" name:@"String"]]; - [self addTokenRecogniser:[CPQuotedRecogniser quotedRecogniserWithStartQuote:@"\'" + [self addTokenRecogniser:[NUIPQuotedRecogniser quotedRecogniserWithStartQuote:@"\'" endQuote:@"\'" name:@"String"]]; - CPRegexpKeywordRecogniserMatchHandler trimSpaceHandler = ^(NSString* tokenString, NSTextCheckingResult* match){ + NUIPRegexpKeywordRecogniserMatchHandler trimSpaceHandler = ^(NSString* tokenString, NSTextCheckingResult* match){ NSString* matched = [tokenString substringWithRange:match.range]; - return [CPKeywordToken tokenWithKeyword:[matched stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; + return [NUIPKeywordToken tokenWithKeyword:[matched stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; }; - [self addTokenRecogniser:[CPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\~\\=)[ \t\r\n\f]*" options:0 error:nil] + [self addTokenRecogniser:[NUIPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\~\\=)[ \t\r\n\f]*" options:0 error:nil] matchHandler:trimSpaceHandler]]; - [self addTokenRecogniser:[CPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\|\\=)[ \t\r\n\f]*" options:0 error:nil] + [self addTokenRecogniser:[NUIPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\|\\=)[ \t\r\n\f]*" options:0 error:nil] matchHandler:trimSpaceHandler]]; - [self addTokenRecogniser:[CPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\=)[ \t\r\n\f]*" options:0 error:nil] + [self addTokenRecogniser:[NUIPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\=)[ \t\r\n\f]*" options:0 error:nil] matchHandler:trimSpaceHandler]]; - [self addTokenRecogniser:[CPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\~)[ \t\r\n\f]*" options:0 error:nil] + [self addTokenRecogniser:[NUIPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\~)[ \t\r\n\f]*" options:0 error:nil] matchHandler:trimSpaceHandler]]; - [self addTokenRecogniser:[CPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\+)[ \t\r\n\f]*" options:0 error:nil] + [self addTokenRecogniser:[NUIPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\+)[ \t\r\n\f]*" options:0 error:nil] matchHandler:trimSpaceHandler]]; - [self addTokenRecogniser:[CPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\>)[ \t\r\n\f]*" options:0 error:nil] + [self addTokenRecogniser:[NUIPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\>)[ \t\r\n\f]*" options:0 error:nil] matchHandler:trimSpaceHandler]]; - [self addTokenRecogniser:[CPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\,)[ \t\r\n\f]*" options:0 error:nil] + [self addTokenRecogniser:[NUIPRegexpRecogniser recogniserForRegexp:[NSRegularExpression regularExpressionWithPattern:@"[ \t\r\n\f]*(\\,)[ \t\r\n\f]*" options:0 error:nil] matchHandler:trimSpaceHandler]]; - [self addTokenRecogniser:[CPWhiteSpaceRecogniser whiteSpaceRecogniser]]; - [self addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@":"]]; - [self addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"."]]; - [self addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"#"]]; - [self addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"-"]]; - [self addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"("]]; - [self addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@")"]]; - [self addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"["]]; - [self addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"]"]]; - [self addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"*"]]; - [self addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"@"]]; + [self addTokenRecogniser:[NUIPWhiteSpaceRecogniser whiteSpaceRecogniser]]; + [self addTokenRecogniser:[NUIPKeywordRecogniser recogniserForKeyword:@":"]]; + [self addTokenRecogniser:[NUIPKeywordRecogniser recogniserForKeyword:@"."]]; + [self addTokenRecogniser:[NUIPKeywordRecogniser recogniserForKeyword:@"#"]]; + [self addTokenRecogniser:[NUIPKeywordRecogniser recogniserForKeyword:@"-"]]; + [self addTokenRecogniser:[NUIPKeywordRecogniser recogniserForKeyword:@"("]]; + [self addTokenRecogniser:[NUIPKeywordRecogniser recogniserForKeyword:@")"]]; + [self addTokenRecogniser:[NUIPKeywordRecogniser recogniserForKeyword:@"["]]; + [self addTokenRecogniser:[NUIPKeywordRecogniser recogniserForKeyword:@"]"]]; + [self addTokenRecogniser:[NUIPKeywordRecogniser recogniserForKeyword:@"*"]]; + [self addTokenRecogniser:[NUIPKeywordRecogniser recogniserForKeyword:@"@"]]; return self; } diff --git a/CSSSelectorConverter/CSSSelectorXPathVisitor.m b/CSSSelectorConverter/CSSSelectorXPathVisitor.m index db4645c..ae625ae 100644 --- a/CSSSelectorConverter/CSSSelectorXPathVisitor.m +++ b/CSSSelectorConverter/CSSSelectorXPathVisitor.m @@ -8,15 +8,20 @@ #import "CSSSelectorXPathVisitor.h" -#import "CSSSelectorGroup.h" #import "CSSUniversalSelector.h" +#import "CSSNamedSelector.h" +#import "CSSTypeSelector.h" #import "CSSIDSelector.h" #import "CSSClassSelector.h" #import "CSSSelectorSequence.h" -#import "CSSPseudoClass.h" -#import "CSSCombinator.h" #import "CSSSelectors.h" +#import "CSSSelectorGroup.h" +#import "CSSSelectorParser.h" #import "CSSSelectorAttribute.h" +#import "CSSNamedSelector.h" +#import "CSSCombinator.h" +#import "CSSNamedSelector.h" +#import "CSSPseudoClass.h" @interface CSSSelectorXPathVisitor() @property (nonatomic, strong) NSMutableString* output; @@ -148,11 +153,12 @@ -(void) visitCSSCombinator:(CSSCombinator*)node -(void) visitCSSSelectors:(CSSSelectors*)node { [node.selectors enumerateObjectsUsingBlock:^(CSSBaseSelector* selector, NSUInteger idx, BOOL *stop) { - if ([selector isKindOfClass:[CSSSelectorSequence class]]) { - // if not specified, the combinator is none - if (idx == 0 || ![[node.selectors objectAtIndex:idx - 1] isKindOfClass:[CSSCombinator class]]) { - [self visit:[CSSCombinator noneCombinator]]; - } + // added NSStringFromClass() to work around for isKindOfClass: match error in unit test + BOOL isSequence = [selector isKindOfClass:[CSSSelectorSequence class]] || [NSStringFromClass([selector class]) isEqualToString:NSStringFromClass([CSSSelectorSequence class])]; + BOOL hasCombinator = idx == 0 || (![[node.selectors objectAtIndex:idx - 1] isKindOfClass:[CSSCombinator class]] && ![NSStringFromClass([[node.selectors objectAtIndex:idx - 1] class]) isEqualToString:NSStringFromClass([CSSCombinator class])]); + + if (isSequence && hasCombinator) { + [self visit:[CSSCombinator noneCombinator]]; } [self visit:selector]; }]; diff --git a/CSSSelectorConverter/CSSSelectors.h b/CSSSelectorConverter/CSSSelectors.h index 76e451e..8808a81 100644 --- a/CSSSelectorConverter/CSSSelectors.h +++ b/CSSSelectorConverter/CSSSelectors.h @@ -7,8 +7,9 @@ // #import "CSSBaseSelector.h" +#import "NUIPParser.h" -@interface CSSSelectors : CSSBaseSelector +@interface CSSSelectors : CSSBaseSelector @property (nonatomic, strong) NSMutableArray* selectors; diff --git a/CSSSelectorConverter/CSSSelectors.m b/CSSSelectorConverter/CSSSelectors.m index c7561d6..1cfc9a1 100644 --- a/CSSSelectorConverter/CSSSelectors.m +++ b/CSSSelectorConverter/CSSSelectors.m @@ -5,19 +5,14 @@ // Created by Francis Chong on 7/1/14. // Copyright (c) 2014 Ignition Soft. All rights reserved. // - -#import "DDLog.h" -#undef LOG_LEVEL_DEF -#define LOG_LEVEL_DEF cssSelectorLogLevel -static const int cssSelectorLogLevel = LOG_LEVEL_VERBOSE; - +#import "NUIParse.h" #import "CSSSelectors.h" #import "CSSCombinator.h" #import "CSSSelectorSequence.h" @implementation CSSSelectors -- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree { +- (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree { self = [self init]; if (self) { CSSSelectorSequence* seq = [syntaxTree valueForTag:@"firstSequence"]; diff --git a/CSSSelectorConverter/CSSTypeSelector.h b/CSSSelectorConverter/CSSTypeSelector.h index c94ba31..1cf2c72 100644 --- a/CSSSelectorConverter/CSSTypeSelector.h +++ b/CSSSelectorConverter/CSSTypeSelector.h @@ -8,7 +8,8 @@ #import #import "CSSNamedSelector.h" +#import "NUIPParser.h" -@interface CSSTypeSelector : CSSNamedSelector +@interface CSSTypeSelector : CSSNamedSelector @end diff --git a/CSSSelectorConverter/CSSTypeSelector.m b/CSSSelectorConverter/CSSTypeSelector.m index e909eee..17e0417 100644 --- a/CSSSelectorConverter/CSSTypeSelector.m +++ b/CSSSelectorConverter/CSSTypeSelector.m @@ -7,15 +7,16 @@ // #import "CSSTypeSelector.h" +#import "NUIParse.h" @implementation CSSTypeSelector -- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree { +- (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree { self = [self init]; if (self) { NSArray *components = [syntaxTree children]; if ([components count] == 1) { - CPIdentifierToken* token = components[0]; + NUIPIdentifierToken* token = components[0]; if ([token isIdentifierToken]) { self.name = [token identifier]; } diff --git a/CSSSelectorConverter/CSSUniversalSelector.h b/CSSSelectorConverter/CSSUniversalSelector.h index b9fc710..3ce7c8e 100644 --- a/CSSSelectorConverter/CSSUniversalSelector.h +++ b/CSSSelectorConverter/CSSUniversalSelector.h @@ -8,7 +8,8 @@ #import #import "CSSTypeSelector.h" +#import "NUIPParser.h" -@interface CSSUniversalSelector : CSSTypeSelector +@interface CSSUniversalSelector : CSSTypeSelector @end diff --git a/CSSSelectorConverter/CSSUniversalSelector.m b/CSSSelectorConverter/CSSUniversalSelector.m index a058ed4..ea0b47f 100644 --- a/CSSSelectorConverter/CSSUniversalSelector.m +++ b/CSSSelectorConverter/CSSUniversalSelector.m @@ -7,10 +7,11 @@ // #import "CSSUniversalSelector.h" +#import "NUIParse.h" @implementation CSSUniversalSelector -- (id)initWithSyntaxTree:(CPSyntaxTree *)syntaxTree { +- (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree { return [self init]; } diff --git a/CSSSelectorConverter/css_selector.grammar b/CSSSelectorConverter/css_selector.grammar deleted file mode 100644 index 4dff65b..0000000 --- a/CSSSelectorConverter/css_selector.grammar +++ /dev/null @@ -1,85 +0,0 @@ -/* -A CSS Selector to XPath Selector Grammar -*/ -@start -@before{ - PKTokenizer *t = self.tokenizer; - [t.symbolState add:@"~="]; - [t.symbolState add:@"|="]; - [t.symbolState add:@":"]; - [t.symbolState add:@"-"]; - [t.wordState setWordChars:NO from:'-' to:'-']; - [t.numberState setAllowsScientificNotation:NO]; - [t.numberState setAllowsTrailingDecimalSeparator:NO]; - -} = selectorsGroup; - -selectorsGroup = selector ( ','! selector )* { - PUSH_SELECTORS_GROUP(); -}; - -selector = simpleSelectorSequence ((combinator { - PUSH_COMBINATOR(); -} simpleSelectorSequence) | simpleSelectorSequence)* { - PUSH_SELECTORS(); -}; - -simpleSelectorSequence = (universalSelector | typeSelector)? (classSelector | idSelector | attributeSelector | pseudoSelector)* { - PUSH_SELECTOR_SEQUENCE(); -}; - -attributeSelector = '['! Word (Empty | ((equal | includes | dashmatch) QuotedString )) ']'! { - PUSH_ATTRIBUTE(); -}; - -/* disabled pseudo selector with params */ -pseudoSelector = ':'! ( /*(paramPseudoSelector) | */ pseudoSelectorName { - PUSH_PSEUDO_CLASS(); -}); - -paramPseudoSelector = paramPseudoSelectorName '('! paramPseudoSelectorParam ')'! { - PUSH_NTH_CHILD(); -}; - -paramPseudoSelectorParam = ( sign? Number? nthChildConstant (sign? Number)? ) | Number | even | odd ; - -dimension = Number Word; - -classSelector = '.'! Word { - PUSH_CSS_CLASS(POP_STR()); -}; - -idSelector = '#'! Word { - PUSH_CSS_ID(POP_STR()); -}; - -typeSelector = Word { - PUSH_CSS_TYPE(POP_STR()); -}; - -universalSelector = '*'! { - PUSH_CSS_UNIVERSAL(); -}; - -paramPseudoSelectorName = nthConstant minus last minus child | nthConstant minus last minus of minus type | nthConstant minus of minus type | nthConstant minus child; -pseudoSelectorName = first minus child | last minus child | first minus of minus type | last minus of minus type | - only minus child | only minus of minus type | empty; - -nthChildConstant = 'n'; -first = 'first'; -last = 'last'; -child = 'child'; -type = 'type'; -of = 'of'; -only = 'only'; -empty = 'empty'; -nthConstant = 'nth'; -odd = 'odd'; -even = 'even'; -combinator = '>' | '~' | plus; -sign = minus | plus; -plus = '+'; -minus = '-'; -equal = "="; -includes = "~="; -dashmatch = "|="; \ No newline at end of file diff --git a/CSSSelectorConverterTests/CSSSelectorParserSpec.m b/CSSSelectorConverterTests/CSSSelectorParserSpec.m index 35ecbb1..ed51623 100644 --- a/CSSSelectorConverterTests/CSSSelectorParserSpec.m +++ b/CSSSelectorConverterTests/CSSSelectorParserSpec.m @@ -8,15 +8,27 @@ #import #import "CSSSelectorParser.h" +#import "NUIParse.h" +#import "CSSSelectorGrammar.h" +#import "CSSSelectorTokeniser.h" SPEC_BEGIN(CSSSelectorParserSpec) describe(@"CSSSelectorParser", ^{ - it(@"parse css", ^{ - CSSSelectorParser *parser = [[CSSSelectorParser alloc] init]; - CSSSelectorGroup* tree = [parser parse:@"table:first-child"]; - [[tree shouldNot] beNil]; - NSLog(@"result = %@", tree); + context(@"serialization", ^{ + xit(@"should serialize and deserialize a parser", ^{ + CSSSelectorTokeniser* tokenizer1 = [[CSSSelectorTokeniser alloc] init]; + CSSSelectorTokeniser* tokenizer2 = [[CSSSelectorTokeniser alloc] init]; + + NUIPLALR1Parser* parser1 = [NUIPLALR1Parser parserWithGrammar:[[CSSSelectorGrammar alloc] initWithPath:[[NSBundle bundleForClass:[self class]] pathForResource:@"CSSSelectorGrammar" ofType:@"txt"]]]; + NUIPSyntaxTree* result1 = [parser1 parse:[tokenizer1 tokenise:@"title .article"]]; + + NSData* data = [NSKeyedArchiver archivedDataWithRootObject:parser1]; + NUIPLALR1Parser *parser2 = [NSKeyedUnarchiver unarchiveObjectWithData:data]; + NUIPSyntaxTree* result2 = [parser2 parse:[tokenizer2 tokenise:@"title .article"]]; + + [[result1 should] equal:result2]; + }); }); }); diff --git a/CSSSelectorConverterTests/CSSSelectorTokeniserSpec.m b/CSSSelectorConverterTests/CSSSelectorTokeniserSpec.m index 0af7751..f7d4a76 100644 --- a/CSSSelectorConverterTests/CSSSelectorTokeniserSpec.m +++ b/CSSSelectorConverterTests/CSSSelectorTokeniserSpec.m @@ -8,126 +8,126 @@ #import #import "CSSSelectorTokeniser.h" - +#import "NUIParse.h" SPEC_BEGIN(CSSSelectorTokeniserSpec) describe(@"CSSSelectorTokeniser", ^{ it(@"tokenize basic css", ^{ CSSSelectorTokeniser* tokeniser = [[CSSSelectorTokeniser alloc] init]; - CPTokenStream *tokenStream = [tokeniser tokenise:@"table"]; - CPTokenStream *expected = [CPTokenStream tokenStreamWithTokens:[NSArray arrayWithObjects: - [CPIdentifierToken tokenWithIdentifier:@"table"], - [CPEOFToken eof], + NUIPTokenStream *tokenStream = [tokeniser tokenise:@"table"]; + NUIPTokenStream *expected = [NUIPTokenStream tokenStreamWithTokens:[NSArray arrayWithObjects: + [NUIPIdentifierToken tokenWithIdentifier:@"table"], + [NUIPEOFToken eof], nil]]; [[tokenStream should] equal:expected]; tokenStream = [tokeniser tokenise:@"table.a"]; - expected = [CPTokenStream tokenStreamWithTokens:@[ - [CPIdentifierToken tokenWithIdentifier:@"table"], - [CPKeywordToken tokenWithKeyword:@"."], - [CPIdentifierToken tokenWithIdentifier:@"a"], - [CPEOFToken eof] + expected = [NUIPTokenStream tokenStreamWithTokens:@[ + [NUIPIdentifierToken tokenWithIdentifier:@"table"], + [NUIPKeywordToken tokenWithKeyword:@"."], + [NUIPIdentifierToken tokenWithIdentifier:@"a"], + [NUIPEOFToken eof] ]]; [[tokenStream should] equal:expected]; }); it(@"tokenize complex selector", ^{ CSSSelectorTokeniser* tokeniser = [[CSSSelectorTokeniser alloc] init]; - CPTokenStream *tokenStream = [tokeniser tokenise:@"table a"]; - CPTokenStream *expected = [CPTokenStream tokenStreamWithTokens:@[ - [CPIdentifierToken tokenWithIdentifier:@"table"], - [CPWhiteSpaceToken whiteSpace:@" "], - [CPIdentifierToken tokenWithIdentifier:@"a"], - [CPEOFToken eof] + NUIPTokenStream *tokenStream = [tokeniser tokenise:@"table a"]; + NUIPTokenStream *expected = [NUIPTokenStream tokenStreamWithTokens:@[ + [NUIPIdentifierToken tokenWithIdentifier:@"table"], + [NUIPWhiteSpaceToken whiteSpace:@" "], + [NUIPIdentifierToken tokenWithIdentifier:@"a"], + [NUIPEOFToken eof] ]]; [[tokenStream should] equal:expected]; tokenStream = [tokeniser tokenise:@"table > a"]; - expected = [CPTokenStream tokenStreamWithTokens:@[ - [CPIdentifierToken tokenWithIdentifier:@"table"], - [CPKeywordToken tokenWithKeyword:@">"], - [CPIdentifierToken tokenWithIdentifier:@"a"], - [CPEOFToken eof] + expected = [NUIPTokenStream tokenStreamWithTokens:@[ + [NUIPIdentifierToken tokenWithIdentifier:@"table"], + [NUIPKeywordToken tokenWithKeyword:@">"], + [NUIPIdentifierToken tokenWithIdentifier:@"a"], + [NUIPEOFToken eof] ]]; [[tokenStream should] equal:expected]; tokenStream = [tokeniser tokenise:@"table ~ a"]; - expected = [CPTokenStream tokenStreamWithTokens:@[ - [CPIdentifierToken tokenWithIdentifier:@"table"], - [CPKeywordToken tokenWithKeyword:@"~"], - [CPIdentifierToken tokenWithIdentifier:@"a"], - [CPEOFToken eof] + expected = [NUIPTokenStream tokenStreamWithTokens:@[ + [NUIPIdentifierToken tokenWithIdentifier:@"table"], + [NUIPKeywordToken tokenWithKeyword:@"~"], + [NUIPIdentifierToken tokenWithIdentifier:@"a"], + [NUIPEOFToken eof] ]]; [[tokenStream should] equal:expected]; tokenStream = [tokeniser tokenise:@"table ~ a"]; - expected = [CPTokenStream tokenStreamWithTokens:@[ - [CPIdentifierToken tokenWithIdentifier:@"table"], - [CPKeywordToken tokenWithKeyword:@"~"], - [CPIdentifierToken tokenWithIdentifier:@"a"], - [CPEOFToken eof] + expected = [NUIPTokenStream tokenStreamWithTokens:@[ + [NUIPIdentifierToken tokenWithIdentifier:@"table"], + [NUIPKeywordToken tokenWithKeyword:@"~"], + [NUIPIdentifierToken tokenWithIdentifier:@"a"], + [NUIPEOFToken eof] ]]; [[tokenStream should] equal:expected]; tokenStream = [tokeniser tokenise:@"table , a"]; - expected = [CPTokenStream tokenStreamWithTokens:@[ - [CPIdentifierToken tokenWithIdentifier:@"table"], - [CPKeywordToken tokenWithKeyword:@","], - [CPIdentifierToken tokenWithIdentifier:@"a"], - [CPEOFToken eof] + expected = [NUIPTokenStream tokenStreamWithTokens:@[ + [NUIPIdentifierToken tokenWithIdentifier:@"table"], + [NUIPKeywordToken tokenWithKeyword:@","], + [NUIPIdentifierToken tokenWithIdentifier:@"a"], + [NUIPEOFToken eof] ]]; [[tokenStream should] equal:expected]; }); it(@"tokenize pseudo class", ^{ CSSSelectorTokeniser* tokeniser = [[CSSSelectorTokeniser alloc] init]; - CPTokenStream *tokenStream = [tokeniser tokenise:@"div > p:first-child"]; - CPTokenStream *expected = [CPTokenStream tokenStreamWithTokens:@[ - [CPIdentifierToken tokenWithIdentifier:@"div"], - [CPKeywordToken tokenWithKeyword:@">"], - [CPIdentifierToken tokenWithIdentifier:@"p"], - [CPKeywordToken tokenWithKeyword:@":"], - [CPIdentifierToken tokenWithIdentifier:@"first-child"], - [CPEOFToken eof]]]; + NUIPTokenStream *tokenStream = [tokeniser tokenise:@"div > p:first-child"]; + NUIPTokenStream *expected = [NUIPTokenStream tokenStreamWithTokens:@[ + [NUIPIdentifierToken tokenWithIdentifier:@"div"], + [NUIPKeywordToken tokenWithKeyword:@">"], + [NUIPIdentifierToken tokenWithIdentifier:@"p"], + [NUIPKeywordToken tokenWithKeyword:@":"], + [NUIPIdentifierToken tokenWithIdentifier:@"first-child"], + [NUIPEOFToken eof]]]; [[tokenStream should] equal:expected]; }); it(@"tokenize attribute", ^{ CSSSelectorTokeniser* tokeniser = [[CSSSelectorTokeniser alloc] init]; - CPTokenStream *tokenStream = [tokeniser tokenise:@"div[class~=\"100\"]"]; - CPTokenStream *expected = [CPTokenStream tokenStreamWithTokens:[NSArray arrayWithObjects: - [CPIdentifierToken tokenWithIdentifier:@"div"], - [CPKeywordToken tokenWithKeyword:@"["], - [CPIdentifierToken tokenWithIdentifier:@"class"], - [CPKeywordToken tokenWithKeyword:@"~="], - [CPQuotedToken content:@"100" quotedWith:@"\"" name:@"String"], - [CPKeywordToken tokenWithKeyword:@"]"], - [CPEOFToken eof], + NUIPTokenStream *tokenStream = [tokeniser tokenise:@"div[class~=\"100\"]"]; + NUIPTokenStream *expected = [NUIPTokenStream tokenStreamWithTokens:[NSArray arrayWithObjects: + [NUIPIdentifierToken tokenWithIdentifier:@"div"], + [NUIPKeywordToken tokenWithKeyword:@"["], + [NUIPIdentifierToken tokenWithIdentifier:@"class"], + [NUIPKeywordToken tokenWithKeyword:@"~="], + [NUIPQuotedToken content:@"100" quotedWith:@"\"" name:@"String"], + [NUIPKeywordToken tokenWithKeyword:@"]"], + [NUIPEOFToken eof], nil]]; [[tokenStream should] equal:expected]; tokenStream = [tokeniser tokenise:@"div[class |= \"100\"]"]; - expected = [CPTokenStream tokenStreamWithTokens:[NSArray arrayWithObjects: - [CPIdentifierToken tokenWithIdentifier:@"div"], - [CPKeywordToken tokenWithKeyword:@"["], - [CPIdentifierToken tokenWithIdentifier:@"class"], - [CPKeywordToken tokenWithKeyword:@"|="], - [CPQuotedToken content:@"100" quotedWith:@"\"" name:@"String"], - [CPKeywordToken tokenWithKeyword:@"]"], - [CPEOFToken eof], + expected = [NUIPTokenStream tokenStreamWithTokens:[NSArray arrayWithObjects: + [NUIPIdentifierToken tokenWithIdentifier:@"div"], + [NUIPKeywordToken tokenWithKeyword:@"["], + [NUIPIdentifierToken tokenWithIdentifier:@"class"], + [NUIPKeywordToken tokenWithKeyword:@"|="], + [NUIPQuotedToken content:@"100" quotedWith:@"\"" name:@"String"], + [NUIPKeywordToken tokenWithKeyword:@"]"], + [NUIPEOFToken eof], nil]]; [[tokenStream should] equal:expected]; tokenStream = [tokeniser tokenise:@"div[class = '100']"]; - expected = [CPTokenStream tokenStreamWithTokens:[NSArray arrayWithObjects: - [CPIdentifierToken tokenWithIdentifier:@"div"], - [CPKeywordToken tokenWithKeyword:@"["], - [CPIdentifierToken tokenWithIdentifier:@"class"], - [CPKeywordToken tokenWithKeyword:@"="], - [CPQuotedToken content:@"100" quotedWith:@"'" name:@"String"], - [CPKeywordToken tokenWithKeyword:@"]"], - [CPEOFToken eof], + expected = [NUIPTokenStream tokenStreamWithTokens:[NSArray arrayWithObjects: + [NUIPIdentifierToken tokenWithIdentifier:@"div"], + [NUIPKeywordToken tokenWithKeyword:@"["], + [NUIPIdentifierToken tokenWithIdentifier:@"class"], + [NUIPKeywordToken tokenWithKeyword:@"="], + [NUIPQuotedToken content:@"100" quotedWith:@"'" name:@"String"], + [NUIPKeywordToken tokenWithKeyword:@"]"], + [NUIPEOFToken eof], nil]]; [[tokenStream should] equal:expected]; }); diff --git a/CSSSelectorConverterTests/CSSSelectorXPathVisitorSpec.m b/CSSSelectorConverterTests/CSSSelectorXPathVisitorSpec.m index c97c1cf..7293f74 100644 --- a/CSSSelectorConverterTests/CSSSelectorXPathVisitorSpec.m +++ b/CSSSelectorConverterTests/CSSSelectorXPathVisitorSpec.m @@ -18,6 +18,7 @@ #import "CSSCombinator.h" #import "CSSSelectorAttribute.h" #import "CSSSelectorAttributeOperator.h" +#import "NUIParse.h" SPEC_BEGIN(CSSSelectorXPathVisitorSpec) diff --git a/CSSSelectorConverterTests/CSSToXPathConverterSpec.m b/CSSSelectorConverterTests/CSSToXPathConverterSpec.m index dcbe4cf..6f4a4c2 100644 --- a/CSSSelectorConverterTests/CSSToXPathConverterSpec.m +++ b/CSSSelectorConverterTests/CSSToXPathConverterSpec.m @@ -10,6 +10,7 @@ #import "DDLog.h" #import "DDTTYLogger.h" #import "CSSSelectorConverter.h" +#import "NUIParse.h" SPEC_BEGIN(CSSToXPathConverterSpec) __block CSSSelectorToXPathConverter *converter; @@ -29,94 +30,99 @@ }); it(@"should parse universal selector", ^{ - NSString* css = [converter xpathWithCSS:@"*"]; + NSString* css = [converter xpathWithCSS:@"*" error:nil]; [[css should] equal:@"//*"]; }); it(@"should parse type selector", ^{ - NSString* css = [converter xpathWithCSS:@"p"]; + NSString* css = [converter xpathWithCSS:@"p" error:nil]; [[css should] equal:@"//p"]; }); + + it(@"should parse multiple type selector", ^{ + NSString* css = [converter xpathWithCSS:@"h3 strong a, #fbPhotoPageAuthorName, title" error:nil]; + [[css should] equal:@"//h3//strong//a | //*[@id = 'fbPhotoPageAuthorName'] | //title"]; + }); it(@"should parse id selector", ^{ - NSString* css = [converter xpathWithCSS:@"#header"]; + NSString* css = [converter xpathWithCSS:@"#header" error:nil]; [[css should] equal:@"//*[@id = 'header']"]; }); it(@"should parse class selector", ^{ - NSString* css = [converter xpathWithCSS:@".header"]; + NSString* css = [converter xpathWithCSS:@".header" error:nil]; [[css should] equal:@"//*[contains(concat(' ', normalize-space(@class), ' '), ' header ')]"]; }); it(@"should parse type with mixed class and id selector", ^{ - NSString* css = [converter xpathWithCSS:@"p#header.red"]; + NSString* css = [converter xpathWithCSS:@"p#header.red" error:nil]; [[css should] equal:@"//p[@id = 'header' and contains(concat(' ', normalize-space(@class), ' '), ' red ')]"]; }); it(@"should parse simple selector sequence", ^{ - NSString* css = [converter xpathWithCSS:@"div p"]; + NSString* css = [converter xpathWithCSS:@"div p" error:nil]; [[css should] equal:@"//div//p"]; - css = [converter xpathWithCSS:@"div *"]; + css = [converter xpathWithCSS:@"div *" error:nil]; [[css should] equal:@"//div//*"]; - css = [converter xpathWithCSS:@"div#main p"]; + css = [converter xpathWithCSS:@"div#main p" error:nil]; [[css should] equal:@"//div[@id = 'main']//p"]; }); it(@"should parse descendant selector sequence", ^{ - NSString* descendantCss = [converter xpathWithCSS:@"div#main p > a"]; + NSString* descendantCss = [converter xpathWithCSS:@"div#main p > a" error:nil]; [[descendantCss should] equal:@"//div[@id = 'main']//p/a"]; - descendantCss = [converter xpathWithCSS:@"div#main p > a p > div"]; + descendantCss = [converter xpathWithCSS:@"div#main p > a p > div" error:nil]; [[descendantCss shouldNot] beNil]; [[descendantCss should] equal:@"//div[@id = 'main']//p/a//p/div"]; }); it(@"should parse adjacent selector sequence", ^{ - NSString* adjacentCss = [converter xpathWithCSS:@"h1 ~ p"]; + NSString* adjacentCss = [converter xpathWithCSS:@"h1 ~ p" error:nil]; [[adjacentCss should] equal:@"//h1/following-sibling::p"]; }); it(@"should parse selector group", ^{ - NSString* css = [converter xpathWithCSS:@"div, p"]; + NSString* css = [converter xpathWithCSS:@"div, p" error:nil]; [[css should] equal:@"//div | //p"]; }); it(@"should parse attribute", ^{ - NSString* css = [converter xpathWithCSS:@"div[foo]"]; + NSString* css = [converter xpathWithCSS:@"div[foo]" error:nil]; [[css should] equal:@"//div[@foo]"]; - NSString* cssWithValue = [converter xpathWithCSS:@"div[width=\"100\"]"]; + NSString* cssWithValue = [converter xpathWithCSS:@"div[width=\"100\"]" error:nil]; [[cssWithValue should] equal:@"//div[@width = \"100\"]"]; - NSString* cssWithIncludesValue = [converter xpathWithCSS:@"div[class~=\"100\"]"]; + NSString* cssWithIncludesValue = [converter xpathWithCSS:@"div[class~=\"100\"]" error:nil]; [[cssWithIncludesValue should] equal:@"//div[contains(concat(\" \", @class, \" \"),concat(\" \", \"100\", \" \"))]"]; - NSString* cssWithDashValue = [converter xpathWithCSS:@"div[att|=\"val\"]"]; + NSString* cssWithDashValue = [converter xpathWithCSS:@"div[att|=\"val\"]" error:nil]; [[cssWithDashValue should] equal:@"//div[@att = \"val\" or starts-with(@att, concat(\"val\", '-'))]"]; }); it(@"should parse pseudo class", ^{ - NSString* firstChild = [converter xpathWithCSS:@"div > p:first-child"]; + NSString* firstChild = [converter xpathWithCSS:@"div > p:first-child" error:nil]; [[firstChild should] equal:@"//div/*[position() = 1 and self::p]"]; - NSString* lastChild = [converter xpathWithCSS:@"ol > li:last-child"]; + NSString* lastChild = [converter xpathWithCSS:@"ol > li:last-child" error:nil]; [[lastChild should] equal:@"//ol/*[position() = last() and self::li]"]; - NSString* firstOfType = [converter xpathWithCSS:@"dl dt:first-of-type"]; + NSString* firstOfType = [converter xpathWithCSS:@"dl dt:first-of-type" error:nil]; [[firstOfType should] equal:@"//dl//dt[position() = 1]"]; - NSString* lastOfType = [converter xpathWithCSS:@"tr > td:last-of-type"]; + NSString* lastOfType = [converter xpathWithCSS:@"tr > td:last-of-type" error:nil]; [[lastOfType should] equal:@"//tr/td[position() = last()]"]; - NSString* onlyChild = [converter xpathWithCSS:@"p:only-child"]; + NSString* onlyChild = [converter xpathWithCSS:@"p:only-child" error:nil]; [[onlyChild should] equal:@"//*[last() = 1 and self::p]"]; - NSString* onlyOfType = [converter xpathWithCSS:@"p:only-of-type"]; + NSString* onlyOfType = [converter xpathWithCSS:@"p:only-of-type" error:nil]; [[onlyOfType should] equal:@"//p[last() = 1]"]; - NSString* empty = [converter xpathWithCSS:@"div:empty"]; + NSString* empty = [converter xpathWithCSS:@"div:empty" error:nil]; [[empty should] equal:@"//div[not(node())]"]; }); diff --git a/Podfile b/Podfile index 7574807..f299695 100644 --- a/Podfile +++ b/Podfile @@ -1,7 +1,8 @@ platform :ios, '7.0' -pod 'CocoaLumberjack' +pod 'CocoaLumberjack', '~> 2.0' +pod 'NUIParse' target :'CSSSelectorConverterTests' do - pod 'Kiwi/XCTest' + pod 'Kiwi', '>= 2.3.0' end \ No newline at end of file diff --git a/Podfile.lock b/Podfile.lock index 0cadf74..4a3c844 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,22 +1,23 @@ PODS: - - CocoaLumberjack (1.7.0): + - CocoaLumberjack (2.2.0): + - CocoaLumberjack/Default (= 2.2.0) + - CocoaLumberjack/Extensions (= 2.2.0) + - CocoaLumberjack/Core (2.2.0) + - CocoaLumberjack/Default (2.2.0): - CocoaLumberjack/Core - - CocoaLumberjack/Extensions - - CocoaLumberjack/Core (1.7.0) - - CocoaLumberjack/Extensions (1.7.0): - - CocoaLumberjack/Core - - Kiwi/ARC (2.2.3) - - Kiwi/NonARC (2.2.3) - - Kiwi/XCTest (2.2.3): - - Kiwi/ARC - - Kiwi/NonARC + - CocoaLumberjack/Extensions (2.2.0): + - CocoaLumberjack/Default + - Kiwi (2.4.0) + - NUIParse (1.3) DEPENDENCIES: - - CocoaLumberjack - - Kiwi/XCTest + - CocoaLumberjack (~> 2.0) + - Kiwi (>= 2.3.0) + - NUIParse SPEC CHECKSUMS: - CocoaLumberjack: be87113f649942f020a37c061c58009b6ee5ff68 - Kiwi: 04c51e880831d291748ec702d42c4101f7eb95c9 + CocoaLumberjack: 17fe8581f84914d5d7e6360f7c70022b173c3ae0 + Kiwi: f49c9d54b28917df5928fe44968a39ed198cb8a8 + NUIParse: 2e3885ba7807477266396292626bd387d34c2338 -COCOAPODS: 0.29.0 +COCOAPODS: 0.39.0 diff --git a/README.md b/README.md index d8c6273..b6982da 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ I build this converter so that I can use `.class` instead of `//*[contains(conca ```objective-c #import "CSSSelectorConverter.h" -CSSToXPathConverter* converter = [[CSSToXPathConverter alloc] init]; +CSSSelectorToXPathConverter* converter = [[CSSSelectorToXPathConverter alloc] init]; [converter xpathWithCSS:@"p" error:nil]; // => "//p" @@ -62,6 +62,13 @@ Following pseduo classes will not be supported: - :lang - :root +## Development + +### Building the project + +1. Install cocoapods +2. Install pods: ``pod install`` + ## License MIT License. See License.txt. \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..3f09fd4 --- /dev/null +++ b/Rakefile @@ -0,0 +1,7 @@ +require 'rubygems' +require 'rake' + +desc "Run tests" +task :test do + system("xcodebuild -workspace CSSSelectorConverter.xcworkspace -scheme CSSSelectorConverter -sdk iphonesimulator test") +end \ No newline at end of file diff --git a/bin/CSSSelectorParserGenerator.m b/bin/CSSSelectorParserGenerator.m new file mode 100644 index 0000000..22b0ee2 --- /dev/null +++ b/bin/CSSSelectorParserGenerator.m @@ -0,0 +1,32 @@ +/* + podfile-start + platform :osx, '10.9' + pod 'CSSSelectorConverter', :local => '/Users/siuying/workspace/opensource/CSSSelectorConverter' + podfile-end + */ + +#include +@import Foundation; +#import "CSSSelectorConverter.h" +#import "CSSSelectorGrammar.h" +#import "CPLALR1Parser.h" + +int main(int argc, const char * argv[]) +{ + @autoreleasepool { + if (argc >= 3) + { + NSString* grammaFile = [[NSString stringWithCString:argv[1] encoding:NSASCIIStringEncoding] stringByExpandingTildeInPath]; + NSString* outputFile = [[NSString stringWithCString:argv[2] encoding:NSASCIIStringEncoding] stringByExpandingTildeInPath]; + CSSSelectorGrammar* grammar = [[CSSSelectorGrammar alloc] initWithPath:grammaFile]; + CPLALR1Parser* parser1 = [CPLALR1Parser parserWithGrammar:grammar]; + [NSKeyedArchiver archiveRootObject:@{@"parser" : parser1} + toFile:outputFile]; + } + else + { + NSLog(@"Usage: CSSSelectorParserGenerator "); + } + } +} + diff --git a/vendor/CoreParse b/vendor/CoreParse deleted file mode 160000 index 034f0dc..0000000 --- a/vendor/CoreParse +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 034f0dc33c82aaf7a38b623d0e9552291268c71e