<commit_before>/*
 * ht3d.js
 * Copyright 2017 <NAME> <<EMAIL>>
 *
 * Utility tools for importing HT3D documents into the Livre3D engine.
 * Part of the Livre project.
 */

'use strict';

const Object3D = require('./object3d.js');


function parse(ht3d) {
  var reading = 'nothing';
  var currentObject = null;
  var currentTag = '';
  var currentProp = '';
  var propValue 
  var text = '';
  for (let i = 0; i < ht3d.length; i++) {
    let thisChar = ht3d.charAt(i);

    switch (reading) {
      case 'nothing':
        if (thisChar === '<') {
          reading = 'tag name';
        }
        else if (!/\s/.test(thisChar)) { // Is not whitespace
          reading = 'text';
          text = thisChar;
        }
        break;

      case 'tag name':
        if (!/\s/.test(thisChar)) {
          switch (thisChar) {
            case '>':
              if (currentTag) {
                let object = new Object3D();

                if (currentObject) {
                  currentObject.add(object);
                }
                currentObject = object;
              }
              reading = 'nothing';
              break;

            case '/':
              reading = 'tag close';
              break;
          }
        }
        else {
          currentTag += thisChar;
        }

      case 'tag close':
        break;<commit_msg>WIP: Parsing of HT3D files<commit_after>/*
 * ht3d.js
 * Copyright 2017 <NAME> <<EMAIL>>
 *
 * Utility tools for importing HT3D documents into the Livre3D engine.
 * Part of the Livre project.
 */

'use strict';

const Object3D = require('./object3d.js');


function parse(ht3d) {
  var reading = 'nothing';
  var currentObject = null;
  var currentTag = '';
  var currentProp = '';
  var propValue 
  var text = '';

  function openTag() {
    reading = "tag name";
  }
  function startTag(thisChar) {
    reading = 'tag name';
    currentTag = thisChar;
  }
  function writeTag(thisChar) {
    currentTag += thisChar;
  }
  function endTag() {
    reading = 'nothing';
    if (currentTag) {
      let object = new Object3D();
      object._tag = currentTag;

      if (currentObject) {
        currentObject.add(object);
      }
      currentObject = object;
    }
  }
  function startProp(thisChar) {
    reading = 'property';
    currentProp = thisChar;
  }
  function writeProp(thisChar) {
    currentProp += thisChar;
  }
  function startValue() {
    reading = 'value';
    propValue = '';
  }
  function writeValue(thisChar) {
    propValue += thisChar;
  }
  function endProp() {
    reading = 'nothing';
    currentObject['_' + currentProp] = propValue;
  }
  function startText(thisChar) {
    reading = 'text';
    text = thisChar;
  }
  function writeText(thisChar) {
    text += thisChar;
  }
  function endText() {
    if (currentObject) {
      currentObject._text = text;
    }

  for (let i = 0; i < ht3d.length; i++) {
    let thisChar = ht3d.charAt(i);

    switch (reading) {
      case 'nothing':
        if (thisChar === '<') {
        }
        else if (!/\s/.test(thisChar)) { // Is not whitespace
          reading = 'text';
          text = thisChar;
        }
        break;

      case 'tag name':
        if (!/\s/.test(thisChar)) {
          switch (thisChar) {
            case '>':
              reading = 'nothing';
              break;

            case '/':
              reading = 'tag close';
              break;
          }
        }
        else {
        }

      case 'tag close':
        if (thisChar === '>') {
          if (currentObject) {
            currentObject = currentObject.parent;
          }
        }
        break;
{'fraction_non_alphanumeric': 0.12959381044487428, 'fraction_numerical': 0.00801326333241227, 'mean_word_length': 1.7116104868913857, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4237204', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1088, 'n_words': 280}