Function lex

Source
pub fn lex(input: &str) -> Vec<Token>
Expand description

Take a source string with no includes or comments and returns the tokens

The source string can be processed with the process function. The tokens are all varients of Token. An illegal token will be returned for any unrechognised tokens.

ยงExamples

extern crate qasm;

let source = r#"
OPENQASM 2.0;
qreg a[3];
CX a[0], a[1];
"#;

let tokens = qasm::lex(source);
println!("{:?}", tokens);
// [OpenQASM, Real(2.0), Semicolon,
//  QReg, Id("a"), LSParen, NNInteger(3), RSParen, Semicolon,
//  Id("CX"), Id("a"), LSParen, NNInteger(0), RSParen, Comma, Id("a"), LSParen, NNInteger(1), RSParen, Semicolon]