source: icGREP/icgrep-devel/icgrep/re/validation.h @ 6184

Last change on this file since 6184 was 6178, checked in by cameron, 9 months ago

RE Validation

File size: 1.9 KB
Line 
1/*
2 *  Copyright (c) 2018 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#ifndef RE_VALIDATION_H
8#define RE_VALIDATION_H
9
10#include <string>
11namespace re { class RE; class CC;}
12namespace cc { class Alphabet;}
13namespace re { class Name; class Start; class End; class CC; class Seq; class Alt;
14    class Rep; class Intersect; class Diff; class Range; class Group;
15    class Assertion;
16}
17
18namespace re {
19/* Check that all names within an RE are defined. */
20bool validateNamesDefined(RE * r);
21
22/* Check that all CCs within an RE have the given Alphabet */
23bool validateAlphabet(const cc::Alphabet * a, RE * r);
24
25/* Check that the RE is free of zero-width assertions */
26bool validateAssertionFree(RE * r);
27
28/* A generic visitor for validation tasks.   The generic routines
29   traverse the AST attempting validation at each RE node, returning
30   false immediately if the validation fails anywhere.   By default,
31   validation requires that Names are defined and that the definitions
32   satisfy the validation requirement, but this may be overridden. */
33
34class RE_Validator {
35public:
36    bool validateRE(RE * r);
37    RE_Validator(std::string name = "") : mValidatorName(name) {}
38protected:
39    bool validate(RE * r);
40    virtual bool validateName(Name * n);
41    virtual bool validateStart(Start * s);
42    virtual bool validateEnd(End * e);
43    virtual bool validateCC(CC * cc);
44    virtual bool validateSeq(Seq * s);
45    virtual bool validateAlt(Alt * a);
46    virtual bool validateRep(Rep * rep);
47    virtual bool validateIntersect(Intersect * e);
48    virtual bool validateDiff(Diff * d);
49    virtual bool validateRange(Range * rg);
50    virtual bool validateGroup(Group * g);
51    virtual bool validateAssertion(Assertion * a);
52private:
53    std::string mValidatorName;
54};
55   
56bool validateAlphabet(const cc::Alphabet * a, RE * r);
57
58}
59#endif
Note: See TracBrowser for help on using the repository browser.