├── .gitignore
├── CompanionGuides
└── CoreParse-template.md
├── CoreParse.xcodeproj
├── project.pbxproj
└── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ └── CoreParse.xccheckout
├── CoreParse
├── Built In Parsers
│ ├── CPJSONParser.h
│ └── CPJSONParser.m
├── CPSenTestKitAssertions.h
├── CoreParse-Info.plist
├── CoreParse-Prefix.pch
├── CoreParse.h
├── Grammar
│ ├── CPGrammar.h
│ ├── CPGrammar.m
│ ├── CPGrammarInternal.h
│ ├── CPGrammarInternal.m
│ ├── CPGrammarPrivate.h
│ ├── CPGrammarPrivate.m
│ ├── CPGrammarSymbol.h
│ ├── CPGrammarSymbol.m
│ ├── CPRHSItem+Private.h
│ ├── CPRHSItem.h
│ ├── CPRHSItem.m
│ ├── CPRHSItemResult.h
│ ├── CPRHSItemResult.m
│ ├── CPRule+Internal.h
│ ├── CPRule.h
│ └── CPRule.m
├── NSArray+Functional.h
├── NSArray+Functional.m
├── NSSetFunctional.h
├── NSSetFunctional.m
├── Parsers
│ ├── CPParser.h
│ ├── CPParser.m
│ ├── CPShiftReduceParser.h
│ ├── CPShiftReduceParser.m
│ ├── CPShiftReduceParsers
│ │ ├── CPItem.h
│ │ ├── CPItem.m
│ │ ├── CPLALR1Parser.h
│ │ ├── CPLALR1Parser.m
│ │ ├── CPLR1Item.h
│ │ ├── CPLR1Item.m
│ │ ├── CPLR1Parser.h
│ │ ├── CPLR1Parser.m
│ │ ├── CPSLRParser.h
│ │ ├── CPSLRParser.m
│ │ ├── CPShiftAction.h
│ │ ├── CPShiftAction.m
│ │ ├── CPShiftReduceAction.h
│ │ ├── CPShiftReduceAction.m
│ │ ├── CPShiftReduceActionTable.h
│ │ ├── CPShiftReduceActionTable.m
│ │ ├── CPShiftReduceGotoTable.h
│ │ ├── CPShiftReduceGotoTable.m
│ │ ├── CPShiftReduceParserProtectedMethods.h
│ │ ├── CPShiftReduceState.h
│ │ └── CPShiftReduceState.m
│ └── Error Recovery
│ │ ├── CPRecoveryAction.h
│ │ └── CPRecoveryAction.m
├── Syntax Tree
│ ├── CPSyntaxTree.h
│ └── CPSyntaxTree.m
├── Tokenisation
│ ├── CPTokenStream.h
│ ├── CPTokenStream.m
│ ├── CPTokeniser.h
│ ├── CPTokeniser.m
│ ├── Token Recognisers
│ │ ├── CPIdentifierRecogniser.h
│ │ ├── CPIdentifierRecogniser.m
│ │ ├── CPKeywordRecogniser.h
│ │ ├── CPKeywordRecogniser.m
│ │ ├── CPNumberRecogniser.h
│ │ ├── CPNumberRecogniser.m
│ │ ├── CPQuotedRecogniser.h
│ │ ├── CPQuotedRecogniser.m
│ │ ├── CPRegexpRecogniser.h
│ │ ├── CPRegexpRecogniser.m
│ │ ├── CPTokenRecogniser.h
│ │ ├── CPWhiteSpaceRecogniser.h
│ │ └── CPWhiteSpaceRecogniser.m
│ └── Token Types
│ │ ├── CPEOFToken.h
│ │ ├── CPEOFToken.m
│ │ ├── CPErrorToken.h
│ │ ├── CPErrorToken.m
│ │ ├── CPIdentifierToken.h
│ │ ├── CPIdentifierToken.m
│ │ ├── CPKeywordToken.h
│ │ ├── CPKeywordToken.m
│ │ ├── CPNumberToken.h
│ │ ├── CPNumberToken.m
│ │ ├── CPQuotedToken.h
│ │ ├── CPQuotedToken.m
│ │ ├── CPToken.h
│ │ ├── CPToken.m
│ │ ├── CPWhiteSpaceToken.h
│ │ └── CPWhiteSpaceToken.m
└── en.lproj
│ └── InfoPlist.strings
├── CoreParseTests
├── CPRegexpRecogniserTest.m
├── CPSTAssertionsTests.h
├── CPSTAssertionsTests.m
├── CPTestErrorEvaluatorDelegate.h
├── CPTestErrorEvaluatorDelegate.m
├── CPTestErrorHandlingDelegate.h
├── CPTestErrorHandlingDelegate.m
├── CPTestEvaluatorDelegate.h
├── CPTestEvaluatorDelegate.m
├── CPTestMapCSSTokenisingDelegate.h
├── CPTestMapCSSTokenisingDelegate.m
├── CPTestWhiteSpaceIgnoringDelegate.h
├── CPTestWhiteSpaceIgnoringDelegate.m
├── CPWillFinishDelegateTest.m
├── CoreParseTests-Info.plist
├── CoreParseTests-Prefix.pch
├── CoreParseTests.m
├── Expression.h
├── Expression.m
├── Expression2.h
├── Expression2.m
├── RuleBase.h
├── RuleBase.m
├── Term.h
├── Term.m
├── Term2.h
├── Term2.m
└── en.lproj
│ └── InfoPlist.strings
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | /.DS_Store
2 |
3 | /CoreParse.xcodeproj/xcuserdata/
4 |
5 | /CoreParse.xcodeproj/project.xcworkspace/xcuserdata/
6 |
--------------------------------------------------------------------------------
/CompanionGuides/CoreParse-template.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beelsebob/CoreParse/9ae4bb59a912d73c4af304d9109a6d9abbb75065/CompanionGuides/CoreParse-template.md
--------------------------------------------------------------------------------
/CoreParse.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CoreParse.xcodeproj/project.xcworkspace/xcshareddata/CoreParse.xccheckout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDESourceControlProjectFavoriteDictionaryKey
6 |
7 | IDESourceControlProjectIdentifier
8 | 5FCEC138-BD89-4E15-965B-903D778E9B1D
9 | IDESourceControlProjectName
10 | CoreParse
11 | IDESourceControlProjectOriginsDictionary
12 |
13 | 933D72C4-BB34-468B-8A2A-F9A5F6A06A65
14 | https://github.com/beelsebob/CoreParse.git
15 |
16 | IDESourceControlProjectPath
17 | CoreParse.xcodeproj/project.xcworkspace
18 | IDESourceControlProjectRelativeInstallPathDictionary
19 |
20 | 933D72C4-BB34-468B-8A2A-F9A5F6A06A65
21 | ../..
22 |
23 | IDESourceControlProjectURL
24 | ssh://github.com/siuying/CSSSelectorConverter.git
25 | IDESourceControlProjectVersion
26 | 110
27 | IDESourceControlProjectWCCIdentifier
28 | 933D72C4-BB34-468B-8A2A-F9A5F6A06A65
29 | IDESourceControlProjectWCConfigurations
30 |
31 |
32 | IDESourceControlRepositoryExtensionIdentifierKey
33 | public.vcs.git
34 | IDESourceControlWCCIdentifierKey
35 | 933D72C4-BB34-468B-8A2A-F9A5F6A06A65
36 | IDESourceControlWCCName
37 | CoreParse
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/CoreParse/Built In Parsers/CPJSONParser.h:
--------------------------------------------------------------------------------
1 | //
2 | // CPJSONParser.h
3 | // CoreParse
4 | //
5 | // Created by Tom Davie on 29/03/2011.
6 | // Copyright 2011 In The Beginning... All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | /**
12 | * The CPJSONParser class is a demonstration of CoreParse.
13 | *
14 | * The parser deals with all JSON except for unicode encoded characters. The reason for not dealing with this corner case is that this parser is simply to demonstrate how to use CoreParse, and
15 | * the code needed to process unicode characters is non-trivial, and not particularly relevant to the demonstration.
16 | */
17 | @interface CPJSONParser : NSObject
18 |
19 | /**
20 | * Parses a JSON string and returns a standard objective-c data structure reflecting it:
21 | *
22 | * JSON numbers and booleans are returned as NSNumbers; JSON strings as NSStrings; `null` as an NSNull object; JSON arrays are returned as NSArrays; finally JSON objects are returned as NSDictionarys.
23 | *
24 | * @param json The JSON string to parse.
25 | */
26 | - (id)parse:(NSString *)json;
27 |
28 | @end
29 |
--------------------------------------------------------------------------------
/CoreParse/Built In Parsers/CPJSONParser.m:
--------------------------------------------------------------------------------
1 | //
2 | // CPJSONParser.m
3 | // CoreParse
4 | //
5 | // Created by Tom Davie on 29/03/2011.
6 | // Copyright 2011 In The Beginning... All rights reserved.
7 | //
8 |
9 | #import "CPJSONParser.h"
10 |
11 | #import "CPTokeniser.h"
12 | #import "CPSLRParser.h"
13 | #import "CPKeywordRecogniser.h"
14 | #import "CPNumberRecogniser.h"
15 | #import "CPWhiteSpaceRecogniser.h"
16 | #import "CPQuotedRecogniser.h"
17 |
18 | #import "CPKeywordToken.h"
19 | #import "CPNumberToken.h"
20 | #import "CPQuotedToken.h"
21 | #import "CPWhiteSpaceToken.h"
22 |
23 | @interface CPJSONParser ()
24 | @end
25 |
26 | @implementation CPJSONParser
27 | {
28 | CPTokeniser *jsonTokeniser;
29 | CPParser *jsonParser;
30 | }
31 |
32 | - (id)init
33 | {
34 | self = [super init];
35 |
36 | if (nil != self)
37 | {
38 | jsonTokeniser = [[CPTokeniser alloc] init];
39 | CPQuotedRecogniser *stringRecogniser = [CPQuotedRecogniser quotedRecogniserWithStartQuote:@"\"" endQuote:@"\"" escapeSequence:@"\\" name:@"String"];
40 | [stringRecogniser setEscapeReplacer:^ NSString * (NSString *str, NSUInteger *loc)
41 | {
42 | if ([str length] > *loc)
43 | {
44 | switch ([str characterAtIndex:*loc])
45 | {
46 | case 'b':
47 | *loc = *loc + 1;
48 | return @"\b";
49 | case 'f':
50 | *loc = *loc + 1;
51 | return @"\f";
52 | case 'n':
53 | *loc = *loc + 1;
54 | return @"\n";
55 | case 'r':
56 | *loc = *loc + 1;
57 | return @"\r";
58 | case 't':
59 | *loc = *loc + 1;
60 | return @"\t";
61 | default:
62 | break;
63 | }
64 | }
65 | return nil;
66 | }];
67 |
68 | [jsonTokeniser addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"{"]];
69 | [jsonTokeniser addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"}"]];
70 | [jsonTokeniser addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"["]];
71 | [jsonTokeniser addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"]"]];
72 | [jsonTokeniser addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@":"]];
73 | [jsonTokeniser addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@","]];
74 | [jsonTokeniser addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"true"]];
75 | [jsonTokeniser addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"false"]];
76 | [jsonTokeniser addTokenRecogniser:[CPKeywordRecogniser recogniserForKeyword:@"null"]];
77 | [jsonTokeniser addTokenRecogniser:[CPNumberRecogniser numberRecogniser]];
78 | [jsonTokeniser addTokenRecogniser:stringRecogniser];
79 | [jsonTokeniser addTokenRecogniser:[CPWhiteSpaceRecogniser whiteSpaceRecogniser]];
80 | [jsonTokeniser setDelegate:self];
81 |
82 | CPGrammar *jsonGrammar = [CPGrammar grammarWithStart:@"value"
83 | backusNaurForm:
84 | @"0 value ::= 'String';"
85 | @"1 value ::= 'Number';"
86 | @"2 value ::=