I'm trying to write a parser for a filetype that utilizes keyword pairs (separated by a space) and am struggling with the correct way to do this. Some examples of tokens might be:
angle spring
angle dampen
angle collision
There are also block definitions and tokens that end that block, for example:
dynamics
angle spring 1.0
angle dampen 0.0
angle collision 0.0
some 1 2 3
more ['stuff' 'here']
tokens "values can be strings, paths, etc"
end dynamics
Newlines seem to be significant, I've been using that to determine if I'm looking at a keyword or just a regular old string (keywords should be the first token on each line). Am I approaching this the right way? Should I instead just tokenize everything and define pairs more rigorously during the yacc stage?
Thanks for your time!
angle\ spring
when tokenizing and the parser wont ever need to know that it actually used a space. If the spacing can be arbitrary you can use a regex likeangle\s+spring
to define the keyword token. If this isn't what you want you should clarify what you mean with an example. - Bakuriu