├── CSSSelectorConverter
├── en.lproj
│ └── InfoPlist.strings
├── CSSSelectorParser.plist
├── IGMasterViewController.h
├── CSSBaseSelector.h
├── CSSSelectorConverter.h
├── IGAppDelegate.h
├── CSSIDSelector.h
├── CSSTypeSelector.h
├── CSSClassSelector.h
├── CSSUniversalSelector.h
├── CSSPseudoClass.h
├── CSSSelectorConverter-Prefix.pch
├── main.m
├── CSSSelectorTokeniser.h
├── CSSBaseSelector.m
├── IGDetailViewController.h
├── CSSNamedSelector.h
├── Images.xcassets
│ ├── AppIcon.appiconset
│ │ └── Contents.json
│ └── LaunchImage.launchimage
│ │ └── Contents.json
├── CSSSelectorGroup.h
├── CSSNamedSelector.m
├── CSSSelectorAttribute.h
├── CSSSelectorGrammar.h
├── CSSSelectors.h
├── CSSCombinator.h
├── CSSPseudoClass.m
├── CSSUniversalSelector.m
├── CSSSelectorSequence.h
├── CSSSelectorAttributeOperator.h
├── CSSIDSelector.m
├── CSSTypeSelector.m
├── CSSClassSelector.m
├── CSSSelectorXPathVisitor.h
├── CSSSelectorToXPathConverter.h
├── CSSSelectorAttribute.m
├── IGDetailViewController.m
├── CSSSelectorParser.h
├── CSSSelectorToXPathConverter.m
├── CSSSelectorGroup.m
├── CSSSelectorConverter-Info.plist
├── CSSSelectorGrammar.txt
├── CSSSelectorGrammar.m
├── CSSSelectors.m
├── CSSSelectorAttributeOperator.m
├── IGAppDelegate.m
├── CSSSelectorSequence.m
├── CSSCombinator.m
├── CSSSelectorParser.m
├── IGMasterViewController.m
├── CSSSelectorTokeniser.m
├── CSSSelectorXPathVisitor.m
└── Base.lproj
│ └── Main.storyboard
├── CSSSelectorConverterTests
├── en.lproj
│ └── InfoPlist.strings
├── CSSSelectorConverterTests-Info.plist
├── CSSSelectorParserSpec.m
├── CSSToXPathConverterSpec.m
├── CSSSelectorXPathVisitorSpec.m
└── CSSSelectorTokeniserSpec.m
├── .gitignore
├── Podfile
├── Rakefile
├── CSSSelectorConverter.xcworkspace
├── contents.xcworkspacedata
└── xcshareddata
│ ├── CSSSelectorConverter.xcscmblueprint
│ └── CSSSelectorConverter.xccheckout
├── CSSSelectorConverter.xcodeproj
├── project.xcworkspace
│ └── contents.xcworkspacedata
├── xcshareddata
│ └── xcschemes
│ │ └── CSSSelectorConverter.xcscheme
└── project.pbxproj
├── .travis.yml
├── CHANGELOG.md
├── Podfile.lock
├── LICENSE.txt
├── bin
└── CSSSelectorParserGenerator.m
├── CSSSelectorConverter.podspec
└── README.md
/CSSSelectorConverter/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/CSSSelectorConverterTests/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | Pods
3 | CSSSelectorConverter.xcodeproj/xcuserdata
4 | CSSSelectorConverter.xcworkspace/xcuserdata
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectorParser.plist:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/siuying/CSSSelectorConverter/HEAD/CSSSelectorConverter/CSSSelectorParser.plist
--------------------------------------------------------------------------------
/Podfile:
--------------------------------------------------------------------------------
1 | platform :ios, '7.0'
2 |
3 | pod 'CocoaLumberjack', '~> 2.0'
4 | pod 'NUIParse'
5 |
6 | target :'CSSSelectorConverterTests' do
7 | pod 'Kiwi', '>= 2.3.0'
8 | end
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rake'
3 |
4 | desc "Run tests"
5 | task :test do
6 | system("xcodebuild -workspace CSSSelectorConverter.xcworkspace -scheme CSSSelectorConverter -sdk iphonesimulator test")
7 | end
--------------------------------------------------------------------------------
/CSSSelectorConverter.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/CSSSelectorConverter.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | rvm: 2.2.3
2 | language: objective-c
3 | before_script:
4 | - export LANG=en_US.UTF-8
5 | - gem install xcpretty cocoapods
6 | - pod install
7 | script: xcodebuild -workspace CSSSelectorConverter.xcworkspace -scheme CSSSelectorConverter -sdk iphonesimulator test | xcpretty -c; exit ${PIPESTATUS[0]}
8 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/IGMasterViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // IGMasterViewController.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface IGMasterViewController : UITableViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSBaseSelector.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSBaseSelector.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface CSSBaseSelector : NSObject
12 |
13 | +(instancetype) selector;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectorConverter.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSSelectorConverter.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Chong Francis on 14年1月8日.
6 | // Copyright (c) 2014年 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #ifndef _CSSSelectorConverter_
10 | #define _CSSSelectorConverter_
11 |
12 | #import "CSSSelectorToXPathConverter.h"
13 | #endif
14 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/IGAppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // IGAppDelegate.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface IGAppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSIDSelector.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSIDSelector.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "CSSNamedSelector.h"
11 | #import "NUIPParser.h"
12 |
13 | @interface CSSIDSelector : CSSNamedSelector
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSTypeSelector.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSTypeSelector.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "CSSNamedSelector.h"
11 | #import "NUIPParser.h"
12 |
13 | @interface CSSTypeSelector : CSSNamedSelector
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSClassSelector.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSClassSelector.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "CSSNamedSelector.h"
11 | #import "NUIPParser.h"
12 |
13 | @interface CSSClassSelector : CSSNamedSelector
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSUniversalSelector.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSUniversalSelector.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "CSSTypeSelector.h"
11 | #import "NUIPParser.h"
12 |
13 | @interface CSSUniversalSelector : CSSTypeSelector
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSPseudoClass.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSPseudoClass.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Chong Francis on 14年1月8日.
6 | // Copyright (c) 2014年 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSNamedSelector.h"
10 | #import "NUIPParser.h"
11 |
12 | @interface CSSPseudoClass : CSSNamedSelector
13 |
14 | @property (nonatomic, weak) CSSNamedSelector* parent;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectorConverter-Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header
3 | //
4 | // The contents of this file are implicitly included at the beginning of every source file.
5 | //
6 |
7 | #import
8 |
9 | #ifndef __IPHONE_5_0
10 | #warning "This project uses features only available in iOS SDK 5.0 and later."
11 | #endif
12 |
13 | #ifdef __OBJC__
14 | #import
15 | #import
16 | #endif
--------------------------------------------------------------------------------
/CSSSelectorConverter/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import "IGAppDelegate.h"
12 |
13 | int main(int argc, char * argv[])
14 | {
15 | @autoreleasepool {
16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([IGAppDelegate class]));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectorTokeniser.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSSelectorTokeniser.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 1/20/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "NUIPTokeniser.h"
10 |
11 | /**
12 | * Tokenize the CSS Selector for the CSSSelectorGrammar to consume.
13 | *
14 | * @see CSSSelectorGrammar
15 | */
16 | @interface CSSSelectorTokeniser : NUIPTokeniser
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSBaseSelector.m:
--------------------------------------------------------------------------------
1 | //
2 | // CSSBaseSelector.m
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSBaseSelector.h"
10 |
11 | @implementation CSSBaseSelector
12 |
13 | -(NSString*) description {
14 | return @"";
15 | }
16 |
17 | +(instancetype) selector {
18 | return [[self alloc] init];
19 | }
20 |
21 | @end
22 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/IGDetailViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // IGDetailViewController.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface IGDetailViewController : UIViewController
12 |
13 | @property (strong, nonatomic) id detailItem;
14 |
15 | @property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
16 | @end
17 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSNamedSelector.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSNamedSelector.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "CSSBaseSelector.h"
11 |
12 | @interface CSSNamedSelector : CSSBaseSelector
13 |
14 | @property (nonatomic, copy) NSString* name;
15 |
16 | +(instancetype) selectorWithName:(NSString*)name;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "40x40",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "60x60",
16 | "scale" : "2x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectorGroup.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSSelectorGroup.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Chong Francis on 14年1月8日.
6 | // Copyright (c) 2014年 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSBaseSelector.h"
10 | #import "CSSSelectors.h"
11 | #import "NUIPParser.h"
12 |
13 | @interface CSSSelectorGroup : CSSBaseSelector
14 |
15 | @property (nonatomic, strong) NSMutableArray* selectors;
16 |
17 | -(void) addSelectors:(CSSSelectors*)selectors;
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Changelog
2 | ---------
3 |
4 | 1.2.1
5 | -----
6 |
7 | - Added [CSSSelectorToXPathConverter sharedConverter].
8 |
9 | 1.2.0
10 | -----
11 |
12 | - Update podspec to only expose minimal files.
13 |
14 | 1.1.2
15 | -----
16 |
17 | - Use NUIParse.
18 |
19 | 1.1.0 (28/01/2014)
20 | ------------------
21 |
22 | - Fix #1, properly handle selector sequence.
23 | * Use [CoreParse](https://github.com/beelsebob/CoreParse) instead of [ParseKit](https://github.com/itod/parsekit) as parser generator.
24 |
25 | 1.0.0 (09/01/2014)
26 | --------------
27 |
28 | + Initial version.
--------------------------------------------------------------------------------
/CSSSelectorConverter/Images.xcassets/LaunchImage.launchimage/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "orientation" : "portrait",
5 | "idiom" : "iphone",
6 | "extent" : "full-screen",
7 | "minimum-system-version" : "7.0",
8 | "scale" : "2x"
9 | },
10 | {
11 | "orientation" : "portrait",
12 | "idiom" : "iphone",
13 | "subtype" : "retina4",
14 | "extent" : "full-screen",
15 | "minimum-system-version" : "7.0",
16 | "scale" : "2x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSNamedSelector.m:
--------------------------------------------------------------------------------
1 | //
2 | // CSSNamedSelector.m
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSNamedSelector.h"
10 |
11 | @implementation CSSNamedSelector
12 |
13 | +(instancetype) selectorWithName:(NSString*)name {
14 | CSSNamedSelector* selector = [[self alloc] init];
15 | selector.name = name;
16 | return selector;
17 | }
18 |
19 | -(NSString*) description {
20 | return [NSString stringWithFormat:@"", _name];
21 | }
22 |
23 | @end
24 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectorAttribute.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSSelectorAttribute.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Chong Francis on 14年1月8日.
6 | // Copyright (c) 2014年 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSBaseSelector.h"
10 | #import "CSSSelectorAttributeOperator.h"
11 | #import "NUIPParser.h"
12 |
13 | @interface CSSSelectorAttribute : CSSBaseSelector
14 |
15 | @property (nonatomic, strong) CSSSelectorAttributeOperator* attributeOperator;
16 | @property (nonatomic, copy) NSString* name;
17 | @property (nonatomic, copy) NSString* value;
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectorGrammar.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSSelectorGrammar.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 1/20/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "NUIPGrammar.h"
10 |
11 | @interface CSSSelectorGrammar : NUIPGrammar
12 |
13 | /**
14 | * Create a Grammar object using the grammar file in the bundle.
15 | */
16 | -(instancetype) init;
17 |
18 | /**
19 | * Create a Grammar object using the grammar file supplied.
20 | * @param path Path to the grammar defintion
21 | */
22 | -(instancetype) initWithPath:(NSString*)path;
23 |
24 | @end
25 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectors.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSSelectors.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSBaseSelector.h"
10 | #import "NUIPParser.h"
11 |
12 | @interface CSSSelectors : CSSBaseSelector
13 |
14 | @property (nonatomic, strong) NSMutableArray* selectors;
15 |
16 | /**
17 | Add a CSSSelectorSequence or CSSCombinator to the selectors.
18 |
19 | @raise NSInvalidArgumentException if selector is not CSSSelectorSequence or CSSCombinator
20 | */
21 | -(void) addSelector:(CSSBaseSelector*)selector;
22 |
23 | @end
24 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSCombinator.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSCombinator.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Chong Francis on 14年1月8日.
6 | // Copyright (c) 2014年 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSBaseSelector.h"
10 | #import "NUIPParser.h"
11 |
12 | typedef NS_ENUM(NSInteger, CSSCombinatorType) {
13 | CSSCombinatorTypeNone = 0,
14 | CSSCombinatorTypeDescendant,
15 | CSSCombinatorTypeAdjacent,
16 | CSSCombinatorTypeGeneralSibling
17 | };
18 |
19 | @interface CSSCombinator : CSSBaseSelector
20 |
21 | @property (nonatomic, assign) CSSCombinatorType type;
22 |
23 | +(CSSCombinator*) noneCombinator;
24 |
25 | @end
26 |
--------------------------------------------------------------------------------
/Podfile.lock:
--------------------------------------------------------------------------------
1 | PODS:
2 | - CocoaLumberjack (2.2.0):
3 | - CocoaLumberjack/Default (= 2.2.0)
4 | - CocoaLumberjack/Extensions (= 2.2.0)
5 | - CocoaLumberjack/Core (2.2.0)
6 | - CocoaLumberjack/Default (2.2.0):
7 | - CocoaLumberjack/Core
8 | - CocoaLumberjack/Extensions (2.2.0):
9 | - CocoaLumberjack/Default
10 | - Kiwi (2.4.0)
11 | - NUIParse (1.3)
12 |
13 | DEPENDENCIES:
14 | - CocoaLumberjack (~> 2.0)
15 | - Kiwi (>= 2.3.0)
16 | - NUIParse
17 |
18 | SPEC CHECKSUMS:
19 | CocoaLumberjack: 17fe8581f84914d5d7e6360f7c70022b173c3ae0
20 | Kiwi: f49c9d54b28917df5928fe44968a39ed198cb8a8
21 | NUIParse: 2e3885ba7807477266396292626bd387d34c2338
22 |
23 | COCOAPODS: 0.39.0
24 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSPseudoClass.m:
--------------------------------------------------------------------------------
1 | //
2 | // CSSPseudoClass.m
3 | // CSSSelectorConverter
4 | //
5 | // Created by Chong Francis on 14年1月8日.
6 | // Copyright (c) 2014年 Ignition Soft. All rights reserved.
7 | //
8 | #import "CSSPseudoClass.h"
9 | #import "NUIParse.h"
10 |
11 | @implementation CSSPseudoClass
12 |
13 | - (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree {
14 | self = [self init];
15 |
16 | id token = [syntaxTree valueForTag:@"className"];
17 | if ([token isIdentifierToken]) {
18 | self.name = [token identifier];
19 | }
20 |
21 | return self;
22 | }
23 |
24 | -(NSString*) description {
25 | return [NSString stringWithFormat:@"", self.name];
26 | }
27 |
28 | @end
29 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSUniversalSelector.m:
--------------------------------------------------------------------------------
1 | //
2 | // CSSUniversalSelector.m
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSUniversalSelector.h"
10 | #import "NUIParse.h"
11 |
12 | @implementation CSSUniversalSelector
13 |
14 | - (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree {
15 | return [self init];
16 | }
17 |
18 | - (id)init {
19 | self = [super init];
20 | self.name = @"*";
21 | return self;
22 | }
23 |
24 | +(instancetype) selector {
25 | return [self selectorWithName:@"*"];
26 | }
27 |
28 | -(NSString*) description {
29 | return @"";
30 | }
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectorSequence.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSSelectorSequence.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "CSSBaseSelector.h"
11 | #import "NUIPParser.h"
12 |
13 | @class CSSCombinator;
14 | @class CSSPseudoClass;
15 | @class CSSTypeSelector;
16 |
17 | @interface CSSSelectorSequence : CSSBaseSelector
18 |
19 | @property (nonatomic, strong) CSSPseudoClass* pseudoClass;
20 |
21 | @property (nonatomic, strong) CSSTypeSelector* universalOrTypeSelector;
22 |
23 | @property (nonatomic, strong) NSMutableArray* otherSelectors;
24 |
25 | -(void) addSelector:(CSSBaseSelector*)selector;
26 |
27 | @end
28 |
--------------------------------------------------------------------------------
/CSSSelectorConverterTests/CSSSelectorConverterTests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | hk.ignition.${PRODUCT_NAME:rfc1034identifier}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleShortVersionString
16 | 1.0
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectorAttributeOperator.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSSelectorAttributeType.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Chong Francis on 14年1月8日.
6 | // Copyright (c) 2014年 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSNamedSelector.h"
10 | #import "NUIPParser.h"
11 |
12 | typedef NS_ENUM(NSInteger, CSSSelectorAttributeOperatorType) {
13 | CSSSelectorAttributeOperatorTypeNone = 0,
14 | CSSSelectorAttributeOperatorTypeEqual,
15 | CSSSelectorAttributeOperatorTypeIncludes,
16 | CSSSelectorAttributeOperatorTypeDash
17 | };
18 |
19 | @interface CSSSelectorAttributeOperator : CSSNamedSelector
20 |
21 | @property (nonatomic, assign) CSSSelectorAttributeOperatorType attributeOperator;
22 |
23 | +(CSSSelectorAttributeOperatorType) operatorWithString:(NSString*) type;
24 |
25 | @end
26 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSIDSelector.m:
--------------------------------------------------------------------------------
1 | //
2 | // CSSIDSelector.m
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSIDSelector.h"
10 | #import "NUIParse.h"
11 |
12 | @implementation CSSIDSelector
13 |
14 | - (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree {
15 | self = [self init];
16 | if (self) {
17 | NSArray *components = [syntaxTree children];
18 | if ([components count] == 2) {
19 | NUIPIdentifierToken* token = components[1];
20 | if ([token isIdentifierToken]) {
21 | self.name = [token identifier];
22 | }
23 | }
24 | }
25 | return self;
26 | }
27 |
28 | -(NSString*) description {
29 | return [NSString stringWithFormat:@"", self.name];
30 | }
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSTypeSelector.m:
--------------------------------------------------------------------------------
1 | //
2 | // CSSTypeSelector.m
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSTypeSelector.h"
10 | #import "NUIParse.h"
11 |
12 | @implementation CSSTypeSelector
13 |
14 | - (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree {
15 | self = [self init];
16 | if (self) {
17 | NSArray *components = [syntaxTree children];
18 | if ([components count] == 1) {
19 | NUIPIdentifierToken* token = components[0];
20 | if ([token isIdentifierToken]) {
21 | self.name = [token identifier];
22 | }
23 | }
24 | }
25 | return self;
26 | }
27 |
28 | -(NSString*) description {
29 | return [NSString stringWithFormat:@"", self.name];
30 | }
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSClassSelector.m:
--------------------------------------------------------------------------------
1 | //
2 | // CSSClassSelector.m
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSClassSelector.h"
10 | #import "NUIParse.h"
11 |
12 | @implementation CSSClassSelector
13 |
14 | - (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree {
15 | self = [self init];
16 | if (self) {
17 | NSArray *components = [syntaxTree children];
18 | if ([components count] == 2) {
19 | NUIPIdentifierToken* token = components[1];
20 | if ([token isIdentifierToken]) {
21 | self.name = [token identifier];
22 | }
23 | }
24 | }
25 | return self;
26 | }
27 |
28 | -(NSString*) description {
29 | return [NSString stringWithFormat:@"", self.name];
30 | }
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectorXPathVisitor.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSSelectorXPathVisitor.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 1/22/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @class CSSBaseSelector;
12 |
13 | /**
14 | * Walk a tree of CSSBaseSelector subclasses, and build a XPath representation of the CSS.
15 | *
16 | * Upon finish, invoke xpathString to get the XPath.
17 | */
18 | @interface CSSSelectorXPathVisitor : NSObject
19 |
20 |
21 | /**
22 | * Visit a selector node (CSSBaseSelector subclasses) and generate XPath representation of the CSS Selector.
23 | *
24 | * @param node A CSSBaseSelector subclasses.
25 | * @throw NSInvalidArgumentException if the class is not supported by the visitor.
26 | */
27 | -(void) visit:(CSSBaseSelector*)node;
28 |
29 | /**
30 | * @return Returns XPath representation of the CSS Selector.
31 | */
32 | -(NSString*) xpathString;
33 |
34 | @end
35 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectorToXPathConverter.h:
--------------------------------------------------------------------------------
1 | //
2 | // CSSToXPathConverter.h
3 | // CSSSelectorConverter
4 | //
5 | // Created by Francis Chong on 7/1/14.
6 | // Copyright (c) 2014 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @class CSSSelectorParser;
12 |
13 | /**
14 | * Convert a CSS Selector to XPath.
15 | *
16 | * @see CSSSelectorParser
17 | * @see CSSSelectorXPathVisitor
18 | */
19 | @interface CSSSelectorToXPathConverter : NSObject
20 |
21 | @property (nonatomic, strong) CSSSelectorParser* parser;
22 |
23 | +(instancetype) sharedConverter;
24 |
25 | -(id) init;
26 |
27 | -(id) initWithParser:(CSSSelectorParser*)parser;
28 |
29 | /**
30 | * Parse a CSS Selector and return a XPath string.
31 | *
32 | *
33 | * @param css The css selector
34 | * @param error If the parse failed and parser return nil, error is set to last known error.
35 | * @return XPath representation of the given CSS Selector.
36 | */
37 | -(NSString*)xpathWithCSS:(NSString*)css error:(NSError*__autoreleasing*)error;
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014 Francis Chong, Ignition Soft. All rights reserved.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
9 |
--------------------------------------------------------------------------------
/CSSSelectorConverter/CSSSelectorAttribute.m:
--------------------------------------------------------------------------------
1 | //
2 | // CSSSelectorAttribute.m
3 | // CSSSelectorConverter
4 | //
5 | // Created by Chong Francis on 14年1月8日.
6 | // Copyright (c) 2014年 Ignition Soft. All rights reserved.
7 | //
8 |
9 | #import "CSSSelectorParser.h"
10 | #import "CSSSelectorAttribute.h"
11 | #import "NUIParse.h"
12 |
13 | @implementation CSSSelectorAttribute
14 |
15 | - (id)initWithSyntaxTree:(NUIPSyntaxTree *)syntaxTree {
16 | self = [self init];
17 | if (self) {
18 | self.attributeOperator = [syntaxTree valueForTag:@"op"];
19 | self.name = [[syntaxTree valueForTag:@"attrName"] identifier];
20 |
21 | NSArray* valChildren = [[syntaxTree valueForTag:@"attrValue"] children];
22 | if (valChildren) {
23 | if ([valChildren count] == 1 && [valChildren[0] isQuotedToken]) {
24 | self.value = [valChildren[0] content];
25 | }
26 | }
27 | }
28 | return self;
29 | }
30 |
31 | -(NSString*) description {
32 | return [NSString stringWithFormat:@"", self.name, self.attributeOperator.name, self.value];
33 | }
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/bin/CSSSelectorParserGenerator.m:
--------------------------------------------------------------------------------
1 | /*
2 | podfile-start
3 | platform :osx, '10.9'
4 | pod 'CSSSelectorConverter', :local => '/Users/siuying/workspace/opensource/CSSSelectorConverter'
5 | podfile-end
6 | */
7 |
8 | #include
9 | @import Foundation;
10 | #import "CSSSelectorConverter.h"
11 | #import "CSSSelectorGrammar.h"
12 | #import "CPLALR1Parser.h"
13 |
14 | int main(int argc, const char * argv[])
15 | {
16 | @autoreleasepool {
17 | if (argc >= 3)
18 | {
19 | NSString* grammaFile = [[NSString stringWithCString:argv[1] encoding:NSASCIIStringEncoding] stringByExpandingTildeInPath];
20 | NSString* outputFile = [[NSString stringWithCString:argv[2] encoding:NSASCIIStringEncoding] stringByExpandingTildeInPath];
21 | CSSSelectorGrammar* grammar = [[CSSSelectorGrammar alloc] initWithPath:grammaFile];
22 | CPLALR1Parser* parser1 = [CPLALR1Parser parserWithGrammar:grammar];
23 | [NSKeyedArchiver archiveRootObject:@{@"parser" : parser1}
24 | toFile:outputFile];
25 | }
26 | else
27 | {
28 | NSLog(@"Usage: CSSSelectorParserGenerator