Class: Expressir::Express::RemarkScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/expressir/express/remark_scanner.rb

Overview

Scans EXPRESS source text and extracts all remarks (tail and embedded), correctly tracking embedded-remark nesting so that inline -- inside a (* ... *) documentation block is NOT mistaken for a tail remark.

Single responsibility: source string -> Array. The scanner has no knowledge of the model; attaching remarks to model elements is the job of RemarkAttacher.

Reference: ISO 10303-11 §7.1.6. tail_remark = '--' [ remark_tag ] { } '\n' embedded_remark = '(' [ remark_tag ] { | nested embedded_remark } ')'

The scanner is a single-pass state machine with three states:

:top          — outside any remark; look for `--` or `(*`.
:in_tail       — inside a tail remark; look only for the next newline.
:in_embedded   — inside one or more nested embedded remarks; look
               for the matching `*)` or a nested `(*`, ignoring `--`.

Defined Under Namespace

Classes: Remark

Constant Summary collapse

TAIL_FORMAT =

Format discriminator values.

"tail"
EMBEDDED_FORMAT =
"embedded"
TAIL_MARKER =

Lexical markers recognised by EXPRESS.

"--"
EMBEDDED_OPEN =
"(*"
EMBEDDED_CLOSE =
"*)"
INFORMAL_PROPOSITION_TAG =

Tag forms (see ISO 10303-11 §7.1.6.3 Remark tag). IP-style informal-proposition tags are recognised only in tail remarks (matching historic behaviour); embedded remarks use the quoted form.

/\A(IP\d+):\s*(.*)\z/m
QUOTED_TAG =
/\A"([^"]*)"\s*(.*)\z/m

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ RemarkScanner

Returns a new instance of RemarkScanner.

Parameters:

  • source (String)

    EXPRESS source text (any encoding).



55
56
57
58
59
# File 'lib/expressir/express/remark_scanner.rb', line 55

def initialize(source)
  @source = source
  @source_bytes = source.b
  @line_map = LineMap.new(@source_bytes)
end

Instance Method Details

#scanArray<Remark> Also known as: call

Returns an Array of Remark, in source order (by byte position).

Returns:



63
64
65
# File 'lib/expressir/express/remark_scanner.rb', line 63

def scan
  run_state_machine
end