Git Product home page Git Product logo

iro4cli's Introduction




An open-source, CLI based rewrite of Iro by Chris Ainsley, supporting automatic VSCode extension and Atom package generation. It's an easy to use command line tool, and will bundle up a provided Iro grammar and create various different grammar targets from it, automagically generating extensions to upload to the marketplace. Some of the available targets include:

  • Textmate
  • Atom
  • Ace
  • Pygments
  • Rouge
  • Sublime 3 (Textmate)
  • CSS

To create an Atom package and VSCode extension at the same time, you can use the following:

iro grammarFile.iro --vscode --atomext

To use the online official version of Iro, you can go to the official website. For documentation on how to create Iro grammars, check the official documentation here.

Getting Started

To get started using iro4cli, you can use one of the provided prebuilt binaries from the Releases tab on the main repository page. If one of these is not available for your chosen operating system or distribution, then you can follow the build steps below.

To build, ensure you have the .NET 6.0 SDK installed (dotnet-sdk-6.0 on apt for Ubuntu/Debian users). You will also need to install the Antlr4 v4.7.2 command line tool, and ensure it is available on PATH. Installing a newer version of the ANTLR4 command line tool or having it unavailable on PATH will result in a build error. Once these prerequisites are installed, simply run the following after cloning the repository:

dotnet build

You may need to run dotnet build twice for it to compile properly.

Usage

For all command line options available, simply run iro --help, or see the following Wiki page: https://github.com/c272/iro4cli/wiki/Command-Line-Options

For Iro grammars, an example grammar is something like the following:

name = exampleGram
file_extensions [] = exgr, exg;

styles [] {
    .example : style {
        //todo
    }
}

I highly suggest you check the official documentation for more details, however.

Progress

So far the following targets have been implemented:

  • Textmate
  • CSS
  • Ace
  • Atom
  • Pygments
  • Rouge
  • .sublime-syntax

Feature parity with Iro online here. Additional goals below.

  • VSCode Extension Generation
  • Atom Package Generation
  • Sublime Extension Generation
  • HighlightJS
  • ANTLR Input

iro4cli's People

Contributors

aminya avatar c272 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

iro4cli's Issues

Using Iro's CLI verison

I saw that you have CLI version releases for different platforms. However, people without any of the mentioned OSs have to use .NET. I wanted to go through the installation of the CLI version using .NET but didn't find any. So, I was seeking for help. What should I do to install the CLI after having .NET 6? I would use this CLI to build a VSCode extension, so if there any other altenative without the CLI, let me know too.

Thank you, I will appreciate your help!

hex color codes error

Using hex color codes causes "invalid statement provided"

.comment : style {
   color                 = #aaffaa
   color                 = "#aaffaa"; // doesn't work either
   textmate_scope        = comment
}
Example file with error
#################################################################
## Iro
################################################################ 
##
## * Press Ctrl + '+'/'-' To Zoom in
## * Press Ctrl + S to save and recalculate... 
## * Documents are saved to web storage.
## * Only one save slot supported.
## * Matches cannot span lines.
## * Unicode chars must be defined in \u0000 to \uffff format.
## * All matches must be contained by a single group ( ... )
## * Look behinds not permitted, (?<= or (?<!
## * Look forwards are permitted (?= or (?!
## * Constants are defined as __my_const = (......)
## * The \= format allows unescaped regular expressions
## * Constants referenced by match \= $${__my_const}
## * Constants can reference other constants
## * You are free to delete all the default scopes.
## * Twitter : ainslec , Web: http://eeyo.io/iro
##
################################################################

name                   = mysample
file_extensions []     = mysample;

################################################################
## Constants
################################################################

__MY_CONSTANT \= (\b[a-z][a-z0-9]*)

################################################################
## Styles
################################################################

styles [] {

.comment : style {
   color                 = #aaffaa
   italic                = true
   ace_scope             = comment
   textmate_scope        = comment
   pygments_scope        = Comment
}

.keyword : style {
   color     = cyan
   ace_scope             = keyword
   textmate_scope        = keyword
   pygments_scope        = Keyword
}

.numeric : style {
   color                 = gold
   ace_scope             = constant.numeric
   textmate_scope        = constant.numeric
   pygments_scope        = Number
}

.punctuation : style {
   color     = red_2
   ace_scope             = punctuation
   textmate_scope        = punctuation
   pygments_scope        = Punctuation
}

.text : style {
   color                 = brown
   ace_scope             = text
   textmate_scope        = text
   pygments_scope        = String
}

.illegal : style {
   color                 = white
   background_color      = red
   ace_scope             = invalid
   textmate_scope        = invalid
   pygments_scope        = Generic.Error
}

}

#################################################
## Parse contexts
#################################################

contexts [] {

##############################################
## Main Context - Entry point context
##############################################

main : context {

   : pattern {
      regex          \= $${__MY_CONSTANT}
      styles []       = .keyword;
   }
   
   : include "numeric" ;
   
   : inline_push {
      regex          \= (\{)
      styles []       = .punctuation;
      : pop {  
         regex       \= (\})
         styles []    = .punctuation;
      }
      : include "main" ;
   }
   
   : pattern {
      regex          \= (;)
      styles []       = .punctuation;
   }
   
   : inline_push {
      regex          \= (\")
      styles []       = .punctuation;
      default_style   = .text
      : pop {
         regex       \= (\")
         styles []    = .punctuation;
      }
   }
   
   : inline_push {
      regex          \= (\()
      styles []       = .punctuation;
      : pop {
         regex       \= (\))
         styles []    = .punctuation;
      }
      : include "numeric" ;
      : pattern {
         regex       \= (,)
         styles []    = .punctuation;
      }
   }
   
   : include "multi_line_comment" ;
   
   : pattern {
      regex          \= (//.*)
      styles []       = .comment;
   }
   
   : pattern {
      regex          \= ([^\s])
      styles []       = .illegal;
   }
   
}

#################################################
## End of Contexts
#################################################

###########################################
## Numeric Context
###########################################

numeric : context {
   : pattern {
      regex          \= (\b\d+)
      styles []       = .numeric;
   }
}

###########################################
## Multi Line Comment Context
###########################################

multi_line_comment : context {
   description        = multiline
   : inline_push {
      regex          \= (/\*)
      styles []       = .comment;
      default_style   = .comment
      : pop {
         regex       \= (\*/)
         styles []    = .comment;
      }
   }
}
   
}

Error:

line 40:25 extraneous input '=' expecting {'[]', '}', ':', IDENTIFIER}
[ERROR] Line 40 - Invalid statement provided, unrecognized.

Rename flag --vscode to avoid confusions

Even though I would remove this flag for different reasons,
I suggest you to change this to something like --gen-vscode-extension or similar.
Being only --vscode makes me think, the output is a vscode compatible spec somewhat.

Any plans on adding Sublime3 support?

Hi, are there any plans on adding Sublime3 support? What is the technical work involved in adding support for Sublime3 exporter? (Hoping I may be able to contribute in some way towards this)

PS: Appreciate the CLI effort for iro. Seems like an awesome tool :)

Supporting ANTLR 4 or Langium grammars

Hi!

I was wondering how hard would it be to support ANTLR 4 or Langium grammars as input or to at least generate one of them as output.

The reason for the question is that both are used to create Language Servers. Langium is especially helpful to create VS Code extensions with language servers.

Please tag a new release

I was trying to use Hex colors in 0.4.1, until I realized the latest commit is not in a release. could you tag a new release with the binaries?

License

Hi,

Thanks for the great work on this project. Would you consider placing it under a permissive license? It appears to me that this is currently license-free software, and is effectively proprietary.

Thanks!

Are there existing Iro grammar files somewhere?

I wrote a Sublime 3 syntax highlighter for my HTML-based template language a few years ago, and I've actually also been trying to port it to Iro ever since.

But I just can't get it to work, I can't even get a basic html comment context parser working, while a html comment parser in tmLanguage or sublime-syntax makes a lot more sense to me.

So does anyone know of any existing Iro grammar files that are a bit more advanced than the default example on the Iro page?

VS Code Extension

Do you have any opinions on making a VS Code extension part of this project's road map? I understand that it's currently CLI-focused, though an extension to make authoring Iro grammars easy would be excellent. While this could be done separately, being made part of this repo directly would allow it to leverage, and stay in sync with, the ANTLR grammar directly, which seems ideal.

Thoughts?

Seems to register regex look-ahead as a capture group

Hello! This is a great project you have here. I seem to have a problem though in my tests of this tool. Namely, that regex look-ahead appears to be registered as a "capture group" by this tool.

Consider the following .iro file: https://pastebin.com/7k2aP8w6

This is the default example on eeyo.io/iro, but with one small change on line 119:

regex \= (\")(?=h)

Which forces quotes to need the letter 'h' after it. This works great on eeyo.io/iro,

image

But iro4cli seems to not be able to parse it:

image

[WARN] Compile - Some top-level flags are missing and/or not implemented yet.
[ERROR] Compile Failed  - Mismatch between capture groups and number of styles for inline push with regex '(\")(?=h)'.

Grammar railroad diagram

Using some online tools like https://www.bottlecaps.de/rr/ui and https://www.bottlecaps.de/convert/ we can have a nice navigable railroad diagram.

Copy and paste the EBNF shown bellow on https://www.bottlecaps.de/rr/ui on the tab Edit Grammar the click on the tab View Diagram to see/download a navigable railroad diagram.

/* converted on Wed May 24, 2023, 09:27 (UTC+02) by antlr_4-to-w3c v0.64 which is Copyright (c) 2011-2023 by Gunther Rademacher <[email protected]> */

compileUnit
         ::= block* EOF
block    ::= statement
           | sys_set
statement
         ::= attribute
           | set
           | include
attribute
         ::= IDENTIFIER definition
sys_set  ::= IDENTIFIER '[]'? '{' statement* '}'
set      ::= IDENTIFIER? '[]'? ':' typed_set
typed_set
         ::= IDENTIFIER ( '{' statement* '}' | statement+ ';' )
include  ::= ':' IDENTIFIER '"' IDENTIFIER '"' ';'
definition
         ::= '[]'? ( '=' | '\=' ) ( definition_ident | HEX_VALUE | regex | constant_ref | array ) ';'?
definition_ident
         ::= '"'? IDENTIFIER '"'?
array    ::= IDENTIFIER ( ',' IDENTIFIER )+
regex    ::= REGEX
constant_ref
         ::= '$' '$' '{' IDENTIFIER '}'
_        ::= COMMENT
           | WS
           | ENDL
          /* ws: definition */

<?TOKENS?>

REGEX    ::= '(' ( [^()#xa#xd] | '\(' | '\)' | REGEX )* ')' ( '|' | '?' | '*' | '+' )* REGEX?
ESCAPED_BRACKET
         ::= '\('
           | '\)'
IDENTIFIER
         ::= [A-Za-z0-9_.#x2D]+
HEX_VALUE
         ::= '#' [0-9A-Za-z]+
COMMENT? ::= '#' .* #xA
WS       ::= [ #xd#x9]+
ENDL     ::= #xA
UNKNOWN_SYMBOL
         ::= .
EOF      ::= $

`iro4cli` crashes on a seemingly correct grammar

Hello @c272,

I have been working on an Iro grammar for my FOSS project.

It is a combination of JS, JSON and some custom syntax.

The definition works OK in Iro's web editor (screenshot below):

Selection_1011

However, when I run the same in iro4cli (after fixing various minor errors/warnings), I get the following Runtime unhandled exception:

[WARN] Compile - Some top-level flags are missing and/or not implemented yet.
Unhandled exception. System.NotImplementedException: The method or operation is not implemented.
   at iro4cli.Compile.Compiler.ProcessContext(String contextName, IroSet context, IroSet contexts)
   at iro4cli.Compile.Compiler.Compile(Dictionary`2 vars, ICompileTarget[] targets)
   at iro4cli.Program.Run(IroCLIOptions opts)
   at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
   at iro4cli.Program.Main(String[] args)
Aborted (core dumped)

Please find the grammar in the file: lama2.txt

Presently, I am able to get the generated outputs from the web-editor. However, it'll be really great to know your thoughts on why the particular grammar might be failing.

Thanks again, for your efforts :)

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.