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

Version 4 #4

Open
fskreuz opened this issue Nov 4, 2017 · 1 comment
Open

Version 4 #4

fskreuz opened this issue Nov 4, 2017 · 1 comment

Comments

@fskreuz
Copy link

fskreuz commented Nov 4, 2017

Description

While working on tooling that deals with pre-parsing component files, I'm seeing props and values on the AST that are not present in the spec. While the AST is fairly understandable and deterministic, it emits nodes with numeric types and one-character properties whose meaning isn't immediately clear. Would be nice to have an updated document which one can look up a code, and check its properties.

@fskreuz fskreuz mentioned this issue Dec 7, 2017
@fskreuz fskreuz changed the title Updating data structures Document v4 Feb 17, 2018
@fskreuz fskreuz changed the title Document v4 Version 4 Feb 17, 2018
@ceremcem
Copy link

ceremcem commented Oct 20, 2018

I have an idea: Maybe we can create a reverse engineering tool for that purpose:

Input

doc = # AST documentation
  v: 
    alias: "Version"
    type: "Integer"

  t: 
    alias: "Template"
    type: "7 or Array"
    
  e: 
    alias: "Element"
    type: "String"
    
  f:
    alias: "Fragment"
    type: "Array"

sample = '''
  <p>hello <b>shiny</b> world</p>
  '''

Output

image

Generator

JS Bin Demo

alias = (name) -> 
  # returns Ractive AST key 
  for key, exp of doc when name is exp.alias
    return key 
  throw new Error "No such alias found: #{name}"
  
examine = (ast) -> 
  if typeof! ast is \Object 
    for key, value of ast 
      switch key
      | alias \Version  => \ok
      | alias \Template =>
        if typeof! value is \Array 
          # this is the root template 
          examine value 
        else 
          \ok 
      | alias \Element => \ok
      | alias \Fragment => examine value
      |_ => throw new Error "What is #{key}?"

  else if typeof! ast is \Array 
    for ast 
      examine .. 
      
  else if typeof! ast is \String 
    \ok 
  else 
    throw new Error "We don't expect this: #{ast}"
  'All documented'
  
check = (ast) -> 
  try
    examine ast 
  catch error 
    error 

new Ractive do 
  el: 'body'
  template: '''
    <p>Result: {{check(p(sample))}}</p>
    
    <h2>Documentation</h2>
    <ul>
    {{#each doc}}
      <ul>{{@key}}: {{.["alias"]}}
        <ul>
          <li>Type: {{.["type"]}}</li>
        </ul>
      </ul>
    {{/each}}
    </ul>
    <h2>Debug</h2>
    <pre>{{JSON.stringify(p(sample), null, 2)}}</pre>

    '''
  data: {doc, check, sample, p: Ractive.parse}

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

2 participants