regex - Writing grammar rules in SML Using Regular Expressions -


i want write converter icalendar csv in sml. hence, need write grammar rules it. understand rules can written defining them datatype. begin with, facing problems write rules regular expressions (terminals).

as example, want write given regex in sml :

label → [a-za-z0-9-]+

can tell me how write rule in sml?

edit

so far, have declared datatype variables denotes various variables of grammar.

datatype variables = label of string 

i have declared function islabel. takes input s (of type string) , returns label(s) if satisfies given regex (by checking if ascii values lie in given range) else raises exception. gotta feeling have found way solve.

other symbols/variables of grammar can defined in datatype variables.

see unix programming standard ml page 163+ example of sml/nj's regular expression library in action.

steps:

add sml/nj library. in smlnj repl use:

cm.make "$/regexp-lib.cm" 

make regular expression engine:

structure re = regexpfn (structure p = awksyntax                          structure e = backtrackengine) 

define label:

val label = re.compilestring "[a-za-z0-9-]+" 

define target:

val target = "ab9a-f" 

match label against target:

val match = stringcvt.scanstring (re.find label) target 

extract values match according program logic.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -