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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
namespace Boo.Pegs

import System

class ActionList:

public static final Empty = ActionList()

def Add(action as PegAction):
return NonEmptyActionList(action, self)

virtual def Execute(ctx as PegContext):
pass

virtual IsEmpty:
get: return true

class NonEmptyActionList(ActionList):

_action as PegAction
_tail as ActionList

def constructor(action as PegAction, tail as ActionList):
_action = action
_tail = tail

override def Execute(ctx as PegContext):
_tail.Execute(ctx)
_action(ctx)

override IsEmpty:
get: return false

class PegState:

[getter(Context)]
_ctx as PegContext

def constructor(ctx as PegContext):
_ctx = ctx

virtual def BeginChoice() as PegState:
return TopLevelChoice(_ctx)

virtual def Commit():
raise InvalidOperationException()

virtual def Rollback():
raise InvalidOperationException()

virtual def OnAction(action as PegAction):
action(Context)

class AbstractChoiceState(PegState):

_state as (object)

def constructor(ctx as PegContext):
super(ctx)
_state = ctx.GetMemento()

override def Commit():
pass

override def Rollback():
Context.Restore(_state)

class PredicateState(AbstractChoiceState):

def constructor(ctx as PegContext):
super(ctx)

override def BeginChoice():
return PredicateState(Context)

override def Commit():
Context.Restore(_state)

override def OnAction(_ as PegAction):
pass

class TopLevelChoice(AbstractChoiceState):

_action = ActionList.Empty

def constructor(ctx as PegContext):
super(ctx)

override def BeginChoice():
return NestedChoice(self)

override def Commit():
_action.Execute(Context)

override def OnAction(action as PegAction):
_action = _action.Add(contextful(action))

def contextful(action as PegAction) as PegAction:
memento = _ctx.GetMemento()
return do (ctx as PegContext):
ctx.WithMemento(memento, action)

class NestedChoice(TopLevelChoice):

_parent as PegState

def constructor(parent as PegState):
super(parent.Context)
_parent = parent

override def Commit():
if _action.IsEmpty: return
_parent.OnAction(_action.Execute)
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: 2272 bytes, 113 lines