Skip to content

Multiline Comments #37

@bantl23

Description

@bantl23

Are multiline comments possible with nex? I've been playing with nex quite a bit and I'm very impressed. However, I'm having trouble figuring out how to handle multiline comments. Can this been done with the nesting feature? I've tried but could not figure it out. Below is one thing I tired but I regex is greedy the nesting grabs the rest of the document.

/[0-9]+/            { println("INTEGER:", txt()) }
/[0-9]+\.[0-9]*/    { println("FLOAT:", txt()) }
/if|then|begin|end|procedure|function/
                    { println( "KEYWORD:", txt()) }
/[a-z][a-z0-9]*/    { println( "ID:", txt()) }
/\+|-|\*|\//        { println("OP:", txt()) }
/[ \t]+/            { /* eat up whitespace */ }
/\/\*.*|\n*\*\// <  { println("BEG_MULTI:", txt()) }
  /.*|\n*\*\//      { println("BEG_COMMENT:", txt()) }
  /\n/              { println("NEWLINE") }
>                   { println("END_COMMENT", txt()) }
/\n/                { println("NEWLINE") }
/./                 { println("UNRECOGNIZED CHAR:", txt()) }
//
package main
import (
  "os"
)

func main() {
  lex := NewLexer(os.Stdin)
  txt := func() string { return lex.Text() }
  NN_FUN(lex)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions