What's new? | Help | Directory | Sign in
Google
boo-extensions
Useful extensions, macros and attributes to the boo programming language
  
  
  
  
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
namespace Boo.Pegs

def empty():
return EmptyExpression()

def any():
return AnyExpression()

def action(action as PegAction):
return ActionExpression(action)

def terminal(text as string):
s = array(CharPredicateExpression({ current as char | current == ch }) for ch in text)
return sequence(*s)

def sequence(*expressions as (PegExpression)):
if 1 == len(expressions): return expressions[0]
return SequenceExpression(expressions)

def choice(*expressions as (PegExpression)):
if 1 == len(expressions): return expressions[0]
return ChoiceExpression(expressions)

def one_or_many(e as PegExpression):
return sequence(e, ZeroOrMany(e))

def zero_or_many(e as PegExpression):
return ZeroOrMany(e)

def not_predicate(e as PegExpression):
ne = FunctionExpression() do (ctx as PegContext):
return not e.Match(ctx)
return FunctionExpression() do (ctx as PegContext):
return ctx.Test(ne)

def predict(test as PegExpression, e as PegExpression):
return FunctionExpression() do (ctx as PegContext):
return ctx.Test(test) and e.Match(ctx)

def char_range(begin as char, end as char):
return CharPredicateExpression() do (current as char):
return current >= begin and current <= end

def same_match(rule as PegRule):
return FunctionExpression() do (ctx as PegContext):
lastMatch = ctx.RuleState.LastMatchFor(rule)
return terminal(lastMatch).Match(ctx)

def digit():
return CharPredicateExpression(char.IsDigit)

def whitespace():
return CharPredicateExpression(char.IsWhiteSpace)
Show details Hide details

Change log

r56 by rodrigobamboo on May 07, 2008   Diff
not predicate DOES NOT consume the input
Go to: 
Project members, sign in to write a code review

Older revisions

r54 by rodrigobamboo on May 07, 2008   Diff
support for predicates (&);
support for last match rules (@rule);
r48 by rodrigobamboo on May 04, 2008   Diff
PegTransaction => PegState;
zero_or_many must backtrack (duh!);
implement one_to_many(e) as
sequence(e, zero_or_many(e)) fixing
all remaining issues;
...
r47 by rodrigobamboo on May 04, 2008   Diff
more explicit names for repetition
rules;
better file names and other things;
All revisions of this file

File info

Size: 1568 bytes, 53 lines