Coder Social home page Coder Social logo

parser's Introduction

Parser

Run

cargo run

It will try to parse the files in the root/js folder and print one line of output for each file.

Status (temporarily frozen)

Work in progress - sorry no docs, no tests, some commented println! in the source code.

Deps

Currently one dependency: crate rayon - just for parsing files in parallel

Goal

To be honest, I have no idea :) The end goal may change later, for now I guess it's about counting compound tokens for different "js" frameworks.

Hypothesis: we can't count lines of code (because it's not meaningful), but we can count tokens. Let's check it out :)

Design

The idea was borrowed from double-entry bookkeeping: token should appear once in a sort of true table and secondly in a sort of table of possible tokens. True table in this sense is a vector of tokens after parsing the "js" file, the second table is a vector that grows dynamically according to the last seen true token.

In other words (just from an implementation point of view), it's a tree that extends itself based on the last seen compound token. (e.g. if the matching compound token is "Statement", the tree will replace the matching leaf with a new tree containing the tokens "While", "ForLoop", "If" and so on). In the end we either get an empty tree (which is good) or not :)

File Structure

The idea is just to make the logic very simple. It's just one possible implementation of parsing logic, so why not make it simple :)

atoms
..macros.rs -- just macros for making trees
..grammar.rs -- grammar for parsing js files
..utils.rs -- simple helpers (how without it? :)
..tokens/engine -- just simple tokenizer
audit
..double_entry.rs -- logic for comparing two tables of tokens: real and possible
registry.rs -- sort of a hashtable, but much easier to debug
main.rs -- entry point

parser's People

Contributors

alexander-panin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.