Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic design #4

Closed
bvssvni opened this issue May 4, 2015 · 0 comments
Closed

Basic design #4

bvssvni opened this issue May 4, 2015 · 0 comments

Comments

@bvssvni
Copy link
Member

bvssvni commented May 4, 2015

It would be nice to make the trait to implement for meta parsing and composing as simple as possible. To achieve this one probably wants to eliminate the state. The overall idea of the design is separating the state such that roll backs are a natural side effect of performing an operation on an earlier state.

Concepts

  • Rule is an object that controls how a document is parsed and composed
  • A meta parser or composer uses sub rules and be a rule itself
  • Meta reader is an object implementing MetaReader which is the receiver of meta data from a meta parser. The meta reader communicates with the meta parser, such that error messages are handled as early as possible.
  • Meta writer is an object implementing MetaWriter which is the sender of meta data to a meta composer. The meta writer receives output character ranges from the meta composer such that error messages can be linked to the original source through mapping.
  • A state is an object associated with the meta reader or writer. For a reader it tells where to put data in the output structure. For a writer it tells where to read from in the input structure. When jumping back to an earlier state, it means the parsing or composing was rolled back because a rule failed. This must be handled by the meta reader or writer.

There is no need for a centralized meta parser or composer, if we can split it into objects that represents the rules and then pass along the state.

The state needed for parsing is chars: &[char], offset: usize.

Semantics

The semantics using the notation PistonDevelopers/piston#736 :

rule = { whitespace, parameter, token, select,
optional, until_whitespace, until_any_or_whitespace,
new_line, tab_indent, point_to, text, while, whole_line }

rule.parse(meta_reader, state, chars, offset) -> 
  meta_reader', result((range, state), (range, parse_error))

meta_reader(meta_data, state, range -> result(state, parse_error)

update(range, chars, offset) -> chars', offset'

rule.compose(meta_writer, state, meta_data, output) ->
  meta_writer', output', result((range, state, meta_data), (range, compose_error))

meta_writer(range, state) -> (meta_date, state)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant