Class: BELParser::Language::ExpressionValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/bel_parser/language/expression_validator.rb

Overview

ExpressionValidator validates the syntax and semantics of BEL expressions when supplied a Specification and Hash of namespaces.

Defined Under Namespace

Modules: Result Classes: NestedStatementResult, ObservedTermResult, ParameterResult, SimpleStatementResult, TermResult

Instance Method Summary collapse

Constructor Details

#initialize(spec, namespaces, uri_reader, url_reader) ⇒ ExpressionValidator

Returns a new instance of ExpressionValidator.



11
12
13
14
15
16
17
18
# File 'lib/bel_parser/language/expression_validator.rb', line 11

def initialize(spec, namespaces, uri_reader, url_reader)
  @spec                = spec
  @namespaces          = namespaces || {}
  @syntax_functions    = Syntax.syntax_functions
  @semantics_functions = Semantics.semantics_functions
  @transform           =
    ApplyNamespaceEncoding.new(@spec, @namespaces, uri_reader, url_reader)
end

Instance Method Details

#validate(expression_node) ⇒ BELParser::Language::Syntax::SyntaxResult

Validate the syntax and semantics of expression_node.

Parameters:

Returns:



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
# File 'lib/bel_parser/language/expression_validator.rb', line 25

def validate(expression_node)
  @transform.process(expression_node)

  case expression_node
  when BELParser::Parsers::AST::SimpleStatement
    SimpleStatementResult.new(
      validate(expression_node.statement.subject.term),
      validate(expression_node.statement.object.child),
      syntax(expression_node),
      semantics(expression_node))
  when BELParser::Parsers::AST::ObservedTerm
    ObservedTermResult.new(
      validate(expression_node.statement.subject.term),
      syntax(expression_node),
      semantics(expression_node))
  when BELParser::Parsers::AST::NestedStatement
    NestedStatementResult.new(
      validate(expression_node.statement.subject.term),
      validate(expression_node.statement.object.child),
      syntax(expression_node),
      semantics(expression_node))
  when BELParser::Parsers::AST::Statement
    SimpleStatementResult.new(
      validate(expression_node.subject.term),
      validate(expression_node.object.child),
      syntax(expression_node),
      semantics(expression_node))
  when BELParser::Parsers::AST::Term
    TermResult.new(syntax(expression_node), semantics(expression_node))
  when BELParser::Parsers::AST::Parameter
    ParameterResult.new(syntax(expression_node), semantics(expression_node))
  else
    nil
  end
end