PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/backtracking/tiny_parse/truc.e

http://github.com/tybor/Liberty
Specman e | 79 lines | 65 code | 14 blank | 0 comment | 2 complexity | 85bac0b0bde8be78a0e2727df2ba4bd0 MD5 | raw file
 1
 2class PARSER_SEQUENCE_MARK_END
 3inherit ABSTRACT_BACKTRACKING_SEQUENCE
 4feature
 5	parseable: PARSER_PARSEABLE
 6	set_parseable(value: like parseable) is
 7		do
 8			parseable := value
 9		end
10	next_sequence(parser: PARSER) is
11		do
12			parser.push_mark_end(parseable)
13			parser.pop_sequence
14			parser.continue
15		end
16end
17
18expanded class PARSER_CONTEXT
19feature
20	depth, position: INTEGER
21	make(d,p: INTEGER) is
22		do
23			depth:=d
24			position:=p
25		end
26end
27
28expanded class PARSER_MARK
29feature
30	position: INTEGER
31	is_begin: BOOLEAN
32	is_end: BOOLEAN is do Result:=not is_begin end
33	parseable: PARSER_PARSEABLE
34	make_begin(pos: INTEGER; what: like parseable) is do is_begin:=True position:=pos parseable:=what end
35	make_end(pos: INTEGER; what: like parseable) is do is_begin:=False position:=pos parseable:=what end
36end
37
38class PARSER_GRAMMAR feature
39	rules: HASHED_DICTIONARY[RULE,STRING]
40	blanks: REGULAR_EXPRESSION_ROOT
41	root: RULE
42end
43
44deferred class PARSER_PARSEABLE
45inherit
46	BACKTRACKING_NODE rename explore as parse end
47end
48
49class PARSER_RULE inherit PARSER_PARSEABLE feature
50	name: STRING
51	item: PARSER_PARSEABLE
52	parse(parser: PARSER) is do parser.goto_inside(item) end
53end
54
55deferred class PARSER_TOKEN inherit PARSER_PARSEABLE feature
56	expr: REGULAR_EXPRESSION_ROOT
57	make(exp: like expr) is do expr := exp end
58	parse(parser: PARSER) is do
59		if parser.match(expr) 
60			then parser.continue 
61			else parser.backtrack
62		end
63	end
64end
65
66class PARSER_FIXED inherit PARSER_TOKEN feature
67end
68
69class TOKEN_RECORDED inherit PARSER_TOKEN feature
70end
71
72class PARSER_OPTIONAL inherit PARSER_PARSEABLE feature
73end
74
75class PARSER_LIST inherit PARSER_PARSEABLE feature
76end
77
78
79