Skip to content

Commit

Permalink
* Change Action blocks to have void return
Browse files Browse the repository at this point in the history
  • Loading branch information
itod committed Mar 29, 2014
1 parent 3137372 commit 08b6053
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 53 deletions.
4 changes: 2 additions & 2 deletions include/PEGKit/PKParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@class PKToken;
@class PKAssembly;

typedef id (^PKSActionBlock) (void);
typedef void (^PKSActionBlock) (void);
typedef void (^PKSSpeculateBlock)(void);
typedef BOOL (^PKSPredicateBlock)(void);
typedef void (^PKSRecoverBlock) (void);
Expand Down Expand Up @@ -105,7 +105,7 @@ enum {
- (void)testAndThrow:(PKSPredicateBlock)block;

// actions
- (id)execute:(PKSActionBlock)block;
- (void)execute:(PKSActionBlock)block;

// delegate callbacks
- (void)fireDelegateSelector:(SEL)sel;
Expand Down
2 changes: 1 addition & 1 deletion res/PGActionTemplate.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{%for 1 to depth %} {%/for%}[self execute:(id)^{
{%for 1 to depth %} {%/for%}[self execute:^{
{%for 1 to depth %} {%/for%}{{actionBody}}
{%for 1 to depth %} {%/for%}}];
8 changes: 3 additions & 5 deletions src/PKParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -683,13 +683,11 @@ - (BOOL)speculate:(PKSSpeculateBlock)block {
}


- (id)execute:(PKSActionBlock)block {
- (void)execute:(PKSActionBlock)block {
NSParameterAssert(block);
if (self.isSpeculating || !_enableActions) return nil;
if (self.isSpeculating || !_enableActions) return;

id result = nil;
if (block) result = block();
return result;
if (block) block();
}


Expand Down
2 changes: 1 addition & 1 deletion test/CSSParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ - (void)start {

- (void)__stylesheet {

[self execute:(id)^{
[self execute:^{

PKTokenizer *t = self.tokenizer;

Expand Down
12 changes: 6 additions & 6 deletions test/CreateTableStmtParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ - (void)createTableStmt_ {
[self existsOpt_];
[self databaseName_];
[self match:CREATETABLESTMT_TOKEN_KIND_SEMI_COLON discard:YES];
[self execute:(id)^{
[self execute:^{

// NSString *dbName = POP();
// BOOL ifNotExists = POP_BOOL();
Expand All @@ -125,7 +125,7 @@ - (void)createTableStmt_ {
- (void)databaseName_ {

[self matchQuotedString:NO];
[self execute:(id)^{
[self execute:^{

// pop the string value of the `PKToken` on the top of the stack
NSString *dbName = POP_STR();
Expand All @@ -149,12 +149,12 @@ - (void)tempOpt_ {
} else {
[self raise:@"No viable alternative found in rule 'tempOpt'."];
}
[self execute:(id)^{
[self execute:^{
PUSH(@YES);
}];
} else {
[self matchEmpty:NO];
[self execute:(id)^{
[self execute:^{
PUSH(@NO);
}];
}
Expand All @@ -168,12 +168,12 @@ - (void)existsOpt_ {
[self match:CREATETABLESTMT_TOKEN_KIND_IF discard:YES];
[self match:CREATETABLESTMT_TOKEN_KIND_NOT_UPPER discard:YES];
[self match:CREATETABLESTMT_TOKEN_KIND_EXISTS discard:YES];
[self execute:(id)^{
[self execute:^{
PUSH(@YES);
}];
} else {
[self matchEmpty:NO];
[self execute:(id)^{
[self execute:^{
PUSH(@NO);
}];
}
Expand Down
2 changes: 1 addition & 1 deletion test/CrockfordParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ - (void)start {

- (void)program_ {

[self execute:(id)^{
[self execute:^{

PKTokenizer *t = self.tokenizer;

Expand Down
2 changes: 1 addition & 1 deletion test/CurlyActionParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ - (void)start_ {
do {
[self matchWord:NO];
} while ([self predicts:TOKEN_KIND_BUILTIN_WORD, 0]);
[self execute:(id)^{
[self execute:^{

id word = nil;
while (!EMPTY()) {
Expand Down
2 changes: 1 addition & 1 deletion test/DelimitedParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ - (void)start {

- (void)__start {

[self execute:(id)^{
[self execute:^{

PKTokenizer *t = self.tokenizer;

Expand Down
14 changes: 7 additions & 7 deletions test/ExpressionActionsParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ - (void)start {

- (void)__expr {

[self execute:(id)^{
[self execute:^{

PKTokenizer *t = self.tokenizer;
[t.symbolState add:@"!="];
Expand Down Expand Up @@ -224,7 +224,7 @@ - (void)__orTerm {

[self match:EXPRESSIONACTIONS_TOKEN_KIND_OR discard:YES];
[self andExpr_];
[self execute:(id)^{
[self execute:^{

BOOL rhs = POP_BOOL();
BOOL lhs = POP_BOOL();
Expand Down Expand Up @@ -257,7 +257,7 @@ - (void)__andTerm {

[self match:EXPRESSIONACTIONS_TOKEN_KIND_AND discard:YES];
[self relExpr_];
[self execute:(id)^{
[self execute:^{

BOOL rhs = POP_BOOL();
BOOL lhs = POP_BOOL();
Expand Down Expand Up @@ -315,7 +315,7 @@ - (void)__relOpTerm {

[self relOp_];
[self callExpr_];
[self execute:(id)^{
[self execute:^{

NSInteger rhs = POP_INT();
NSString *op = POP_STR();
Expand Down Expand Up @@ -448,17 +448,17 @@ - (void)__literal {
if ([self predicts:EXPRESSIONACTIONS_TOKEN_KIND_NO, EXPRESSIONACTIONS_TOKEN_KIND_NO_UPPER, EXPRESSIONACTIONS_TOKEN_KIND_YES, EXPRESSIONACTIONS_TOKEN_KIND_YES_UPPER, 0]) {
[self testAndThrow:(id)^{ return LA(1) != EXPRESSIONACTIONS_TOKEN_KIND_YES_UPPER; }];
[self bool_];
[self execute:(id)^{
[self execute:^{
PUSH_BOOL(EQ_IGNORE_CASE(POP_STR(), @"yes"));
}];
} else if ([self predicts:TOKEN_KIND_BUILTIN_NUMBER, 0]) {
[self matchNumber:NO];
[self execute:(id)^{
[self execute:^{
PUSH_DOUBLE(POP_DOUBLE());
}];
} else if ([self predicts:TOKEN_KIND_BUILTIN_QUOTEDSTRING, 0]) {
[self matchQuotedString:NO];
[self execute:(id)^{
[self execute:^{
PUSH(POP_STR());
}];
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/ExpressionParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ - (void)start {

- (void)__expr {

[self execute:(id)^{
[self execute:^{

PKTokenizer *t = self.tokenizer;
[t.symbolState add:@"!="];
Expand Down
2 changes: 1 addition & 1 deletion test/GrammarActionsParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ - (void)start {

- (void)start_ {

[self execute:(id)^{
[self execute:^{

NSAssert([self.foo isEqualToString:@"hello world"], @"");
NSAssert([_foo isEqualToString:@"hello world"], @"");
Expand Down
2 changes: 1 addition & 1 deletion test/HTMLParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ - (void)start {

- (void)__start {

[self execute:(id)^{
[self execute:^{

PKTokenizer *t = self.tokenizer;

Expand Down
2 changes: 1 addition & 1 deletion test/JSONParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ - (void)start {

- (void)start_ {

[self execute:(id)^{
[self execute:^{

PKTokenizer *t = self.tokenizer;

Expand Down
2 changes: 1 addition & 1 deletion test/JavaScriptParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ - (void)start {

- (void)program_ {

[self execute:(id)^{
[self execute:^{

PKTokenizer *t = self.tokenizer;

Expand Down
2 changes: 1 addition & 1 deletion test/JavaScriptWhitespaceParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ - (void)start {

- (void)program_ {

[self execute:(id)^{
[self execute:^{

PKTokenizer *t = self.tokenizer;

Expand Down
6 changes: 3 additions & 3 deletions test/MiniMath2Parser.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ - (void)addExpr_ {
while ([self speculate:^{ [self match:MINIMATH2_TOKEN_KIND_PLUS discard:YES]; [self multExpr_]; }]) {
[self match:MINIMATH2_TOKEN_KIND_PLUS discard:YES];
[self multExpr_];
[self execute:(id)^{
[self execute:^{

PUSH_DOUBLE(POP_DOUBLE() + POP_DOUBLE());

Expand All @@ -119,7 +119,7 @@ - (void)multExpr_ {
while ([self speculate:^{ [self match:MINIMATH2_TOKEN_KIND_STAR discard:YES]; [self primary_]; }]) {
[self match:MINIMATH2_TOKEN_KIND_STAR discard:YES];
[self primary_];
[self execute:(id)^{
[self execute:^{

PUSH_DOUBLE(POP_DOUBLE() * POP_DOUBLE());

Expand All @@ -145,7 +145,7 @@ - (void)primary_ {
- (void)atom_ {

[self matchNumber:NO];
[self execute:(id)^{
[self execute:^{

PUSH_DOUBLE(POP_DOUBLE());

Expand Down
8 changes: 4 additions & 4 deletions test/MiniMathParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ - (void)__expr {
while ([self speculate:^{ [self match:MINIMATH_TOKEN_KIND_PLUS discard:YES]; [self mult_]; }]) {
[self match:MINIMATH_TOKEN_KIND_PLUS discard:YES];
[self mult_];
[self execute:(id)^{
[self execute:^{
PUSH_DOUBLE(POP_DOUBLE()+POP_DOUBLE());
}];
}
Expand All @@ -133,7 +133,7 @@ - (void)__mult {
while ([self speculate:^{ [self match:MINIMATH_TOKEN_KIND_STAR discard:YES]; [self pow_]; }]) {
[self match:MINIMATH_TOKEN_KIND_STAR discard:YES];
[self pow_];
[self execute:(id)^{
[self execute:^{
PUSH_DOUBLE(POP_DOUBLE()*POP_DOUBLE());
}];
}
Expand All @@ -151,7 +151,7 @@ - (void)__pow {
if ([self speculate:^{ [self match:MINIMATH_TOKEN_KIND_CARET discard:YES]; [self pow_]; }]) {
[self match:MINIMATH_TOKEN_KIND_CARET discard:YES];
[self pow_];
[self execute:(id)^{
[self execute:^{

double exp = POP_DOUBLE();
double base = POP_DOUBLE();
Expand All @@ -173,7 +173,7 @@ - (void)pow_ {
- (void)__atom {

[self matchNumber:NO];
[self execute:(id)^{
[self execute:^{
PUSH_DOUBLE(POP_DOUBLE());
}];

Expand Down
4 changes: 2 additions & 2 deletions test/NamedActionParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ - (void)start_ {

- (void)__a {

[self execute:(id)^{
[self execute:^{
PUSH(@"foo");
}];
[self match:NAMEDACTION_TOKEN_KIND_A discard:NO];
[self execute:(id)^{
[self execute:^{
PUSH(@"bar");
}];

Expand Down
2 changes: 1 addition & 1 deletion test/TDNSPredicateParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ - (void)start {

- (void)__start {

[self execute:(id)^{
[self execute:^{

PKTokenizer *t = self.tokenizer;
[t setTokenizerState:t.wordState from:'#' to:'#'];
Expand Down
10 changes: 5 additions & 5 deletions test/TableIndexParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ - (void)qualifiedTableName_ {

[self name_];
[self indexOpt_];
[self execute:(id)^{
[self execute:^{

// now stack contains 3 `NSString`s.
// ["mydb", "mytable", "foo"]
Expand Down Expand Up @@ -138,7 +138,7 @@ - (void)name_ {
[self match:TABLEINDEX_TOKEN_KIND_DOT discard:YES];
}
[self tableName_];
[self execute:(id)^{
[self execute:^{

// now stack contains 2 `PKToken`s of type Word
// [<Word «mydb»>, <Word «mytable»>]
Expand All @@ -159,7 +159,7 @@ - (void)indexOpt_ {
[self index_];
} else {
[self matchEmpty:NO];
[self execute:(id)^{
[self execute:^{
PUSH(@"");
}];
}
Expand All @@ -173,7 +173,7 @@ - (void)index_ {
[self match:TABLEINDEX_TOKEN_KIND_INDEXED discard:YES];
[self match:TABLEINDEX_TOKEN_KIND_BY discard:YES];
[self indexName_];
[self execute:(id)^{
[self execute:^{

// now top of stack will be a Quoted String `PKToken`
// […, <Quoted String «"foo"»>]
Expand All @@ -188,7 +188,7 @@ - (void)index_ {
} else if ([self predicts:TABLEINDEX_TOKEN_KIND_NOT_UPPER, 0]) {
[self match:TABLEINDEX_TOKEN_KIND_NOT_UPPER discard:YES];
[self match:TABLEINDEX_TOKEN_KIND_INDEXED discard:YES];
[self execute:(id)^{
[self execute:^{
PUSH(@"");
}];
} else {
Expand Down
Loading

0 comments on commit 08b6053

Please sign in to comment.