f# - FsLex - Differ between 2 strings -
i've couple of tokens:
pname , ename - both strings.
now want setup 2 rules in lexer, in order match tokens.
the first rule (pname) should match when string consist of characters a-z, , optional special characters @/().
the second rule (ename) should match when string consist of characters a-z, , optional prefix (#/.).
now how make rule in lexer file match ename - when theres no prefix?
if makes difference, ename have { after it's string like: (prefix)ename { - bracket shouldn't passed parser...
any suggestions?
if question related your previous question (about parsing css) files, should use different approach.
the lexer should identify simple tokens such # , . (token names hash , dot), curly braces (tokens lcurly , rcurly { , } respectively) , identifier ident using regular expression takes sequence of characters a-za-z.
the rest of processing (such identifying css rules .foo { ... }) should done in parser. in previous answer, described how parse list of property names - assumes have navigators syntactic element specifies html elements such #name or #name .class. can write separate parsing rules these:
navigators = | navigator { [$1] } | navigator navigators { $1::$2 } navigator = | hash ident { selectbyid($2) } | dot ident { selectbyclass($1) } for more information wirting parsers & lexers see wikibooks article , chris smith's blog.
Comments
Post a Comment