File: Parse.cpp

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (109 lines) | stat: -rw-r--r-- 2,849 bytes parent folder | download | duplicates (4)
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
#include "stdafx.h"
#include "Compiler/Syntax/Parser.h"
#include "Compiler/Syntax/GLR/Parser.h"
#include "Compiler/Package.h"

using namespace storm::syntax;

BEGIN_TEST(InfoParse, Server) {
	Engine &e = gEngine();

	Package *pkg = e.package(S("lang.simple"));
	Parser *p = Parser::create(pkg, S("SRoot"));

	Str *src = new (e) Str(S("foo + bar / 2;"));
	Bool ok = p->parse(src, new (e) Url());
	UNUSED(ok);
	VERIFY(p->hasTree() && p->matchEnd() == src->end());

	InfoNode *tree = p->infoTree();
	CHECK_EQ(tree->length(), 14);
	CHECK_EQ(tree->leafAt(0)->color, tVarName);
	CHECK_EQ(tree->leafAt(4)->color, tNone);
	CHECK_EQ(tree->leafAt(6)->color, tVarName);
	CHECK_EQ(tree->leafAt(12)->color, tConstant);
	CHECK_EQ(tree->leafAt(13)->color, tNone);

} END_TEST


BEGIN_TEST(InfoError, Server) {
	Engine &e = gEngine();

	Package *pkg = e.package(S("lang.simple"));
	InfoParser *p = InfoParser::create(pkg, S("SExpr"), new (e) glr::Parser());

	{
		Str *src = new (e) Str(S("foo +"));
		InfoErrors s = p->parseApprox(src, new (e) Url());
		VERIFY(s.success());

		InfoNode *tree = p->infoTree();
		VERIFY(tree->length() == 5);
		CHECK_EQ(tree->leafAt(0)->color, tVarName);
		CHECK_EQ(tree->leafAt(4)->color, tNone);
	}

	{
		Str *src = new (e) Str(S("foo bar"));
		InfoErrors s = p->parseApprox(src, new (e) Url());
		VERIFY(s.success());

		InfoNode *tree = p->infoTree();
		VERIFY(tree->length() == 7);
		CHECK_EQ(tree->leafAt(0)->color, tVarName);
		CHECK_EQ(tree->leafAt(3)->color, tNone);
		CHECK_EQ(tree->leafAt(4)->color, tVarName);
	}

	{
		// How are strings with unknown tokens handled?
		Str *src = new (e) Str(S("foo +;"));
		InfoErrors s = p->parseApprox(src, new (e) Url());
		VERIFY(s.success());

		// This checks to see if trees are properly padded to their full length.
		InfoNode *tree = p->fullInfoTree();
		VERIFY(tree->length() == 6);
		CHECK_EQ(tree->leafAt(0)->color, tVarName);
		CHECK_EQ(tree->leafAt(4)->color, tNone);
	}

	{
		// Can we skip unknown characters?
		Str *src = new (e) Str(S("foo ? bar"));
		InfoErrors s = p->parseApprox(src, new (e) Url());
		VERIFY(s.success());

		InfoNode *tree = p->infoTree();
		VERIFY(tree->length() == 9);
		CHECK_EQ(tree->leafAt(0)->color, tVarName);
		CHECK_EQ(tree->leafAt(6)->color, tVarName);
		CHECK_EQ(tree->leafAt(8)->color, tVarName);
	}

} END_TEST

BEGIN_TEST(JavaError, Server) {
	Engine &e = gEngine();

	Package *pkg = e.package(S("lang.java"));
	InfoParser *p = InfoParser::create(pkg, S("SStmt"));

	{
		// Previously, this failed...
		Str *src = new (e) Str(S("1 +"));
		InfoErrors s = p->parseApprox(src, new (e) Url());
		CHECK(s.success());
	}

	{
		// And this...
		Str *src = new (e) Str(S("try { foo(bar, } catch (Type v) {}"));
		InfoErrors s = p->parseApprox(src, new (e) Url());
		CHECK(s.success());

		if (!s.success())
			p->throwError();
	}
} END_TEST