File: FileReader.h

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • 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 (115 lines) | stat: -rw-r--r-- 3,004 bytes parent folder | download | duplicates (3)
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
114
115
#pragma once
#include "Thread.h"
#include "Package.h"
#include "Core/Io/Url.h"
#include "Syntax/Parser.h"

namespace storm {
	STORM_PKG(lang);

	/**
	 * Information about a single file to be read.
	 */
	class FileInfo : public ObjectOn<Compiler> {
		STORM_CLASS;
	public:
		// Create, read contents from the file.
		STORM_CTOR FileInfo(Url *file, Package *pkg);

		// Create, provide contents and a starting point.
		STORM_CTOR FileInfo(Str *contents, Str::Iter start, Url *file, Package *pkg);

		// Contents of this file.
		Str *contents;

		// Start point.
		Str::Iter start;

		// Url to the file.
		Url *url;

		// Package containing the file.
		Package *pkg;

		// Generate a file info for continuing from 'pos'.
		FileInfo *STORM_FN next(Str::Iter pos);
	};


	/**
	 * Specifies what kind of things we expect to read from the next reader in the chain. If no
	 * reader in the chain supports the specified type, we may delay creating the next reader.
	 */
	enum ReaderQuery {
		// We are reading syntax, ie. we intend to call 'readSyntaxRules' or 'readSyntaxProductions'.
		STORM_NAME(qSyntax, syntax) = 0x01,

		// We are reading types, ie. we intend to call 'readTypes' or 'resolveTypes'.
		STORM_NAME(qTypes, types) = 0x02,

		// We are reading functions, ie. we intend to call 'readFunctions'.
		STORM_NAME(qFunctions, functions) = 0x04,

		// We are intending to query information for interactive parsing.
		STORM_NAME(qParser, parser) = 0x08,
	};

	BITMASK_OPERATORS(ReaderQuery);

	/**
	 * A reader for a part of a single file. Use together with 'FilePkgReader'.
	 *
	 * This interface supports the reading of a file to be split into multiple parts. Each file may
	 * provide a new FileReader when 'next' is called. If so, that reader is used to get more data
	 * from the file.
	 */
	class FileReader : public ObjectOn<Compiler> {
		STORM_CLASS;
	public:
		// Create a file reader.
		STORM_CTOR FileReader(FileInfo *info);

		// File content.
		FileInfo *info;

		// Get the next part of this file.
		MAYBE(FileReader *) STORM_FN next(ReaderQuery q);

		// Get the syntax rules.
		virtual void STORM_FN readSyntaxRules();

		// Get the syntax options.
		virtual void STORM_FN readSyntaxProductions();

		// Get the types.
		virtual void STORM_FN readTypes();

		// Resolve types.
		virtual void STORM_FN resolveTypes();

		// Get all functions.
		virtual void STORM_FN readFunctions();

		// Resolve functions.
		virtual void STORM_FN resolveFunctions();

		/**
		 * For language server integration. Overload either 'rootRule' or 'createParser'.
		 */

		// Get the initial rule used for parsing this language.
		virtual syntax::Rule *STORM_FN rootRule();

		// Create a parser for this language.
		virtual syntax::InfoParser *STORM_FN createParser();

	protected:
		// Create any additional file readers. Only called until it succeeds once.
		virtual MAYBE(FileReader *) STORM_FN createNext(ReaderQuery q);

	private:
		// The previously created next part.
		FileReader * nextPart;
	};

}