My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones  
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

from lepl import *

def with_line(node):
def wrapper(results, stream_out, **kargs):
return node(results, ('line_no', s_delta(stream_out)[1]))
return wrapper

class Greeting(Node): pass
newline = ~Literal('\n')
space = ~Space()
padding = (space | newline)[:]
line = padding & (Literal('howdy:') ** with_line(Greeting)) & padding

ast = line.parse(' \n \n \n howdy: \n \n\n ')
print(ast[0])



class Block(List): pass

def with_line(node):
def wrapper(results, stream_in, stream_out):
print('inside')
a = s_delta(stream_in)[1]
try:
b = s_delta(stream_out)[1]
except StopIteration:
b = 'eof'
return node([results, a, b])
return wrapper

identifier = Token('[a-zA-Z][a-zA-Z0-9_]*') > List
symbol = Token('[^0-9a-zA-Z \t\r\n]')


#block = (~symbol('{') & (identifier | symbol)[0:] ** with_line(Block) & ~symbol('}')) # V1
block = (~symbol('{') & (identifier | symbol)[0:] & ~symbol('}')) ** with_line(Block) # V2

parser = block.get_parse()

print(parser('{\n Andrew \n}')[0])

Change log

ae931ae554c3 by and...@acooke.org on Jan 11, 2012   Diff
fix line no bug
Go to: 
Project members, sign in to write a code review

Older revisions

3c562f5ef9e0 by and...@acooke.org on Nov 17, 2011   Diff
cleanup small
f5a97799d820 by andrew on Jun 3, 2011   Diff
starting to merge rxpy
All revisions of this file

File info

Size: 1065 bytes, 43 lines
Powered by Google Project Hosting