Git Product home page Git Product logo

icy's Introduction

markless

Embrace Whitespace

Icy lets you skip closing braces and semicolons by applying indentation based deduction rules. Therefore letting you write:

void BFCAllocator::SetSafeFrontier(uint64 count) {
  uint64 current = safe_frontier_.load(std::memory_order_relaxed)
  while (count > current) {
    if (safe_frontier_.compare_exchange_strong(current, count)) {
      retry_helper_.NotifyDealloc()
      return
    else {
      current = safe_frontier_.load(std::memory_order_relaxed)

instead of:

void BFCAllocator::SetSafeFrontier(uint64 count) {
  uint64 current = safe_frontier_.load(std::memory_order_relaxed);
  while (count > current) {
    if (safe_frontier_.compare_exchange_strong(current, count)) {
      retry_helper_.NotifyDealloc();
      return;
    } else {
      current = safe_frontier_.load(std::memory_order_relaxed);
    }
  }
}

Brace the rules

  1. Strings, comments, trailing whitespace and empty lines are ignored.
  2. If next line has higher indentation, both lines are treated as same logical line.
    • ScopeExitGuard(const bool callOnScopeExit_,
                     F &&onScopeExit_,
                     m_callOnScopeExit(callOnScopeExit_),
                     m_onScopeExit(std::forward<F>(onScopeExit_))
  3. If a line ends with an opening brace and next line has exactly one level higher indentation, it marks the start of a block.
    • namespace guard { // Not a block. Must close manually
      if (m_callOnScopeExit) { // Block
          m_onScopeExit()
      std::cout << "Enter"     // Block closed
  4. The line after the next logical line having indentation equal or lower than the block's start, marks the end of the block.
    • ScopeExitGuard(ScopeExitGuard<G> &&other)
          : m_callOnScopeExit(true) { // Block start at logical line's indent 0
        other.m_callOnScopeExit = false
      
      ~ScopeExitGuard() { // Previous block ends
        if (m_callOnScopeExit) {
          m_onScopeExit()
  5. If a logical line has indentation equal or greater than the next line, it is treated as a statement and appended with a semi-colon.
    • The line must not end with { ; , : < ( [ =.
    • Exception for isolated template declarations.
      • template <typename G> // Not a statement
        ScopeExitGuard(ScopeExitGuard<G> &&other)
            : m_callOnScopeExit(true) {
          other.m_callOnScopeExit = false // Statement
          std::cout << "Exit" // Statement
        auto flags = {1, 2, 3}

Extras

  • Icy can seamlessly integrated with existing C++ tooling since the brace and semi-colon addition is done only on the line ends which preserves line and column numbers. TODO: Extensions for popular editors. Should be trivial.
  • Decompilation with icyd involves clang-format with following configuration.
    LambdaBodyIndentation: Signature
    IndentGotoLabels: true
    IndentExternBlock: Indent
    BreakBeforeBraces: Attach
    AllowAllArgumentsOnNextLine: false
    Cpp11BracedListStyle: false
    IndentRequires: true
    IndentWrappedFunctionNames: true
    NamespaceIndentation: All
    UseTab: Never
    CompactNamespaces: false
    
    Closing braces and semi-colons are removed if Icy compiler icyc can deduce them from the indentation of formatted code.

Related works

There have been a few attempts at trimming the C++ syntax but have ended up being too disruptive.

icy's People

Contributors

tejasvi avatar

Stargazers

 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.