Skip to content

Request ljs2lua #6

Open
Open

Description

@bferguson3

I'd like to be able to code using ljs and then run it in an interpreted environment that uses standard lua 5.1 code (eg love2d/lovr).

Can you make a reverse converter?

Activity

  1. mingodad commented on Jun 9, 2020

    @mingodad
    Owner

    Probably yes but I do not need it, could you do it too and share it ?

  2. Shadowblitz16 commented on Nov 24, 2020

    @Shadowblitz16

    I would like this too for love2d

  3. Artoria2e5 commented on May 19, 2021

    @Artoria2e5

    It would really help to have a grammar instead of following the C parser. I know it's a simple recursive-descent, but code is always more complicated to the eye than what's in lua-parser.ly.

    Having more parsers also opens up the opportunity to get code formatters. A port of prettier-lua to ljs would... fix some complaints about how many people prefers to have a space after flow-control keywords and no space before the : in typing.

  4. mingodad commented on May 19, 2021

    @mingodad
    Owner

    Thank you for your interest and feedback !
    Here you have an EBNF grammar compatible with https://www.bottlecaps.de/rr/ui for railroad diagram generation (I need to add it to the repository eventually). Copy the grammar bellow and paste on the Edit Grammar tab then switch to the View Diagram tab on https://www.bottlecaps.de/rr/ui (any feedback is welcome).

    //"--" lf cr  '+' lf  '+' tab
    Ljs ::= statlist
    statlist ::=  ( statement  )*
    statement ::= ';'  | ifstat  | whilestat  | block  | forstat  | dowhilestat  | funcstat  |  ( "local"  | "var"  | "let"  | "auto"  )  ( "function" localfunc  | localstat  )  | labelstat  | "return" retstat  | gotostat  | exprstat
    ifstat ::= "if" test_then_block  ( "else" statement  )?
    test_then_block ::= '(' expr ')' statement
    block ::= '{' statlist '}'
    whilestat ::= "while" '(' cond ')' statement
    forstat ::= "for" '(' TK_NAME  ( fornum  | forlist  )
    fornum ::= '=' expr ',' expr  ( ',' expr  )? forbody
    forlist ::=  ( ',' TK_NAME  )* TK_IN explist forbody
    forbody ::= ')' statement
    dowhilestat ::= "do" '{' statlist '}' "while" '(' cond ')'
    cond ::= expr
    funcstat ::= "function" funcname body
    funcname ::= singlevar  ( '.' fieldsel  )*  ( "::" fieldsel  )?
    singlevar ::= str_checkname
    body ::= '('  ( parlist  )? ')'  ( ':' TK_NAME  )? '{' statlist '}'
    parlist ::= TK_DOTS  ( ':' TK_NAME  )?  | TK_NAME  ( ':' TK_NAME  )?  ( ','  ( TK_NAME  | TK_DOTS  )  ( ':' TK_NAME  )?  )*
    localfunc ::= TK_NAME body
    localstat ::= name_attribute  ( ',' name_attribute  )*  ( '=' explist  )?
    name_attribute ::= TK_NAME  ( getlocalattribute  )?  ( ':' TK_NAME  )?
    getlocalattribute ::= '<'  ( "const"  | "close"  ) '>'
    labelstat ::= TK_NAME ':'
    retstat ::=  ( explist  )?  ( ';'  )?
    gotostat ::= "goto" str_checkname  | "break"  | "continue"
    inc_dec_op ::=  ( "++"  | "--"  )
    exprstat ::= suffixedexp  ( assign_compound  | assignment  | ';'  )?
    assignment ::= ','  | '='
    assign_compound ::= TK_CADD  | TK_CSUB  | TK_CMUL  | TK_CDIV  | TK_CMOD
    suffixedexp ::= primaryexp  ( '.' fieldsel  | '[' yindex  | "->" checkname funcargs  | funcargs  | inc_dec_op  )*
    primaryexp ::= '(' expr ')'  | singlevar  | inc_dec_op
    fieldsel ::= checkname
    checkname ::= codestring
    codestring ::= str_checkname
    str_checkname ::= TK_NAME
    yindex ::= expr ']'
    funcargs ::= '('  ( explist  )? ')'
    tconstructor ::=  ( field  (  ( ','  | ';'  ) field  )*  )? '}'
    field ::= TK_NAME recfield  | '[' yindex recfield  | listfield
    listfield ::= expr
    recfield ::= '=' expr
    explist ::= expr  ( ',' expr  )*
    expr ::= subexpr  ( '?' expr ':' expr  )?
    subexpr ::=  (  ( getunopr subexpr  )  | simpleexp  )  ( getbinopr subexpr  )*
    getunopr ::= "not"  | '-'  | '~'  | '#'
    getbinopr ::= '+'  | '-'  | '*'  | '%'  | '^'  | '/'  | "idiv"  | '&'  | '|'  | '!'  | "<<"  | ">>"  | ".."  | "!="  | "=="  | '<'  | "<="  | '>'  | ">="  | "&&"  | "||"
    simpleexp ::= TK_FLT  | TK_INT  | TK_STRING  | TK_NIL  | TK_TRUE  | TK_FALSE  | TK_DOTS  | '{' tconstructor  | TK_FUNCTION body  | suffixedexp
    
    letter ::= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"
    oct ::= '0'  .. '7'
    digit ::= '0'  .. '9'
    nzdigit ::= '1'  .. '9'
    cr ::= '\r'
    lf ::= '\n'
    tab ::= '\t'
    stringCh ::= ANY  '-' '"'  '-' '\'  '-' cr  '-' lf
    charCh ::= ANY  '-' "'"  '-' '\'  '-' cr  '-' lf
    longStringCh ::= ANY  '-' "]]"
    printable ::= '\u0020'  .. '\u007e'
    hex ::= digit  '+' 'a'  .. 'f'  '+' 'A'  .. 'F'
    TK_NAME  ::= letter  ( letter  | digit  )*
    TK_FLT  ::=  ( '.' digit  ( digit  )*  (  ( 'e'  | 'E'  )  ( '+'  | '-'  )? digit  ( digit  )*  )?  | digit  ( digit  )* '.'  ( digit  )*  (  ( 'e'  | 'E'  )  ( '+'  | '-'  )? digit  ( digit  )*  )?  | digit  ( digit  )*  ( 'e'  | 'E'  )  ( '+'  | '-'  )? digit  ( digit  )*  )
    TK_INT  ::=  ( digit  ( digit  )*  |  ( "0x"  | "0X"  ) hex  ( hex  )*  )
    TK_STRING  ::= '"'  ( stringCh  | '\'  ( printable  |  ( '\r'  )? '\n'  )  )* '"'  | "'"  ( charCh  | '\'  ( printable  |  ( '\r'  )? '\n'  )  )* "'"  | "[["  ( longStringCh  )* "]]"
    badString  ::= '"'  ( stringCh  | '\' printable  )*  ( cr  | lf  )  | "'"  ( charCh  | '\' printable  )*  ( cr  | lf  )
    TK_AUTO  ::= "auto"
    TK_BREAK  ::= "break"
    TK_CONTINUE  ::= "continue"
    TK_DO  ::= "do"
    TK_ELSE  ::= "else"
    TK_FALSE  ::= "false"
    TK___FILE__  ::= "__FILE__"
    TK_FOR  ::= "for"
    TK_FUNCTION  ::= "function"
    TK_GOTO  ::= "goto"
    TK_IDIV  ::= "idiv"
    TK_IF  ::= "if"
    TK_IN  ::= "in"
    TK_LET  ::= "let"
    TK___LINE__  ::= "__LINE__"
    TK_LOCAL  ::= "local"
    TK_NIL  ::= "null"
    TK_RETURN  ::= "return"
    TK_TRUE  ::= "true"
    TK_VAR  ::= "var"
    TK_WHILE  ::= "while"
    TK_AND  ::= "&&"
    TK_NOT  ::= '!'
    TK_OR  ::= "||"
    TK_POW  ::= "**"
    TK_CONCAT  ::= ".."
    TK_DOTS  ::= "..."
    TK_EQ  ::= '='
    TK_GE  ::= ">="
    TK_LE  ::= '<'
    TK_NE  ::= "!="
    TK_CADD  ::= "+="
    TK_CSUB  ::= "-="
    TK_CMUL  ::= "*="
    TK_CDIV  ::= "/="
    TK_CMOD  ::= "%="
    TK_CCONCAT  ::= "..="
    TK_PLUSPLUS  ::= "++"
    TK_MINUSMINUS  ::= "--"
    TK_SHL  ::= "<<"
    TK_SHR  ::= ">>"
    TK_ARROW  ::= "->"
    TK_DBCOLON  ::= "::"
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions